I had never really thought about whether a symbol could be a number in Lisp, so I played around with it today:
> '1 1 > (+ '1 '1) 2 > (+ '1 1) 2 > (define a '1) > (+ a 1) 2
The above code is scheme, but it seems to be roughly the same in Common Lisp and Clojure as well. Is there any difference between 1 and quoted 1?
Lisp-1 refers to Scheme's model and Lisp-2 refers to Common Lisp's model. It's basically about whether variables and functions can have the same name without clashing. Clojure is a Lisp-1 meaning that it does not allow the same name to be used for a function and a variable simultaneously.
Clojure is a lisp-1, meaning it uses the same name resolution for both functions and value bindings.
Use defun to define your own functions in LISP. Defun requires you to provide three things. The first is the name of the function, the second is a list of parameters for the function, and the third is the body of the function -- i.e. LISP instructions that tell the interpreter what to do when the function is called.
The single-quote character is shorthand way of saying (quote foo) where quote is the form to return just foo without evaluating it. One thing to really remember in Scheme or any Lisp for that matter is that everything is evaluated by default. So, in cases where you don't want to evaluate you need a way to sat this.
In Common Lisp, '1 is shorthand for (QUOTE 1). When evaluated, (QUOTE something) returns the something part, unevaluated. However, there is no difference between 1 evaluated and 1 unevaluated.
So there is a difference to the reader: '1 reads as (QUOTE 1) and 1 reads as 1. But there is no difference when evaluted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With