Arc Forumnew | comments | leaders | submitlogin
`,@'
1 point by evanrmurphy 5118 days ago | 2 comments
I'm trying to use unquote-splicing to turn the list '(1 (2 3)) into '(1 2 3). This works:

  arc> `(1 ,@'(2 3))
  (1 2 3)
But this doesn't:

  arc> (list 1 `,@'( 2 3))
  Error: "unquote-splicing: invalid context within quasiquote 
  at: (unquote-splicing (ar-nil-terminate (quote (2 3 . nil)))) 
  in: (quasiquote (unquote-splicing (ar-nil-terminate (quote 
  (2 3 . nil)))))"
Can anyone shed light on this?

Update: I thought about this more and can sort of see the sense in it. quasiquote needs to be on an outer list so that unquote-splicing has something to splice into. Otherwise you could do:

  not-arc> `,@'(a b c)
  a b c
Which seems problematic, although I'm not exactly sure why. Does this have to do with it?


3 points by rocketnia 5117 days ago | link

Which seems problematic, although I'm not exactly sure why.

I think you've answered your own question. That sounds like multiple value return, and I'm not sure why it bugs me either, but it does exist in Scheme if you find you want to explore that path.

  > (values 1 2 3)
  1
  2
  3
  > (call-with-values (lambda () (values 1 2 3)) list)
  '(1 2 3)
I just found this discussion talking about the motivation and (im)practicality of multiple value return: https://groups.google.com/group/comp.lang.scheme/browse_thre... I don't have time to read the whole thing right now, but I've read the first 25 posts, and I think the first 8 of those (through David Rush's first post) are the most interesting.

Anyway, to look at your issue from another standpoint, do you really expect (list 1 <expression>) to give you a list of length 3? (If you do, I don't hold it against you. ^^ I'm just trying to provoke a gut reaction.)

-----

2 points by aw 5117 days ago | link

quasiquote works like a macro (in fact, you can implement it as a macro), and macros expand into a single value. That is, in

   (a b c (foo) d e f)
foo can expand into X or (X Y Z), but it can't splice itself into the surrounding list.

If you extend macros so that they can splice themselves, then you could implement a quasiquote that would be able to do that as well.

-----