Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between quote, list when used in equal

Tags:

common-lisp

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.

like image 223
Daesos Avatar asked Apr 28 '26 04:04

Daesos


1 Answers

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)
like image 112
jkiiski Avatar answered May 01 '26 15:05

jkiiski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!