Name for a macro?

For the Compleat Fan
Locked
Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Name for a macro?

Post by 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':

Code: Select all

(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
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

shove
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Whats wrong with:

(append filename ".ext")
Hans-Peter

Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

HPW wrote: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
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

concat
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Cyril
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

Jeff wrote: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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Code: Select all

> (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
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

Lutz wrote: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
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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...

Artful code

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

Code: Select all

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

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

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...

Artful code

m35
Posts: 171
Joined: Wed Feb 14, 2007 12:54 pm

Post by m35 »

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
Posts: 183
Joined: Tue Oct 30, 2007 6:27 pm
Location: Moscow, Russia
Contact:

Post by Cyril »

m35 wrote: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
Posts: 253
Joined: Tue Aug 02, 2005 6:40 am
Contact:

Post by Fanda »

Jeff wrote: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

Fanda

Locked