3 ms·
This isn’t the right intuition for the syntax, this is the right intuition for evaluation. Why move that bracket? The answer is simple: we want the syntax to a
by reikonomusha 6y ago
This isn’t the right intuition for the syntax, this is the right intuition for evaluation.
Why move that bracket? The answer is simple: we want the syntax to also denote a serialized data structure: a tree of atomic elements.
So (f a b c) represents a list of symbols F, A, B, C, and the interpretation of this list is a call of the function F on arguments A, B, C.
- Reelin 6y agoFor someone who hasn't used sexprs or looked at an AST before, it might not be clear why a data structure and atomic elements are goals in the first place. I tried to write an explanation but found it surprisingly difficult to articulate. In short, there's almost certainly other ways to accomplish the same thing but sexprs are dead simple and they work _really_ well in practice. Just go use them and it will make sense!
- username90 6y agoSexpr makes expressions easier for computers to parse. That is all there is to it. Other languages focuses more on making code easier for humans to parse. Both are good for different things.
- chriswarbo 6y agoLisp and s-expressions are two different things. In particular, there are various alternative syntaces for Lisp, which we can automatically convert between (e.g. via a pre-processor, or a reader macro), e.g https://readable.sourceforge.io https://readable.sourceforge.io https://www.dwheeler.com/readable/sweet-expressions.html https://www.dwheeler.com/readable/sweet-expressions.html https://srfi.schemers.org/srfi-49/srfi-49.html https://srfi.schemers.org/srfi-49/srfi-49.html https://srfi.schemers.org/srfi-119/srfi-119.html https://srfi.schemers.org/srfi-119/srfi-119.html
- minerjoe 6y agoBut your editor is also a "computer". Editing lisp code with an editor tuned to s-expressions can be pure joy. Most programmers work at the character level of text files, many lispers work much closer to the abstract syntaxt tree (AST).
- Reelin 6y ago> Sexpr makes expressions easier for computers to parse. That is all there is to it. I would _strenuously_ disagree with that claim, but as previously stated I find the explanation of why I disagree to be surprisingly difficult to articulate. Nonetheless, I find that in practice sexprs are an incredibly effective tool for the task of programming as a whole.
- Viliam1234 6y ago> Why move that bracket? The answer is simple: we want the syntax to also denote a serialized data structure: a tree of atomic elements. In other words, to evaluate "f(a, b, c)", what you really evaluate is "a", "b", "c", and "f(a, b, c)". You never evaluate "a, b, c". If you move the bracket, then "what is in bracket" matches "what is evaluated".