Function matching w/ "abc" ++ Rest
Peter-Henry Mander
erlang@REDACTED
Fri Dec 9 09:58:49 CET 2005
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.
Pete.
On Fri, 2005-12-09 at 07:01 +0100, dizzyd wrote:
> A general Erlang theory/performance question...
>
> If I define a series of functions like so:
>
>
> f1("abc" ++ Rest) ->
> abc;
> f1("def" ++ Rest) ->
> def;
>
>
> Is that ++ operator creating a new list and appending to it for the match? Are there scary amounts of list comparisons and overhead happening here? There doesn't seem to be anything about this form in the Erlang docs, yet it works. What's going on?
>
> Thanks![/list]
> _________________________________________________________
> Sent using Mail2Forum (http://m2f.sourceforge.net)
>
More information about the erlang-questions
mailing list