0

I'm told that: `(,x) is a shorthand for (cons x '()).

I'm a bit confused because that's not documented anywhere.

Also if that is the case, what does `(((pea)) ,q) evaluate to?

And why is pea wrapped in two sets of parens?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Alper
  • 3,424
  • 4
  • 39
  • 45
  • See `quasiquote` and `unquote` for documentation. – mnemenaut Sep 07 '22 at 20:35
  • I can find a bunch of stuff about that but it's not like there's an official documentation for either of those somewhere, is there? – Alper Sep 07 '22 at 21:55
  • @Alper The Scheme standards are available online; e.g. [quasiquotation](http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.17) in R6RS. – molbdnilo Sep 08 '22 at 05:47
  • The language of _The Reasoned Schemer_ is not Scheme, but istm knowledge of Scheme is assumed; the [TSPL index](http://cisco.github.io/ChezScheme/csug9.5/csug_1.html) is useful for online lookup ([find quasiquote => TSPL p142](https://scheme.com/tspl4/objects.html#./objects:s5)). [Racket](https://docs.racket-lang.org/minikanren/index.html) [documents](https://docs.racket-lang.org/guide/qq.html) may also be useful. – mnemenaut Sep 08 '22 at 06:44

1 Answers1

1
`(thing1 thing2 thing3 ...)

is roughly equivalent to

(list `thing1 `thing2 `thing3 ...)

When an expression inside backticks is preceded by a comma, that cancels out the backtick, so

`(,x)

is equivalent to

(list x)

Since a list is a chain of pairs whose last cdr is the empty list, this is equivalent to

(cons x '())

In your second example

`(((pea)) ,q)

is equivalent to

(list '((pea)) q)

Basically, when you use backquote, you can treat it like an ordinary quoted expression, except that , "unquotes" the subexpression that follows it. So you convert it to calls to list and cons with the non-comma expressions quoted, and the comma expressions not quoted.

As for why it has two sets of parentheses, that depends on how this data is being used. They needed pea to be nested 2 levels deep for some reason.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Barmar
  • 741,623
  • 53
  • 500
  • 612