Last active
December 11, 2015 02:58
-
-
Save willconant/4534549 to your computer and use it in GitHub Desktop.
Here's a simple idea for more readable s-expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imagine that you have lisp envy, but your brain can't quite handle all | |
the parentheses. Here's my idea for more readable s-expressions. | |
When you begin parsing, you start in terminator mode. In terminator | |
mode, an expression is a series of space separated expressions | |
terminated by a newline or semicolon: | |
print "hello" | |
eat "tomatoes" | |
clean "dishes" | |
In traditional s-expressions, this would be: | |
((print "hello") (eat "tomatoes") (clean "dishes")) | |
Expressions in terminator mode can contain traditional expressions: | |
print (str "hello, " name) | |
And you can flip back into terminator mode with curly braces: | |
if (< x 5) { | |
print "now we're back in terminator mode" | |
print "so we don't have too many parentheses" | |
} | |
Without curly braces, you'd stay in traditional mode in the if body: | |
if (< x 5) ( | |
(print "this time we stayed in traditional mode") | |
(print "so newlines are just whitespace") | |
(print "and complex expressions must be contained in parens") | |
) | |
Now you can imagine some more complex forms that are still fairly | |
readable: | |
switch x ( | |
1 { | |
print "x is 1" | |
} | |
2 { | |
print "x is 2" | |
} | |
else { | |
if (isSpecial x) { | |
print "x isn't 1 or 2, but it is special in some way" | |
} else { | |
print "I'm bored of x" | |
} | |
} | |
) | |
In my new syntax, you can write in either s-expression mode or js style mode and interchange them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That was basically the direction I wad going with the first version of the syntax, but i've since decided the significant newlines are more trouble than they are worth in a c style syntax.