Re: Varför kan jag inte inte anropa A -- B -- C ?

Robert Virding robert.virding@REDACTED
Thu Oct 16 23:41:37 CEST 2003


Unfortunately you are all missing something, -- is a big joke. After
I had added the ++ syntax, it is just syntactic sugar really, I just had
to add -- as a joke. I was also planning to add ** and // but I
couldn't really come up with good list meanings so I dropped it.
That is why there is no really thought out semantics for --.

The operator associativity had to be the same as ++ though. Sometimes
I still get the feeling we should have done the same as Smalltalk.

Robert

----- Original Message ----- 
From: "Pierpaolo BERNARDI" <bernardp@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Tuesday, October 14, 2003 10:12 PM
Subject: Re: Varför kan jag inte inte anropa A -- B -- C ?


> From: "Erik Stenman" <Erik.Stenman@REDACTED>
> 
> > But the "spec" says: Operators with the same priority are evaluated left
> to
> > right.
> ...
> > Looking at erl_parse.yrl one can see that list_op ('--' and '++') are
> right
> > associated.
> > So either the documentation or the implementation is wrong.
> > Changing line 105 from:
> > expr_300 -> expr_400 list_op expr_300 :
> > mkop('$1', '$2', '$3').
> > expr_300 -> expr_400 : '$1'.
> > to:
> > expr_300 -> expr_300 list_op expr_400 :
> > mkop('$1', '$2', '$3').
> > expr_300 -> expr_400 : '$1'.
> > Will give you a left associated parser:
> > Eshell V5.3  (abort with ^G)
> > 1> [1,2,3,4,5,6]--[1,2]--[3,4]--[5,6].
> > []
> 
> But ++ needs to be right associative for efficiency reasons;
> -- is more intuitive if left associative, like -.
> 
> It seems the best course would be to separate ++ from --.
> Second best is to leave like it is now, as ++ is probably
> more used than --.
> 
> BTW, in a quick scan of code written by me, I found some functions
> that would go from linear to quadratic running time, if the
> associativity of ++ were to be changed.
> Am I the only one that hadn't read the spec this carefully?
> 
> Cheers
> P.
> 
> 



More information about the erlang-questions mailing list