3 ms·
So this code (from https://github.com/axch/test-manager/blob/c4fc3224e873716c58b07ffd35b38ad6c9881e87/ordered-map.scm#L32-L38 https://github.com/axch/test-manag
by roryokane 11y ago
So this code (from https://github.com/axch/test-manager/blob/c4fc3224e873716c58b07ffd35b38ad6c9881e87/ordered-map.scm#L32-L38 https://github.com/axch/test-manager/blob/c4fc3224e873716c58...)
(define-record-type omap-entry
(make-omap-entry key item next prev)
omap-entry?
(key omap-entry-key set-omap-entry-key!)
(item omap-entry-item set-omap-entry-item!)
(next omap-entry-next set-omap-entry-next!)
(prev omap-entry-prev set-omap-entry-prev!))
would be written like this?
(define-record-type omap-entry
make-omap-entry key item next prev.
omap-entry?,
key omap-entry-key set-omap-entry-key!.
item omap-entry-item set-omap-entry-item!.
next omap-entry-next set-omap-entry-next!.
prev omap-entry-prev set-omap-entry-prev!)
(To mark `omap-entry?` as being a value, not the S-expression `(omap-entry?)`, I decided to place a comma after it instead of a period. The alternative is requiring no punctuation and making newlines significant.)
Well, I suppose it does look better.
However, the idea is of limited applicability. While looking through the example project (https://github.com/axch/test-manager https://github.com/axch/test-manager), I had trouble finding some code where this would actually be useful – most code has too much nesting.
That’s why I prefer another solution for removing excess parens from Lisp syntax: making whitespace significant. It improves the syntax in cases where your periods would help, and it applies in additional cases as well.
“Sweet-expressions” (http://readable.sourceforge.net/ http://readable.sourceforge.net/) is an implementation of that. Here is the above code ran through the `sweeten` tool to convert it to sweet-expressions:
define-record-type
omap-entry
make-omap-entry key item next prev
omap-entry?
key omap-entry-key set-omap-entry-key!
item omap-entry-item set-omap-entry-item!
next omap-entry-next set-omap-entry-next!
prev omap-entry-prev set-omap-entry-prev!
Absolutely no parentheses necessary, while still preserving homoiconicity. You don’t even have to remember the `)` at the end of the last nested line. And I chose this example code to look good with your idea – when the code has more nesting, sweet-expressions look even better.
About the interrogative mood `?` you describe: it might simplify `if` statements. But that would require removing the convention where boolean-returning functions have a name ending in `?`, such as `omap-entry?` in the example. It’s a tradeoff.
- igravious 11y agoSweet-expressions is a cool idea. Was it Python that started the whitespace-is-significant trend? I'm wondering why someone doesn't create a Scheme or a Lisp with this as valid syntax out of the box. I think you'd still need to support regular S-expressions though, right?