Function matching w/ "abc" ++ Rest

Bjorn Gustavsson bjorn@REDACTED
Fri Dec 9 10:44:07 CET 2005


Peter-Henry Mander <erlang@REDACTED> writes:

> Assuming tha code was supposed to read:
> 
> f1("abc" ++ Rest) ->
>  abc;
> f1("def" ++ Rest) ->
>  def;
> 
> You would be better off writing:
> 
> f1([$a,$b,$c|_Rest]) -> abc;
> f1([$d,$e,$f|_Rest]) -> def.

Why?

The compiler generates exactly the same code for the two
ways of writing the function.

/Bjorn

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list