[erlang-patches] Scan "=<<" as something useful

Raimo Niskanen <>
Mon Jun 10 16:50:51 CEST 2013


On Fri, Jun 07, 2013 at 06:22:29PM +0200, Anthony Ramine wrote:
> Nothing to reply to this?

Oops. Sorry about that. Good summary.

> 
> -- 
> Anthony Ramine
> 
> Le 1 mai 2013 à 15:14, Anthony Ramine a écrit :
> 
> > Hello Raimo,
> > 
> > I've given some more thought about that subject and whether the fix could surprise people if they ever did a typo.
> > 
> > 1/ "A=<<<1>>" ("A =< << 1 >>") instead of "A=<<1>>" ("A = << 1 >>")
> > 
> > * If A is not bound, this is a compilation error. The intended code would have compiled fine.
> > * If A is bound, the intended code is to crash if A isn't <<1>>, that kind of quick and dirty check is usually to fail early and found not nested in a function body; the typo is a comparison expression and the compiler will complain its return value is not used.
> > * If A is bound and the expression's return value used, no compilation error or warning will be triggered but Dialyzer will complain about a binary/boolean type mismatch.
> > 
> > 2/ "A=<<1>>" ("A = << 1 >>") instead of "A=<<<1>>" ("A =< << 1 >>")
> > 
> > * If A isn't bound, code compiles just fine. The intended code would have failed with a compilation error.
> > * If A is bound, no compilation error but Dialyzer will complain of a binary/boolean type mismatch.
> > 
> > So we are left with two cases where the compiler will say nothing, but Dialyzer will.

I think the language should not depend too much on Dialyzer. Any
strangeness is bad even if Dialyzer would detect it.

Not that any of those cases looks very sensible....

Just for the record, so I can easily recall what I aggreed on:
Intending to write:
    1a)     A = bound(), A = << 1 >>.
    1b)     A = bound(), A = << 1 >>, ... % Just a warning
    2)      A = bound(), A =< << 1 >>, ...
without spaces between the variable and the binary plus mistyping the
number of '<'s in the binary would get strangely behaving code through
the compiler (1b with a warning), but not without Dialyzer warning.

So this argument against implementing your suggested patch is not a very
strong one today. Back then there was no Dialyzer (which we should not
assume essential) and I think that compiler warning about unused return
value from comparision did not exist either.

But I still think that forever forcing Erlang to need an infinite look
ahead custom syntax aware scanner still is a strong argument against the
suggested improvement.

> > 
> > Regards,
> > 
> > -- 
> > Anthony Ramine
> > 
> > Le 29 avr. 2013 à 15:32, Raimo Niskanen a écrit :
> > 
> >> On Mon, Apr 29, 2013 at 03:11:44PM +0200, Anthony Ramine wrote:
> >>> I don't understand how is that a typo, as "A=<<<1>>" is valid syntax with or without my patch.
> >> 
> >> ...i misread the old arguments; rather that intending to write "A =< << 1 >>"
> >> without spaces as "A=<<<1>>" and misspelling to "A=<<1>>" would give no compiler
> >> error and unexpected runtime behaviour...
> >> 
> >>> 
> >>> -- 
> >>> Anthony Ramine
> >>> 
> >>> Le 29 avr. 2013 à 15:05, Raimo Niskanen a écrit :
> >>> 
> >>>> One final straw back then was this: the typo "A=<<<1>>" accidentally
> >>>> becomes valid syntax with the proposed change.
> >>> 
> >> 
> >> -- 
> >> 
> >> / Raimo Niskanen, Erlang/OTP, Ericsson AB
> >> _______________________________________________
> >> erlang-patches mailing list
> >> 
> >> http://erlang.org/mailman/listinfo/erlang-patches
> > 
> 

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-patches mailing list