syntax-quote asymmetry

6 views
Skip to first unread message

Rock

unread,
Jun 1, 2009, 10:59:52 AM6/1/09
to Clojure
I've been working on the Wiki lately and I'm stuck on the part about
syntax-quotes (that I had already written) which required some
updating.

There have been some changes (linked to fully lazy sequences I
suppose) with the way syntax-quotes are expanded.

It used to work like this:

------------------------------

For Lists, syntax-quote establishes a template of the corresponding
data structure. Within the template, unqualified forms behave as if
recursively syntax-quoted.

`(x1 x2 x3 ... xn)

is interpreted to mean

(clojure.core/concat |x1| |x2| |x3| ... |xn|)

where the | | are used to indicate a transformation of an xj as
follows:

* |form| is interpreted as (clojure.core/list `form), which
contains a syntax-quoted form that must then be further interpreted.

* |~form| is interpreted as (clojure.core/list form).

* |~@form| is interpreted as form.

If the syntax-quote syntax is nested, the innermost syntax-quoted form
is expanded first. This means that if several ~ occur in a row, the
leftmost one belongs to the innermost syntax-quote.

------------------------------

but now

`(x1 x2 x3 ... xn)

is interpreted to mean

(clojure.core/seq (clojure.core/concat |x1| |x2| |x3| ... |xn|))

[ Rich PLEASE explain why the change ]

There's nothing shocking about that except for this peculiar behavior:

`()

is expanded to

(clojure.core/list)

instead of (what you would expect following the rule):

(clojure.core/seq (clojure.core/concat))

Of course the latter would produce nil which is WRONG, so this
asymmetry was introduced (which was NOT there in the past because it
would have been: (clojure.core/concat (clojure.core/list)) ).

But that's not the end of it. If you do

`[]

you get:

(clojure.core/apply clojure.core/vector (clojure.core/seq
(clojure.core/concat)))

instead of (what you would expect and is EQUIVALENT):

(clojure.core/vector)

The same for the other analogous data structures.

Now, that does seem a little bizarre.

A simple question (especially for Rich):

why not simply make

`(x1 x2 x3 ... xn)

expand to

(clojure.core/apply clojure.core/list (clojure.core/seq (clojure.core/
concat))) ?

That way the symmetry is restored and the rules are much simpler.


Rock

Rock

unread,
Jun 1, 2009, 11:07:45 AM6/1/09
to Clojure
I'm sorry. A small correction regarding the last post:

--------------------------------------------------------

A simple question (especially for Rich):

why not simply make

`(x1 x2 x3 ... xn)

expand to

(clojure.core/apply clojure.core/list (clojure.core/seq (clojure.core/
concat |x1| |x2| |x3| ... |xn|)) ?

That way the symmetry is restored and the rules are much simpler.

--------------------------------------------------------

Rock
Reply all
Reply to author
Forward
0 new messages