clarification on single assignment

matthias@REDACTED matthias@REDACTED
Thu Nov 23 14:20:04 CET 2000


 Martin> '=' means match, which binds unbound variables.
 
 Matthias>The record syntax goes a long way towards implying assignment 

Robert writes

 > I'll send my reply there [the mailing list] ... Anyway it's 
 > good with traffic in erlang-questions.

Syntax discussions seem to involve the same small group of people over
and over again. I'd guess the rest aren't interested.

 > What
 > 
 >     Variable#type{name = value}
 > 
 > really means is, of course, create a new record of type #type which is 
 > a copy of Variable except for the field 'name' which has a new
 > value.

The strange thing about pattern matching with records is that no
pattern matching actually occurs unless you're already in the context
of another pattern match. 

That leads me to wonder how the second '=' in an expression like

  A = B#type{name = value}         % A unbound, B bound, for this example

can be a pattern match. What are the operator's arguments? What is its
precedence?

Why* can I write
 
  Value = 3,
  B = #type{},
  A = B#type{name = Value}.

but not

  B = #type{name = 3},
  A = B#type{name = Value},
  Value.

Pattern matching is supposed to bind unbound variables. If the second
'=' really were a pattern matching operator, A would be the same as B,
Value would be 3. Maybe it's "restricted pattern matching".

Matthias

 * because the chapter on records doesn't say you can...



More information about the erlang-questions mailing list