I am a little confused about the meaning of the '
sign in racket. It appears to me that the same sign has different meanings. Look at 2 simple examples below:
Returns a newly allocated list containing the vs as its elements.
> (list 1 2 3 4)
'(1 2 3 4)
Produces a constant value corresponding to datum (i.e., the representation of the program fragment) without its lexical information, source location, etc. Quoted pairs, vectors, and boxes are immutable.
> '(1 2 3 4)
'(1 2 3 4)
So my question is:
Does the '
sign has 2 meanings (a symbol and a list) or are these the same data type and list
actually returns a quoted constant value? If the second is the case why does this work:
> '(+ (- 2 13) 11)
'(+ (- 2 13) 11)
> (eval (list + (- 2 13) 11))
0
(also (eval '(+ (- 2 13) 11))
works and evaluates correctly to 0
)
But this does not:
> (list + (- 2 13) 11)
'(#<procedure:+> -11 11)
> (eval '(#<procedure:+> -11 11))
. read: bad syntax `#<'
Related maybe: What is ' (apostrophe) in Lisp / Scheme?
(eval '(#<procedure:+> -11 11))
doesn't work is that#<procedure:+>
cannot be read back in. However, using quasiquote and unquote,(eval (quasiquote ((unquote +) -11 11)))
works. Using the short hand that would be written as(eval `(,+ -11 11))
. – Aquifer