[erlang-questions] Fwd: Why single-assignment with non-shared state?
Richard A. O'Keefe
Tue Oct 23 04:08:07 CEST 2007
On 22 Oct 2007, at 2:05 am, Tobias Gerdin wrote:
> Well as long as the expressions you match on doesn't change during
> matching I do not see the problem. There are several prominent
> languages such as the ML-family, Scala, or even Lisps which feature
> both pattern matching and assignment.
I know nothing about Scala.
However, I keep both SML and Mlton on my machines (hmm, I think I may
have MoscowML somewhere as well). SML DOES NOT ALLOW PATTERN MATCHING
ON MUTABLE DATA. SML's mutable data are "references" (boxes holding a
single variable) and "arrays". You cannot look inside either of these
using pattern matching.
The only "pattern matching" feature standardly available in Lisp is
destructuring-bind (and its close relatives). It matches mutable
cons cells because Lisp doesn't have any other kind. Reading any
Scheme or Lisp tutorial, with its dire warnings against changing
lists that happened to appear as literal data, may provide some idea
of the trouble mutable data can get you into.
More information about the erlang-questions