Question: Difference between quote, list when used in equal

Question

Difference between quote, list when used in equal

Answers 2
Added at 2016-12-21 08:12
Tags
Question

I need to know what the difference between quote and a list. For example:

cl-prompt> (equal (first (list * 1 2)) *)
T

cl-prompt> (equal (first '(* 1 2)) *)
NIL

I don't get what's the problem.

Answers to

Difference between quote, list when used in equal

nr: #1 dodano: 2016-12-21 08:12

When used as a variable * refers to the last result printed to the repl.

CL-USER> (+ 4 4)
8 
CL-USER> *
8

In the first one, both asterisks are unquoted, so they are treated as variables rather than symbols (their value being whatever you evaluated before that line). They are the same variable, so of course EQUAL.

CL-USER> (list * 1 2)
(8 1 2)

In the second one, the first asterisk is a quoted symbol, while the second is a variable with the value T. The symbol * is not EQUAL to T, so it returns NIL

CL-USER> '(* 1 2)
(* 1 2)
nr: #2 dodano: 2016-12-24 18:12

Even for other symbol than *, say q,

(equal (first '(q 1 2)) q)

is the same as (equal 'q q) (note the quote), whereas

(equal (first (list q 1 2)) q)

is the same as (equal q q).

'(q 1 2) equals (list 'q 1 2), not (list q 1 2); hence the difference.

Source Show
◀ Wstecz