[erlang-questions] Binary pattern matching and optimization

Vance Shipley vances@REDACTED
Mon Nov 24 19:08:32 CET 2008

I would like to have a function like this:

	foo(<<_:Offset/binary, Foo:8, _/binary>>, Offset) ->
		bar(Bin, Foo).

Unfortunately that doesn't work:

	Eshell V5.6.5  (abort with ^G)
	1> compile:file(codec).
	./codec.erl:15: variable 'Offset' is unbound

I don't understand why the first version can't work but
neither do I understand much about writing compilers.

So instead I do this:

	foo(Bin, Offset) ->
		<<_:Offset/binary, Foo:8, _/binary>> = Bin,
		bar(Bin, Foo).

This works fine of course but now I am trying to understand
the meaning of this (optional) compiler warning:

	Warning: INFO: using a matched out sub binary will prevent
	delayed sub binary optimization

How should I interpret this warning?

More information about the erlang-questions mailing list