|
|
|
|
|
by snotrockets
1869 days ago
|
|
Line breaks only shorten lines, they do not change the reading direction. Yes, you can start at the bottom and read upwards, but that's unnatural for most. Compare: something.first().second().third()
With: (third
(second
(first
(something))))
The end from read must you to understand, and it gets more complicated as your code does. No wonder Clojure's threading macro is so popular, as it would allow you to write it as: (-> something first second third)
Fun fact: Lisp was never supposed to be written with S-expressions. They were intermediate representation, for bootstrapping. McCarthy designed M-expression, with function notation, inflix, and sugar'd cond and list; but all that was omitted due to lack of time, and we were left with S-exps. |
|
That's not the complete picture.
The early Lisp manual had a definition for Lisp syntax. The Lisp syntax was based on M-expressions for code and S-expressions for data.
Basically what now is
was where the function call uses M-Expression syntax and the data were S-expressions.Then we have so-called S-Functions, which work with S-expressions. append is such an s-function.
McCarthy then defined a mapping from M-Expressions to S-Expressions, thus that M-Expressions could be represented (not just written, but also in memory) as S-expressions.
In the next step he defined new S-functions called apply and eval, which took M-Expressions as S-Expression data and computed the results of apply or eval operations.
Example use of apply:
Thus these s-functions could compute with code which was represented at runtime by s-expression data.Thus such a program would use both code in M-Expression format and compute with code in S-Expression format.
Since these S-functions apply and eval could be themselves translated to s-expressions and get executed, the specific S-functions apply and eval could get executed by a s-expression evaluator.
The code above would then be written:
which in modern way would be written as Since programs thus were executed / computed as s-expressions, they were input, computed and printed as s-expressions.Thus the idea of a simple s-expression meta-programming system made the idea of an additional step of m-expression syntax reading/printing less attractive.