Name for a macro?

Started by Cyril, January 31, 2008, 04:52:38 PM

Previous topic - Next topic

Cyril

I have always felt that appending an element to the right of the list or string is a very important operation. What do I like in newlisp, it is its ability to pass -1 as a third argument to 'push'. But writing -1 explicitly is boring, and arguments order seems unnatural. 'push @lst, $elt;' from Perl is much better, but 'push' is already defined in other way in newlisp. Of course I can define my own macro in a trivial way, but I stumbled at a name for it. I am not a native English speaker, so I don't know which verb looks natural to the most of you here. My current solution is 'tack':


(define-macro (tack _a _b)
  (push (eval _b) (eval _a) -1))

(tack filename ".ext")


Does anyone have a better idea?
With newLISP you can grow your lists from the right side!

Jeff

#1
shove
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

HPW

#2
Whats wrong with:



(append filename ".ext")
Hans-Peter

Cyril

#3
Quote from: "HPW"Whats wrong with:



(append filename ".ext")


Non-destructiveness. I want to modify filename.
With newLISP you can grow your lists from the right side!

Jeff

#4
concat
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Cyril

#5
Quote from: "Jeff"concat


'concat' and 'append' look like pure functions for me. Seeing such a word in the code, I assume that result is yield and arguments leaved intact. On the other hand, 'push', 'tack' and 'shove' look like actions. More then, like brutal and destructive actions. I readily believe that they are breaking their arguments. But there are my deep-in-mind associations, and I am not a native English speaker. Maybe other people feel it in other way. And yes, I opine that good mnemonics matters.
With newLISP you can grow your lists from the right side!

Lutz

#6
> (set 'var "filename")
"filename"
> (write-buffer var ".ext")
4
> var
"filename.ext"
>


remember 'write-buffer' and 'write-line' do append to a string when given a string instead of a file handle ;-)



Lutz

Cyril

#7
Quote from: "Lutz"remember 'write-buffer' and 'write-line' do append to a string when given a string instead of a file handle ;-)


Oh, this works! I'll remember this for the rest of my life, I promise! ;-)
With newLISP you can grow your lists from the right side!

Jeff

#8
Lutz,



Is there a way to set stdout inside an application so that all print and println output is written to a buffer?
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

Lutz

#9
There is the 'device' function, but it only works with files:


> (device (open "buffer" "w"))
3
> (println "hello world")
"hello world"
> (close (device))
true
> !cat buffer
hello world
>


Lutz

Jeff

#10
I know.  That would be too slow.  I was hoping for something more along the lines of using device to assign stdin to a string-buffer so that print would act more like write-buffer.
Jeff

=====

Old programmers don\'t die. They just parse on...



http://artfulcode.net\">Artful code

m35

#11
Abstracting streams is probably my favorite use of OOP. I suppose the lispy way of doing it is to pass a function that performs the write?



I haven't used FOOP at all yet. I wonder how it would look using that.

Cyril

#12
Quote from: "m35"I suppose the lispy way of doing it is to pass a function that performs the write?


I have no clue how other people do it, but my experimental 'sxml2xml' function accepts an output function as argument. It is called like '(sxml2xml print pattern 4)', you can also pass '(curry net-send soc)' or '(curry write-buffer buf)' instead or 'print'.
With newLISP you can grow your lists from the right side!

Fanda

#13
Quote from: "Jeff"concat


Actually, I would suggest something similar. I like how other LISPs use '!' at the end of their functions to imply destructive behaviour. It makes it very clear. See for example dotlisp:

http://dotlisp.sourceforge.net/dotlisp.htm#Lists">http://dotlisp.sourceforge.net/dotlisp.htm#Lists



Fanda