newLISP Fan Club

Forum => Whither newLISP? => Topic started by: oofoe on January 27, 2012, 10:30:52 PM

Title: Compose for NewLISP?
Post by: oofoe on January 27, 2012, 10:30:52 PM
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:


(setq x 412)
(setq a '((name "Bob")
             (age    x)))


So that:


(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:


(setq a (list '(name "Bob")
                   (list 'age x)))


So... Is there any more elegant way to do it?



Thanks!
Title: Re: Compose for NewLISP?
Post by: jopython on January 28, 2012, 02:23:52 AM
Try Kazimirs blog.



//http://kazimirmajorinc.blogspot.com/2010/02/composition-of-functions-or-macros.html
Title: Re: Compose for NewLISP?
Post by: Kazimir Majorinc on January 28, 2012, 06:00:31 AM
In this particular case you can check expand in manual.
Title: Re: Compose for NewLISP?
Post by: oofoe on January 29, 2012, 07:16:41 AM
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!