Sunday, July 03, 2016

[sqdxacek] Lisp with newlines

Consider modifying Lisp to be able to interpret lines as having parentheses around them.  The goal is to decrease the amount of parentheses.  We introduce a very special form "do":

do foo bar

which when occurring on a single line with "do" at the beginning of the line (possibly preceded by whitespace) gets rewritten by a preprocessor as

(foo bar)

Without "do", things remain the same; no parentheses get added.  Some tricky cases:

do (foo bar)
is ((foo bar))

do (foo bar
is ((foo bar)

do (foo bar
baz)
is ((foo bar) baz)

do (foo bar
do baz)
is ((foo bar) (baz))

do (foo bar
do )
is ((foo bar) ())

The code gets littered with "do" everywhere, though that's not so different from other languages littered with semicolons or forced newlines everywhere.  The keyword "do" could be replaced with some more unobtrusive symbol, perhaps even a semicolon at the end of the line (analogous to "do" at the end of a line), though I dislike languages with excessive reliance on punctuation.

Exploring semicolons in the middle of lines:

foo bar ;
is (foo bar)

foo bar ; baz quux ;
is (foo bar)(baz quux)

foo bar ; baz quux
is (foo bar) baz quux

foo bar ; (baz quux
is (foo bar)(baz quux

foo bar ; (baz ; quux)
is (foo bar)((baz) quux)

(foo bar ;
is ((foo bar)

(foo bar ; )
is ((foo bar))

(foo bar ; ) ;
is ((foo bar)) ()

Alternatively, the default behavior on lines could always be to surround with parentheses, and there could be a very special form that indicates when not to.  I think this would be more confusing: invisible nothingness means something.

No comments :