What is Nostr?
Panicz Maciej Godek /
npub1t3p…cyhf
2024-11-12 20:11:34

Panicz Maciej Godek on Nostr: Sometimes, when some people learn about the "define" keyword in #scheme they - ...

Sometimes, when some people learn about the "define" keyword in #scheme they - usually more or less jokingly - ask the provocative question: can you redefine "define"?

One example of it was given by Will Byrd, in his talk about "The Most Beautiful Program Ever Written", where he evaluated the form (define define 5) - and then had to restart the interpreter.

However, behind this seemingly playful question there is a much more serious one, namely - can you meaningfuly redefine "define".

To me, the eye-opening moment was when I saw the source code of the (ice-9 curried-definitions) module in Guile:

https://github.com/cky/guile/blob/stable-2.0/module/ice-9/curried-definitions.scm

It generalizes the "define" operator to allow usages such as

(define ((f x) y) (list x y))

so that, for example, ((f 3) 4) would evaluate to the list (3 4). I think this syntax has been used throughout the "Structure and Interpretation of Classical Mechanics'.

When I learned about it, and about the (ice-9 match) module, I thought it would be cool to have a variant of "define" that would not only allow for such "curried" definitions, but also to destructure the arguments in place. Of course, for consistency, this sort of destructuring would also be implemented for other core forms in Scheme - such as "lambda", but also "let" and "let*".

This gradually gave rise to the (grand scheme) glossary

https://github.com/plande/grand-scheme

which I eventually codified as the SRFI-201 "spec".

Above everything else, it made me realize how exceptional a programming language Scheme is. Every other language forces me to write programs in the way envisioned by its designers. With Scheme, however, I could write my programs in the exact way I wanted them to be written, as long as they were encoded in s-expressions (although some implementations overcome even this limitation. For example, Bigloo's "read" function accepts an additional argument, which is a grammar specification to be used for parsing the input character stream; also Racket has an incredibly powerful module system that allows every single module to use a different syntax. But I like s-expressions).

Sometimes I hear the argument that such limitations are "actually good", because they don't let programmers "go wild and write completely incomprehensible code", which is "important on team projects".

(and I usually think about Go and Java when I hear them)

But in reality, lack of expressiveness hinders maintainability of non-trivial programs.
Author Public Key
npub1t3pucnsn50uyh4dw3ye38wqekm0a6rf05nkmlrwq8tlf4ty86frsk5cyhf