Search code examples
schemelispchicken-scheme

Regarding the quote (') in Scheme


My understanding is that the single quote ' in Scheme is used to tell Scheme that what follows is a symbol and not a variable. Hence, it should not be evaluated. Based on this understanding, I don't get why Chicken prints 1.0 when I enter '3/3 at the REPL.

CHICKEN
(c) 2008-2016, The CHICKEN Team
(c) 2000-2007, Felix L. Winkelmann
Version 4.11.0
linux-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2016-08-23 on buildvm-13.phx2.fedoraproject.org

#;1> '3/3
1.0

I expected it to print 3/3. Why does this get evaluated instead of a quote being present? Thanks.


Solution

  • Quote is a syntax which expands to a quote expression. That is to say, 'X means (quote X), whatever X is. quote is an operator whose value is the argument syntax itself. For instance, the value of (quote (+ 2 2)) is the list (+ 2 2) itself, rather than the value 4. Likewise, (quote a) yields the symbol a rather than the value of the expression a.

    Like other Lisp dialects, Scheme programs are written in a data notation. Every element of the source code of a Scheme program corresponds to an identifiable data structure which a Scheme program could manipulate. quote is a way of gaining access to a piece of the program's body as a literal object, passing that object into the program's space of run-time values.

    3/3 is a token which denotes a number. That number is 1.0. Some objects have more than one "spelling". Sometimes you use one spelling when entering the object into the Lisp system, and when it is printed, a different spelling is used.

    The 3/3 evaluation is not the usual expression evaluation, but something which occurs when the token is scanned and converted to an object.

    Try entering 3/3 without the quote.

    Analogy: your question is like:

    How come when I type '1.0E3, I get 1000.0? The exponent E3 is being evaluated in spite of the quote!

    However, I would expect 3/3 and '3/3 to produce 1 rather than 1.0.

    The reason 3/3 denotes 1.0 is that Chicken Scheme doesn't have full support for rational numbers, "out of the box". See this mailing list posting:

    https://lists.gnu.org/archive/html/chicken-users/2013-03/msg00032.html

    Also see the recommendation: there is an "egg" (Chicken Scheme module) called numbers which provides the "full numerical tower". "Numerical tower" is a Lisp jargon for the type system of numbers. A "full tower" means having "the works": complex numbers, rationals, bignum integers, floating-point numbers in multiple precision and so on.