3 ms·
S-expressions are more of a grammar, you'd need to change the English grammar to something more like it, specifically make the action first. Send money to John
by didibus 9y ago
S-expressions are more of a grammar, you'd need to change the English grammar to something more like it, specifically make the action first.
Send money to John's account -> (send-to (account-of "John") money)
Find all empty boxes in the warehouse -> (find-in warehouse empty boxes)
If Bob is home tomorrow, tell him John was looking for him. -> (if (is-home bob tomorrow) (tell bob (fn [him] (was-looking-for him bob))))
Now you'd have to define a lot of those arguments, and the implementation of these functions would be complex, to interpret all the relational rules of natural English language. But I feel this would be s-expressions applied to english. Things would be grouped in parenthesis, with the action first, and the set of things involved in the action following. Conditions would come first, different tense would be different functions, subject and complement would follow as arguments, and actions can involve other actions by passing them as arguments.
Now on the subject of readability, I think you're right. Spacing, font, whitespace all helps readability, and maybe the syntax lacks a little in visual separation and organisation, though you can solve most of it with indentation. But I think we must also consider comprehension. Code is more than about reading the text, it's all about understanding the underlying behavior. I think LISP syntax is good for that, in fact, it's much closer to English in that sense. It can have very powerful embedded semantics. But just like English, it requires you learn the definition and rules of a lot of words, or in LISP, functions and macros. That's what people mean when they say LISP syntax is both simple yet powerful.
Now it's not easy to learn, just like English isn't, but once you know it, it's much more expressive, and the rules are simple, but build off one another to form complex systems. I think this is actually very close to a natural language in a way.
- kazinator 9y agoS-expressions are less of a grammar. (send-to (account-of "John") money) has a tree structure that is known even if those symbols have no assigned meaning or lexical category. We know that structure by following just the tiny grammar that governs the parentheses and symbols, instead of the huge (and not completely knowable) grammar which governs sentences like "send the money to John's account". Linguists do in fact use parenthesized notation ("labelled brackets") http://www.glottopedia.org/index.php/Labeled_bracketing http://www.glottopedia.org/index.php/Labeled_bracketing This indicates what the syntax is of a sentence, so that parsing according to a grammar is no longer necessary.
- int_19h 9y agoRight, so parenthesized notation is basically an "AST dump" of a natural language sentence. But when it's dumped to paper, the end result is a visual representation, which still needs to be parsed to consume again (and have the AST inside your brain) - you just have to do it according to the rules of that parenthesized notation. So, when you see a sentence in this notation, do you find that it takes you less time to read than the original notation, or more? For me, it's definitely more. And I think the reason why this is widely used in linguistics is not because it's faster, but because 1) different languages have different syntax parsing rules, and having a single language-agnostic uniform notation is desirable, and 2) unlike normal syntax, this notation is completely unambiguous even in corner cases - in particular, it can explicitly represent arbitrary nesting without ambiguity in a way that commas do not.