An alternate pattern-matching conditional for Elisp
lwn.net
lwn.net
They mention repurposing the comma and backtick to serve functions that they don't elsewhere, which I agree is probably worth changing, but otherwise I can't understand at all what the issue is. And reading about the problems with cond*, it seems worse to me in every way. Not terrible, but certainly worse.
I don't really understand why Stallman considers cond* better even by the standards of his own arguments. Very odd, I feel I must be missing something.
Maybe if I tried to use it the issues would become evident.
I get that if you're manually writing code to match a list structure, you do it in a "cdr safe" way. E.g. if we are matching a two element object, we can't assume that it has an accessible cadr.
It's the job of pattern matching to do the shape checks so as not to misuse the object being matched; no aspect of that needs to be visible, including naming like "cdr safe".
first cond* version: https://lwn.net/ml/emacs-devel/E1rQJDv-0001UG-2E@fencepost.g...
cond* could also be written in itself. One way would be to have a minimal bootstrapping cond* which handles just that subset of the syntax which is used in the implementation of the real, production cond*.
I'm sometimes glad that the CL standard is frozen.
Sarcasm aside, this is literally https://xkcd.com/927/.
Sarcasm aside for real this time, getting this sort of binding mechanism in a COND-like form is unusual. This effectively means that a programmer needs to inspect all previous COND* forms, instead of relying on lexical scope AND indentation as they normally would, to see where new bindings are made. This is like Common Lisp's LOOP, but even there bindings are only allowed at the beginning of the loop, before any iteration clauses.
I also see a parallel to if/else if/else cascades. You can “break” and else if leg into … else { zzz; if (…) … } and then you can declare new variables at the zzz spot that are then available for the rest of the cascade.
I don’t know much about pcase and cond* so I can’t speak to the more general point. I just wanted to mention one specific aspect.
I miss emacs but as a Java developer what can you do…
In Scheme there is sometimes:
(define (foo)
(define a 10)
(+ a 42))
But even there all the embedded "define"s, by standard, need to be at the top of the body, directly at the start.