Arc Forumnew | comments | leaders | submitlogin
Unquoting
6 points by bogomipz 6172 days ago | 13 comments
Is there a technical reason for having back-quote as a separate notation? Why can't an ordinary quote be unquotable? I've always wondered if this is just an onion.

And while I'm at it, I always felt ,x looked kind of funny. I guess , was chosen because it's kind of inverse of `, but if we're getting rid of ` that doesn't apply any more. So how about using $ or even ` to unquote?

And last, but not least, since @ can only be used while unquoting, why do I have to write ,@ ? Why not just @ by itself? This, btw, does not conflict with the idea of allowing @ outside of quoted lists. The @ could splice regardless of the quoteness of the surrounding list.

Does anybody else feel that

  '(a b @args $x)
is at least as readable as

  `(a b ,@args ,x)


4 points by nostrademons 6172 days ago | link

Backquote, comma, and comma-at are reader macros that expand into quasiquote, unquote, and unquote-splicing, respectively. So your example expands to

  (quasiquote (a b (unquote-splicing args) (unquote x)))
If you allow unquoting within quote, how do you tell the difference between an evaluated (unquote x) form and a literal (unquote x)? You might want the latter if, for example, you have a macro that returns another macro with unquoting.

-----

1 point by bogomipz 6171 days ago | link

Simple; '$x versus ''$x

-----

2 points by rkts 6171 days ago | link

The unquote character (,) is definitely ugly. I'd suggest using ~ instead, as Clojure does. Of course that means dropping the current meaning of ~, which strikes me as redundant anyway given the composition operator (i.e. ~foo is the same as no:foo).

-----

1 point by ehird 6171 days ago | link

blaise did this too

-----

3 points by andreuri2000 6172 days ago | link

> Is there a technical reason for having back-quote as a separate notation? Why can't an ordinary quote be unquotable? I've always wondered if this is just an onion.

So you can express things like `',x.

-----

1 point by bogomipz 6171 days ago | link

I guess I already knew the answer would have to do with nested quotes, but I see it more clearly now. It's very simple really; what the plain quote buys you is the ability to unquote once instead of twice when using quote inside quasiquote.

Do people that write a lot of macros feel that's such a precious feature?

What's wrong with ''$$x ?

-----

1 point by ehird 6171 days ago | link

'',x

-----

1 point by sjs 6171 days ago | link

But ``,x is certainly not the same as `',x

Here's a macro for illustration:

     (mac a (x y)
      `(do (prn ',x)
           (prn `,y)))
Compared with:

    (mac b (x y)
      `(do (prn ',x)
           (prn `,,y)))

    arc> (a 1 2)
    1
    Error: "reference to undefined identifier: _y"
    arc> (b 1 2)
    1
    2
    2

-----

3 points by oddbod 6172 days ago | link

[] could be quasiquote, $ unquote, and $$ unquote-splicing:

    arc> (with (x 1  y '(2 3))
           [a b c $x $$y])
    (a b c 1 2 3) 
[] more strongly implies 'sequence'. Lambda would become {}, which implies 'block':

    arc> (map {prn _} '(1 2 3))
    1
    2
    3

-----

1 point by nex3 6172 days ago | link

Or we could avoid the whole syntax round-robin and make quasiquote {}.

-----

1 point by oddbod 6171 days ago | link

Or <>, which implies 'template' (to a younger audience).

-----

1 point by bogomipz 6171 days ago | link

Is (quote foo) way more efficient than (quasiquote foo) ?

Is that a reason why you don't want to use quasiquote unless you're actually going to unquote something, and especially not for every literal symbol in your code?

-----

1 point by simonb 6172 days ago | link

http://citeseer.ist.psu.edu/bawden99quasiquotation.html

-----