newLISP Fan Club

Forum => Whither newLISP? => Topic started by: jsmall on September 19, 2004, 06:48:59 PM

Title: quasiquote and unqoute
Post by: jsmall on September 19, 2004, 06:48:59 PM
Is there a way to write something like this in newlisp?



      `(1  , (+ 2 3))



So that it evaluates to:



     (1 5)





It looks like I have to use some like a macro to achieve this

effect.
Title:
Post by: nigelbrown on September 19, 2004, 08:06:53 PM
can do: eval of a list of elements



> (map 'eval '(1 (+ 2 3)))

(1 5)

>



Nigel
Title:
Post by: jsmall on September 19, 2004, 08:40:31 PM
Quote from: "nigelbrown"can do: eval of a list of elements



> (map 'eval '(1 (+ 2 3)))

(1 5)

>



Nigel


Clever - Thanks!



I was hoping to do something like



    `(html (body (@ (text blue) ...) ...)



and have unquoted expressiion to fill in.



I know I can use the cgi module instead and

embed newlisp code instead as the dual of this

approach  but sometimes it is nice to use the

dual.



If I use the map eval for nested lists it gets

tricky and also I would have to quote again

everything I didnt' want evaluated.  Would

it be too costly space or execution wise to

add quasiquote and unquote to newlisp?
Title:
Post by: Lutz on September 20, 2004, 06:11:07 AM
The functon 'expand' will look for symbols on every level of a nested list and fill in the evaluation of those symbols:



(set 'x 2)
(set 'a '(d e))
(set 'e "hello")

(set 'HTML '(a x (b c x)))

(expand HTML 'x 'a 'e)  => ((d "hello") 2 (b c 2))


Note that 'expand' works in an incremental fashion: the 'e' is filled in first by expanding 'a', then 'e' is expanded into "hello"



Lutz