[erlang-questions] bit syntax: what does "<<1234>> =" match?

Robert Virding robert.virding@REDACTED
Tue Mar 1 12:01:41 CET 2011


----- "Anthony Ramine" <nox@REDACTED> wrote:
 
> So we agree, but I misread what you said and thought the opposite ;)
> The compiler does not complain with <<1234>> and that's already weird
> as it is. It gets to a whole new level of weirdness when you discover
> that <<foo>> is also a legal pattern even though it won't ever match.

Yes, I checked the compiler as well and, unfortunately :-), you are right. If you check the generated code you will find that works in the same way as the interpreter: it first extracts the first 8 bit integer (default as no size or type specified) and then tries to match it against the atom foo, which fails. I would have thought that erl_lint should have caught this. Just to boast a bit: in LFE this results in an error in both the compiler and interpreter. :-)

Robert

-- 
Robert Virding, Erlang Solutions Ltd.


More information about the erlang-questions mailing list