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

Pierpaolo BERNARDI bernardp@REDACTED
Tue Oct 14 22:12:04 CEST 2003


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