This is not because Lisp is functional. Most dialects of Lisp are not functional languages. Many languages that are functional support 1 + 2 syntax for addition.
Lisp uses a nested list structure for representing code, which encodes into a parenthesized printed notation. We can think of (+ 1 2) as being an abstract syntax tree node with the operator + and two child nodes 1 and 2.
Because addition is a function (it operates on values and produces values), it is modeled as a function. The symbol + is simply the name of a library function and thus (+ 1 2) denotes a call to that function.
Not everything in the operator position is a function! Often, a symbol in the operator position is an operator.
The (symbol arg1 arg2 ...) notation isn't primarily functional; it is primarily denotational. It denotes a syntax in which the symbol is the main vocabulary item that gives it the meaning, and the arguments are modifiers.
It can represent ideas other than arithmetic. For instance, it could encode facts in a logical system:
(married john amy) ;; declaration of fact: john and amy are married
Or syntax:
(bit man dog) ;; verb subject object
In Lisp code there are lots of operators that are not functions.
(let ((x 3) (y 4)) (+ x 3))
let isn't a function; if it were then ((x 3) (y 4)) would have to be an argument expression that is evaluated, which is completely different from what it's actually expressing.
That's basically it; this nested list is a notation for encoding ideas: whatever ideas you want. In the notation, usually the first item is a symbol which holds an important vocabulary item that is the key to the meaning.
Forms can alter the vocabulary that is active in whatever they enclose, and so Lisp has to be read outside in.
In the above let we know that because we are inside a let, then (x 3) doesn't mean call the function x with argument 3. let has altered the vocabulary; it has its own rules and we must understand its interior according to those rules.
Thank you for the explanation, very interesting, and makes me want to dive more into lisp and see what's possible with this approach. Next thing you know, I am Clojure fanboy.
Can you help me understand, what is the purpose of (+ x 3) at the end of that let statement. Is that just the default return from the original function, using input given by the let function? Thanks!
Again, if we say "let function" that is not accurate. let is an operator that creates a new nesting of the lexical scope in which it binds some variables, and then evaluates forms in that environment.
let implements something similar to what is achieved with a combination of special syntax in some other languages.
Lisp C
(let ((x 1) { int x = 1;
(y 2) int y = 2;
(foo x y)) foo(x, y); }
Both of these mean "create fresh instances of variables x and y, which are scoped only to this construct, initializing them with 1 and 2, and then call foo with x and y arguments."
Lisp uses a nested list structure for representing code, which encodes into a parenthesized printed notation. We can think of (+ 1 2) as being an abstract syntax tree node with the operator + and two child nodes 1 and 2.
Because addition is a function (it operates on values and produces values), it is modeled as a function. The symbol + is simply the name of a library function and thus (+ 1 2) denotes a call to that function.
Not everything in the operator position is a function! Often, a symbol in the operator position is an operator.
The (symbol arg1 arg2 ...) notation isn't primarily functional; it is primarily denotational. It denotes a syntax in which the symbol is the main vocabulary item that gives it the meaning, and the arguments are modifiers.
It can represent ideas other than arithmetic. For instance, it could encode facts in a logical system:
Or syntax: In Lisp code there are lots of operators that are not functions. let isn't a function; if it were then ((x 3) (y 4)) would have to be an argument expression that is evaluated, which is completely different from what it's actually expressing.That's basically it; this nested list is a notation for encoding ideas: whatever ideas you want. In the notation, usually the first item is a symbol which holds an important vocabulary item that is the key to the meaning.
Forms can alter the vocabulary that is active in whatever they enclose, and so Lisp has to be read outside in.
In the above let we know that because we are inside a let, then (x 3) doesn't mean call the function x with argument 3. let has altered the vocabulary; it has its own rules and we must understand its interior according to those rules.
reply