[erlang-questions] Re: Special syntax for dictionaries
Richard O'Keefe
ok@REDACTED
Wed May 12 06:30:46 CEST 2010
On May 12, 2010, at 5:32 AM, Sergey Samokhin wrote:
>> Having too many meanings for the same symbol is too confusing and
>> error-prone. I didn't use "=" because that already means "match".
>
> You are right in that '=' is used here and there in Erlang.
>
> We use '=' to bind variable name to its value: Var = 42.
> And also to pattern match on value: 42 = Var.
No, those are the SAME thing. If you exclude records (which is
precisely what I want to do), = means ONE thing.
>
> Why use yet another symbol to do these usual things?
Nobody is suggesting any such thing. In my frames proposal,
= remains the one and only symbol for pattern matching.
But writing a maplet DOES NOT INVOLVE ANY PATTERN MATCHING!
>
> I find the following syntax most convenient:
>
> #{key = "val"}
But that uses = for something which is in NO WAY the same
as binding a variable name to its value (the thing on the
left is NOT a variable) nor is it even close to being
a pattern match on value ('key' is not the same as "val").
So you are saying that the most convenient syntax is one
that uses the pattern matching symbol for something that
not only is not pattern matching but isn't even related!
That makes no more sense than using the addition operator
would.
In an expression <{key ~ Var = "val"}> the = on the right
*IS* a pattern match and the ~ on the left *ISN'T*.
That is why it would be stupid to make them the same
symbol.
>
> It's like syntax for records, but without the record name.
But the frames proposal allows something that looks very
much like a record name: <tag{key ~ Val}>.
Frames *aren't* records (because they are a run-time
construct) even though they have many of the same parts
as records (which are a purely compile-time construct).
Because of the difference in semantics, it would be
disastrous to give them the same syntax.
#thingy{whatsit = Who_Jackie} is a record.
<thingy{whatsit ~ Who_Jackie}> is a frame.
If they looked the same, how would you know what your
program meant?
In converting code to use frames, I found it *essential*
to be able to tell which parts had been changed and which
had not.
This is not a defence of <{~}> .
There may well be better symbols around (although in the
case of ~ I have tried quite hard to find one and failed).
It's an argument against copying records syntax slavishly.
We *NEED* frame syntax to be *different* from record syntax
because the difference in semantics means that we need to
be *certain* which one we're dealing with.
And the mistake (to put it kindly) of abusing = for something
that is not matching is something we need to put behind us as
quickly as we can.
>
More information about the erlang-questions
mailing list