Page 1 of 1

Compose for NewLISP?

Posted: Sat Jan 28, 2012 6:30 am
by oofoe
Hi!

I realize that this is probably really easy and trivial... However! I would like to define an associative list that uses pre-existing variables. Something like this:

Code: Select all

(setq x 412)
(setq a '((name "Bob")
             (age    x)))
So that:

Code: Select all

(lookup 'age a) -> 412
Of course this doesn't actually work because the "x" is quoted inside the quoted associative list, so it returns x the symbol instead of the value at associative list creation time. This will work, but it's ugly because you have to use different strategies to assemble the individual keys and values:

Code: Select all

(setq a (list '(name "Bob")
                   (list 'age x)))
So... Is there any more elegant way to do it?

Thanks!

Re: Compose for NewLISP?

Posted: Sat Jan 28, 2012 10:23 am
by jopython

Re: Compose for NewLISP?

Posted: Sat Jan 28, 2012 2:00 pm
by Kazimir Majorinc
In this particular case you can check expand in manual.

Re: Compose for NewLISP?

Posted: Sun Jan 29, 2012 3:16 pm
by oofoe
Thanks for getting back to me!

I should have been more clear -- I was thinking of "compose" not in the computer science or mathematical sense, but rather as a REBOL-style compose operation where it takes a quoted list and looks up certain tagged symbols. It does look like "expand" is the closest match.

Thanks!