cons

Q&A's, tips, howto's
Locked
eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

cons

Post by eddier »

Would it be hard to make (cons take multiple arguments?

Example

(cons 'a 'b 'c) => (a b c)

Eddie

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

Post by HPW »

Why not?

(list 'a 'b 'c)
Hans-Peter

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post by Sammo »

In newLISP, isn't 'list' basically the same as 'cons' but allowing an arbitray number of args? Is so, can you (setq mycons list) and then (mycons 'a 'b 'c), or perhaps use (constant cons list) in the appropriate context to reassign 'cons'?

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

Post by Lutz »

I agree with Sam: 'cons' with multiple args for 'cons' is like using 'list' , also
'cons' is also a lot like 'push' becuase it can take a list as the second argument:

(set 'lst '(b c))

(cons 'a lst) => (a b c)

(push 'a lst) => 'a

lst => (a b c)

the difference beeing, that push is non-destructive and returns the new list, while push has the side effect of changing the list.

If it where for me, I would just dump 'cons', because I think having 'list' and 'push', you got all you ever need, but ... there are many traditional LISPers who wouldn't want to 'lisp' without it. Personally, I think, I never have used it.

Lutz

eddier
Posts: 289
Joined: Mon Oct 07, 2002 2:48 pm
Location: Blue Mountain College, MS US

Post by eddier »

Your right! I wasn't thinking functionally (at all) Friday.

dunce Eddie

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

Post by HPW »

>there are many traditional LISPers who wouldn't want to 'lisp' without it.

Yes, the alisp people are such people.
When it does not hurt, let it as it is.
Hans-Peter

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

Post by Lutz »

Yes 'cons' stays. The advantage of most of the traditional LISP functions is, that they can be implemented with very little code, so it doesn't save much, when they are thrown out.

Lutz

Locked