Function matching w/ "abc" ++ Rest
Fri Dec 9 10:48:56 CET 2005
from the reference manual;
"When matching strings, the following is a valid pattern:
f("prefix" ++ Str) -> ...
This is syntactic sugar for the equivalent, but harder to read
f([$p,$r,$e,$f,$i,$x | Str]) -> ..."
note that f("foo" ++ _) works, and is the right choice for this example.
Peter-Henry Mander wrote:
> Assuming tha code was supposed to read:
> f1("abc" ++ Rest) ->
> f1("def" ++ Rest) ->
> You would be better off writing:
> f1([$a,$b,$c|_Rest]) -> abc;
> f1([$d,$e,$f|_Rest]) -> def.
More information about the erlang-questions