4 ms·
Sweet expressions are a bridge too far IMHO. I would be perfectly content with merely getting rid of those dangling ))))) thanks to simple parentheses insertion
by lloeki 9y ago
Sweet expressions are a bridge too far IMHO. I would be perfectly content with merely getting rid of those dangling ))))) thanks to simple parentheses insertion† based on a single very simple indent/dedent rule:
> if the next line is indented, anything from the beginning of the current line starting at the indent till a dedent matching the current line indent is wrapped in one set of parentheses.
Seriously, what about this?
defmacro deftag [name]
list 'defn name ['& 'inner]
list 'str "<" (str name) ">"
'(apply str inner)
"</" (str name) ">"
deftag html
deftag body
deftag h1
deftag p
Now what about the DSL that now downright looks like slim-lang?:
html
body
h1 "Hello World"
p "How's it going?"
Or look at that:
defn qsort [coll]
if (empty? coll)
coll
let [pivot (first coll)
remainder (rest coll)]
concat
(qsort (filter (partial > pivot) remainder))
[pivot]
(qsort (filter (partial <= pivot) remainder))
(even the qsort ones could be removed, but they balance [pivot] somehow)
I'm perfectly happy with writing (+ 1 2 3) or whatever, the only parentheses that bother me are those that are perfectly delineated by indentation already, just as newlines perform the same duty as semicolons. They're just duplicated noise††.
† Other languages perform similar semicolon insertion, with varying degrees of success and ambiguities (JS==terrible, Go==terrific).
†† I know, you're supposed to get used to it and "unsee" them. I know, "paredit!". But seriously if you have to write a tool solely to produce noise, and you have to get accustomed to ignore said noise, well, somehow, something's off.
- deleted 9y ago[deleted]
- Jtsummers 9y agoDylan. Dylan offered something like what you're asking for here. You had much the same power as traditionally structured lisps (it even has an alternative s-expression syntax). https://en.wikipedia.org/wiki/Dylan_(programming_language) https://en.wikipedia.org/wiki/Dylan_(programming_language)
- kamaal 9y agoYou might want to take a look at Haskell. It comes from a family of languages called ML. And ML was known at one point as Lisp without parenthesis. Modern incarnations of the same like F# are attractive too. But Lisp is what it is, List processing.