0

In Scheme, if I wanted a list, say (1 2 3), I would just write '(1 2 3). Usually, this is fine, but it is actually equivalent to (quote (1 2 3)), which is not exactly the same as (list 1 2 3). An example of when this would give different results:

'(1 2 (+ 0 3)) -> (1 2 (+ 0 3))
(list 1 2 (+ 0 3)) -> (1 2 3)

Is there a syntactical sugar for the second line here? For vectors there is. For example:

#(1 2 (+ 0 3)) -> #(1 2 3)
(vector 1 2 (+ 0 3)) -> #(1 2 3)

If there is no such sugar for list, that would be pretty ironic, because lists are used way more often than vectors in Scheme!

xdavidliu
  • 2,411
  • 14
  • 33
  • 5
    In Racket (my interpreter), `#(1 2 (+ 0 3))` evaluates to `'#(1 2 (+ 0 3))` – Óscar López Feb 14 '16 at 17:04
  • 1
    See this question: [What is the difference between quote and list?](http://stackoverflow.com/questions/34984552/what-is-the-difference-between-quote-and-list) and its accepted answer. – Renzo Feb 14 '16 at 20:31
  • @ÓscarLópez The same in Guile and Chicken: literal syntax for vectors does not evaluate forms inside. – mobiuseng Feb 14 '16 at 21:28

1 Answers1

6

If you need to evaluate a part of the list, you can use quasiquoting and unquoting, like this:

`(1 2 ,(+ 0 3))
=> '(1 2 3)
Óscar López
  • 232,561
  • 37
  • 312
  • 386