Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 405
NeuronQ Avatar asked Apr 11 '13 07:04

NeuronQ


People also ask

How do you compare two numbers in a Lisp?

To compare two numbers for numerical equality and type equality, use eql. The arguments may be any non-complex numbers. max returns the argument that is greatest (closest to positive infinity). min returns the argument that is least (closest to negative infinity).

What does the rest function do on a Lisp like list?

One of us learned LISP in the old days, so occasionally we'll use car or cdr instead of first or rest.) Rest takes a list as an argument and returns the list, minus its first element. You can figure out the rest, like how to get at the third and fourth elements of the list using first and rest.

What does apostrophe mean in Lisp?

The apostrophe or single-quote character marks an expression or symbol as a literal expression, to be taken at 'face-value' and not to be evaluated by the AutoLISP interpreter.

Which types of variable are used in Lisp?

These types include integer, float, cons, symbol, string, vector, hash-table, subr, byte-code function, and record, plus several special types, such as buffer, that are related to editing.


1 Answers

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

like image 152
jwmc Avatar answered Oct 10 '22 18:10

jwmc