Very interesting. This PEP is still in draft state, but I am interested to see how the community will react. For me, I have a few thoughts: 1) This is really close to Erlang/Elixir pattern matching and will make fail-early code much easier to write and easier to reason about. 2) match/case means double indentation, which I see they reasoned about later in the "Rejected ideas". Might have a negative impact on readabil…
I have a visceral dislike of pattern matching. Lisp shows just how much people will abuse it in real-world production codebases. It becomes impossible to understand even simple logic without comments. I’d link to some examples, but I’m on mobile; suffice to say, pull up the emacs codebase and read through some of the more advanced modules like edebug.el. I’m not certain that one uses pattern matching, but it’s a perf…
Firstly, even basic list destructuring with destructuring-bind is an improvement over a soup of car/cadar/caddr/.
Suppose we are in a compiler and would like to look for expressions of he pattern:
(not (and (not e0) (not e1) (not e2) ...))
in order to apply DeMorgan's and rewrite them to (or e0 e1 ...)
I would rather have a nice pattern matching case like this: (match-case expr
...
((not (and @(zeromore not @term)))
`(or ,term)) ;; rewrite done!
...)
than: (if (and (consp expr)
(eq (car expr) 'not))
(consp (cdr expr))
(consp (cadr (expr)))
(null (cddr expr))
(eq (caadr (expr)) 'and)
(eq (cadr expr)
... ad nauseum)
Even if a fail-safe version of destructuring-bind is used to validate and get the basic shape, it's still tedious: (destructuring-case expr
...
((a (b c))
(if (and (eq a 'and)
(eq b 'not))
... now check that c is a list of nothing but (not x) forms
)))
I don't have a pattern matcher in TXR Lisp. That is such a problem that it's holding up compiler work! Because having to write grotty code just to recognize patterns and pull out pieces is demotivating. It's not just demotivating as in "I don't feel like doing the gruntwork", but demotivating as in, "I don't want to saddle my project with the technical debt caused by cranking out that kind of code", which will have to be rewritten into pattern matching later.