Compose for NewLISP?

Pondering the philosophy behind the language
Locked
oofoe
Posts: 61
Joined: Wed Sep 28, 2005 7:13 pm
Contact:

Compose for NewLISP?

Post 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!
Testing can show the presence of bugs, but not their absence.

jopython
Posts: 123
Joined: Tue Sep 14, 2010 3:08 pm

Re: Compose for NewLISP?

Post by jopython »


Kazimir Majorinc
Posts: 388
Joined: Thu May 08, 2008 1:24 am
Location: Croatia
Contact:

Re: Compose for NewLISP?

Post by Kazimir Majorinc »

In this particular case you can check expand in manual.

oofoe
Posts: 61
Joined: Wed Sep 28, 2005 7:13 pm
Contact:

Re: Compose for NewLISP?

Post 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!
Testing can show the presence of bugs, but not their absence.

Locked