quasiquote and unqoute

Started by jsmall, September 19, 2004, 06:48:59 PM

Previous topic - Next topic

jsmall

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.

nigelbrown

#1
can do: eval of a list of elements



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

(1 5)

>



Nigel

jsmall

#2
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?

Lutz

#3
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