Concerning erlang's bit syntax

Magnus Thoang magnus.thoang@REDACTED
Tue Nov 4 10:46:22 CET 2003


I like erlang's bit syntax. It makes my life easier in almost all 
situations where I need to shuffle bytes around.

I was surprised, though, when the code I had ran in the erlang shell had 
to be rewritten for the compiler:

This matching works (R9C) in the shell but cannot be put in a module:

<<StrSize:32,Str:StrSize/binary,Rest/binary>> =

When trying to compile the above expression, the compiler gives an error 
about StrSize being unbound (in the 'Str:StrSize/binary' expression).

The documentation is not clear about this case, but it mentions a 
somewhat similar function head as not being allowed.

It is just a minor annoyance, but is there a good reason for this?

Magnus Thoäng

More information about the erlang-questions mailing list