quasiquote and unqoute

Pondering the philosophy behind the language
Locked
jsmall
Posts: 26
Joined: Mon Sep 20, 2004 1:44 am

quasiquote and unqoute

Post 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.

nigelbrown
Posts: 429
Joined: Tue Nov 11, 2003 2:11 am
Location: Brisbane, Australia

Post by nigelbrown »

can do: eval of a list of elements

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

Nigel

jsmall
Posts: 26
Joined: Mon Sep 20, 2004 1:44 am

Post 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?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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

Locked