0
(display (+ 1 2)) ; output 3
(display '(+ 1 2)) ; output (+ 1 2)

(display z) ; Error: execute: unbound symbol: "z" []
(display 'z) ; output z

What does quoting change the following expression into? A string, or a list, or both? The first example seems changed into a list, while the second seems into a single-character string.

Are strings and lists related types in Scheme?

Thanks.

Tim
  • 1
  • 141
  • 372
  • 590

1 Answers1

1

'<datum> is but a synonym for (quote datum). It quotes exactly the datum that follows it. In your examples, first a syntactic list is quoted, and next it is only a symbol.

String is a primitive data type, while list is an aggregate, a cons of two values (of the languages I'm aware of so far, only Haskell defines strings as character lists, not sure if Erlang dares to do the same). Despite they can obviously be subject to the same generic algorithms, their methods, while being isomorphic, have different names in Scheme's standard library.

bipll
  • 11,747
  • 1
  • 18
  • 32
  • Thanks. What is the type of the function `quote`? Does it return a list or string? – Tim Sep 03 '17 at 13:55
  • @Tim it returns the structured source code of its argument as data. It works with all values that has literal representation, even strings and numbers that are self evaluating. – Sylwester Sep 03 '17 at 21:48
  • It is not exactly a function (its argument is never evaluated) but rather a syntax; so, for example, `''42` evaluates to `(quote 42)` rather than 42. You can say it is polymorphic: when called with a list, returns a list, and once applied to a numeric literal, returns a number. A brief description is here: http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_sec_4.1.2 (hasn't changed since then). – bipll Sep 04 '17 at 05:55