4 ms·
> why is the syntax defined this way? Because Lisp has two syntax levels: one of s-expressions and one for the programming language on top of s-expressions. S
by lispm 7y ago
> why is the syntax defined this way?
Because Lisp has two syntax levels: one of s-expressions and one for the programming language on top of s-expressions.
S-expression examples
(berlin madrid london)
(john (age 21) (weight 65))
Lisp code examples:
(if (> a b) a b)
Non Lisp code, but a valid S-expression:
(if (> a b) then a else b)
You can define a new syntax for Lisp - like it has been done before - where you traditional syntax to define a programming language. You then just need a grammar and a parser.
Originally s-expressions were only thought for data and programs would have a different syntax.
A conditional might be written like that.
cond a > b -> a ;
t -> b
Lisp code with lists might then look like:
append[ (a,b,c) , car[list] ]
Where (a,b,c) is a literal list of three symbols.
But the Lisp system was internally defined using lists and the compiler&interpreter were using Lisp code as lists.
Thus it was seemed more practical to just work with s-expressions (nested lists, ...) and defer the question of syntax to a later time.
Later multiple attempts had been made to define a Lisp with a more traditional syntax: the Lisp 2 effort in the 60s, various syntactic front ends, RLISP, LOGO, ML, Dylan, ... . But for Lisp programmers it was more practical to keep the s-expression syntax, because the internal machineries of Lisp are using s-expressions anyway