Page 1 of 1

quasiquote and unqoute

Posted: Mon Sep 20, 2004 1:48 am
by 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.

Posted: Mon Sep 20, 2004 3:06 am
by nigelbrown
can do: eval of a list of elements

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

Nigel

Posted: Mon Sep 20, 2004 3:40 am
by jsmall
nigelbrown wrote: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?

Posted: Mon Sep 20, 2004 1:11 pm
by Lutz
The functon 'expand' will look for symbols on every level of a nested list and fill in the evaluation of those symbols:

Code: Select all

(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