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?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
NeuronQ
  • 7,527
  • 9
  • 42
  • 60
  • 2
    The Common Lisp Hyperspec is an excellent reference for the Common Lisp language. It has a reference. Even for non-alphabetic symbols: http://www.lispworks.com/documentation/HyperSpec/Front/X_Alph_9.htm – Rainer Joswig Apr 11 '13 at 08:23

1 Answers1

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 +).

jwmc
  • 551
  • 2
  • 3
  • 2
    In addition, `**`, `***`, `++` and `+++` are defined, allowing you to refer to the two values of `*` and `+` that precedes the current one. – Vatine Apr 11 '13 at 12:12