|
|
Log in / Subscribe / Register

"Structural pattern matching" for Python, part 1

"Structural pattern matching" for Python, part 1

Posted Aug 7, 2020 13:07 UTC (Fri) by anton (subscriber, #25547)
In reply to: "Structural pattern matching" for Python, part 1 by Cyberax
Parent article: "Structural pattern matching" for Python, part 1

ML was developed by Robin Milner and accomplices in the 1973-1978 time frame. The 1978 book on Edinburgh LCF contains a detailed description of ML. It seems to me that the dominant ML dialect in this century has been OCaml.

Prolog was slightly earlier (starting in 1972); there pattern matching is a natural result of unification (unlike pattern matching in ML, which is a special language feature); the syntax, though, is not that far to what we see in ML or in the proposal. And maybe the contentious issue "Is it the value of the name or a new variable to be bound?" is there because there is no difference in Prolog (logic variables work differently from functional/imperative variables). E.g., the first clause of the definition test from the article can be written similar to the example:

test(point(X,Y),Z):- X=Y, Z="A point on the diagonal".
or as:
test(point(X,X), "A point on the diagonal").
Making a query for test(point(1,2),Z) will try to unify point(1,2) with point(X,X), which fails, because X cannot be simultaneously be bound to 1 and 2.

I don't remember how the value-or-unbound issue is solved in ML.

An earlier language with pattern matching is Snobol (started 1962), but I don't know enough about Snobol to compare it.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds