clarification on single assignment

Robert Virding rv@REDACTED
Thu Nov 23 12:00:56 CET 2000


matthias@REDACTED writes:
>
>    Martin> But Erlang doesn't even have assignment in the first
>    Martin> place!  '=' means match, which binds unbound variables.
>
>The record syntax goes a long way towards implying assignment 
>
>   Variable#type{name = value}
>
>I don't see how that can be explained in terms of pattern
>matching without digging into how it's actually implemented.
>
>Matthias
>
>(Not posted to the mailing list because I don't want to start a
>discussion about records. There might still be people out there who
>don't know about them ;-)

I'll send my reply there so that they find out, also the the reply 
might be interesting.  Anyway it's good with traffic in 
erlang-questions.

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.

I will admit, however, that the syntax for record updates and matches in
general does look a lot like assignments in most languages.  I will also
admit that most uses of match are for assignment, or at least a
destructuring assignment, i.e. you pull the value apart and assign
variable to parts of it.  That is why the compiler warns.

I personally don't miss being able to reassign variables, but that
probably is dew to that I have not had it for so long that it is not
something I think about.  It is only important when it changes.  Like on
which side of the road you drive.

	Robert





More information about the erlang-questions mailing list