Why (list + 1 2) evaluates to ('(+ 1 2) 1 2) in Common Lisp
Asked Answered
S

1

5

Why does evaluating (list + 1 2) in Common Lisp (CCL REPL) returns ('(+ 1 2) 1 2)?


More: OK, I see that + actually evaluates to the last REPL result, but I still have a question: Is this a standard CL REPL thing, to have + equal to the last result, or is it Clozure specific?

Sidle answered 11/4, 2013 at 7:32 Comment(1)
The Common Lisp Hyperspec is an excellent reference for the Common Lisp language. It has a reference. Even for non-alphabetic symbols: lispworks.com/documentation/HyperSpec/Front/X_Alph_9.htmDarkle
A
7

You will find that, in the REPL, the variable * holds the last result, and + holds the last evaluated form.

For example:

> (+ 1 2)
  => 3
> +
  => (+ 1 2)
> (+ 2 3)
  => 5
> *
  => 5

Yes, these are standard, and in the HyperSpec.

If you wish to create a list containing the symbol +, rather than its value, you will need to quote it, as such: '+, or (quote +).

Ashtray answered 11/4, 2013 at 8:3 Comment(1)
In addition, **, ***, ++ and +++ are defined, allowing you to refer to the two values of * and + that precedes the current one.Politic

© 2022 - 2024 — McMap. All rights reserved.