guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to unquote arbitrary length elements in a backquote


From: Rock
Subject: How to unquote arbitrary length elements in a backquote
Date: Tue, 21 Dec 2010 19:39:46 +0100

Given that Guile hasn't adopted R6RS style quasiquotation yet (and I don't know if it ever will), here's a workaround I've come up with.

This is also in reply to Hans Aberg's question regarding Backquote simplification.

Basically, this is the story:

(unquote x1 x2 ... xn) ---> (unquote-splicing (list x1 x2  ... xn)) [naturally this MUST be contained within another list or vector]

(unquote-splicing x1 x2 ... xn) ---> (unquote-splicing (append x1 x2 ... xn) [same as above]

(unquote (quote x1 x2 ... xn)) ---> (unquote-splicing (quote (x1 x2 ... xn))) [idem]

That should cover all one's needs of applying these operators on arbitrary length lists of elements. This works in Common Lisp as well, although there's no need for this except in specific cases because they got it right with backquotes from the very beginning :)

With the reader macros it comes out like this:

,@(list ...)

,@(append ...)

,@'( ... )

respectively.

Hope this helps anybody who was struggling with this issue.

--
Rocco Rossi

E-Mail: address@hidden
Profilo: http://www.google.com/profiles/rocco.rossi

"Sono nato senza conoscere nulla e ho avuto un po' di tempo per cambiare qua e là questa mia condizione." (Richard P. Feynman)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]