rhombus-prototype
rhombus-prototype copied to clipboard
Make every place where binding variables currently appear allow arbitrary match patterns
-
[ ] Make every place where binding variables currently appear allow arbitrary match patterns (this requires some thought for handling what is currently things like
(define (f x) ..), so maybe we do this in a more limited way or change that way of defining functions to use a new keyword) #41 -
[ ] Building on the match allowance, also allow functions to be defined case-by-case, for example maybe using a notation like this (roughly allowed in all internal definition contexts where
:=is the keyword that triggers this kind of parsing):(length '()) := 0 (length (cons x y)) := (+ 1 (len y))
And, even better, have this turn into define/contract or maybe provide/contract if something like this is written:
length : (-> list? exact-nonnegative-integer?)
(length '()) := 0
(length (cons x y)) := (+ 1 (len y))
from Wishlist of backwards incompatible things for a future Racket2. #33
I emphatically think this should NOT be a match pattern, but a more general sort of binding-expander, like Remix's def-expanders. We don't want to push people to use a single system, match, when there are many available options.
For your second point, Remix's def+ is an attempt to provide that feature and is a relevant place to look for inspiration for an RFC.
I like the use of _ (recognized by free-identifier=?) in match, syntax-case, syntax-rules, and syntax-parse as an explicit way of communicating "I'm not going to use this thing". I often wish define-values and lambda understood it in the same way: I have at least once had a bug from accidentally shadowing _ by using it as a placeholder in a binding form that didn't treat it specially. I'm conflicted, though, about how deeply it should be built in: I value that Racket's heritage has no "reserved words". Maybe the solution is a #%plain-define-values, but I'm still trying to think of what other pitfalls "_-everywhere" might bring.
@LiberalArtist Related, I am constantly annoyed that I can't do this:
(define-values (_ _ value-I-actually-want _ _) (something))
...because it complains that this introduces duplicate bindings for _. Yes, you're technically correct there compiler. The worst kind of correct.
Yeah, I find myself always using match-define-values instead of define-values for this reason.