3 ms·
One option that might be suitable for a DSL, is implicit parens based on whitespace. A newline opens a new paren, and the paren closes when it reaches another l
by fwip 3y ago
One option that might be suitable for a DSL, is implicit parens based on whitespace. A newline opens a new paren, and the paren closes when it reaches another line with the same indentation e.g:
(defun factorial (x)
(if (zerop x)
1
(* x (factorial (- x 1)))))
could be rewritten as
defun factorial (x)
if (zerop x)
1
* x (factorial (- x 1))
- alwaysbeconsing 3y agoWhitespace significance might be the choice even more controversial than Lisp parens. For myself, I appreciate both, but those that do not, really do not.
- capableweb 3y agoProbably there are more Python users out there than combined users of all lisp-like languages, which I guess would mean people are less scared of white-space significance than s-expressions :)
- nsajko 3y agoExisting SRFI: SRFI 49 "Indentation-sensitive syntax": https://srfi.schemers.org/srfi-49/srfi-49.html https://srfi.schemers.org/srfi-49/srfi-49.html
- fwip 3y agoThanks, I knew that there must be prior art out there. :)
- Syzygies 3y agoI doubt that SRFI 49, or any other proposal I've seen online, has been battle-tested. I've written thousands of lines of Scheme using my own preprocessor, and it's my favorite code to look at. I prefer Haskell, for incredible ease of parallelism and a deeper mathematical foundation. The two features I look for in a reduced parenthesis syntax (like looking for the bone marrow in a beef stew recipe) are: 1. Some constructions begin doubly parenthesized. One needs a symbol to represent the missing object one parenthesis in. I use $. 2. One can write more expressive lines with a flavor of open paren that autocloses at the end of the line. I use |.