3 ms·
About this last point from the article: > Why have I never seen... > ...a Lisp that can drop nested parentheses when the meaning is clear from context? I onc
by djedr 5y ago
About this last point from the article:
> Why have I never seen...
> ...a Lisp that can drop nested parentheses when the meaning is clear from context?
I once wrote a Lisp that dropped closing parentheses for one and zero-argument functions. This was done by introducing simple syntax sugar:
foo | bar
would be equivalent to
foo[bar]
in my Lisp -- this would be equivalent to the S-exp:
(foo bar)
My implementation used a syntax inbetween S- and M- expressions with brackets instead of parens and the first list element placed before the opening bracket, i.e. `f[x y z]` would mean `(f x y z)`.
For zero-arg functions the syntax was:
foo!
same as:
foo[]
same as:
(foo)
This worked pretty well and in combination with currying would substantially reduce the overall amount of parens in the code.
The `f[x]` syntax by itself also has the advantage of removing nesting for curried functions, i.e `(((f x) y) z)` becomes `f[x][y][z]`. In fact in this syntax two consecutive brackets `[[` were illegal.
So it both eliminated consecutive opening parens and substantially reduced consecutive closing parens. This was an effort to fix the major readability problems for people coming into Lisp.
For the curious, both the syntax and the language overall is described here (my master's thesis): https://djedr.github.io/masters_thesis.pdf https://djedr.github.io/masters_thesis.pdf (Chapter 2 in particular).
- celeritascelery 5y agoInteresting. Did you encounter any trade-offs or downsides in choosing this over a traditional s-expression style lisp? I am curious why this hasn’t been seen in a mainstream lisp before.
- wgoodall01 5y agoThis has been seen in a mainstream lisp before! (sort of) Wolfram Language uses almost this exact syntax—function application looks like f[x,y], but in all other respects, it works like a LISP would.
- djedr 5y ago> Did you encounter any trade-offs or downsides in choosing this over a traditional s-expression style lisp? No downsides for `f[x]` instead of `(f x)`. It really does fix the problem of overnesting without any significant trade-off that I can see. Net value of this improvement is the highest. For `foo | bar` instead of `foo[bar]` I see some downsides from a minimalist point of view. Slight complexity is added to the parser. The `|` is right-associative which has to be kept in mind when reading the code: foo | bar | baz might be less clear/more difficult to grasp for somebody who is learning the language than: foo[bar[baz]] As for the zero-argument sugar `foo!` -- its value is marginal, so also might not be worth it from a minimalist point of view. > I am curious why this hasn’t been seen in a mainstream lisp before. Not sure. Certainly I have not seen this exact improvement anywhere before or since. I think it's mostly a matter of tradition. Somehow S-expressions stuck as the defining feature of Lisp and a fundamental ALGOL-like change like that would be too much to stay in the family, certainly not in the mainstream. Indeed, as @wgoodall01 mentions there is the Wolfram Language based around something similar to M-expressions, but it is neither mainstream nor (classified as) a Lisp. The syntax is also more complex overall. There is also Rebol[0] and its variants, but it is also not mainstream and diverges from Lisp substantially. Nothing else of note comes to mind. I think John McCarthy had the right idea with M-expressions. Perhaps the definition should have been a bit more minimal back then and today we would have a major Lisp with this sort of syntax. [0] https://en.wikipedia.org/wiki/Rebol https://en.wikipedia.org/wiki/Rebol
- throwamon 5y agoInteresting ideas! Would it make sense to "sugarify" currying even further? For instance, `f[x][y][z]` could become something like `f→[x y z]`.
- djedr 5y ago> Interesting ideas! :-) > Would it make sense to "sugarify" currying even further? For instance, `f[x][y][z]` could become something like `f→[x y z]`. Technically it could be done. Does it make sense? Depends on what are you trying to achieve. Personally I tend toward an _extremely_ minimalist approach and the complexity of that would not be worth it for me. In fact today I'd question the addition of `|` and `!` as too specific. The syntax you proposed does save a few brackets, but the functionality could also be achieved with a specialized function: →[f x y z] So I'd stick to that unless I found a more compelling reason to include the sugar.