[erlang-questions] "prefix" ++ Rest = Something

Stefan Hellkvist hellkvist@REDACTED
Wed Oct 25 08:56:51 CEST 2017


Erlang has this syntactic sugar for matching string prefixes (
http://erlang.org/doc/reference_manual/expressions.html#id80508) where you
can do:

"prefix" ++ Rest = "prefixsomething"

, which would bind Rest to "something" in this case.

I'm curious why however it is ok to do:

1> "prefix" ++ Rest = "prefixsomething".
2> Rest.

but it is not ok to do:

1> Prefix = "prefix".
2> Prefix ++ Rest = "prefixsomething".
* 1: illegal pattern

Is it because this syntactic sugar is transformed more or less as a
preprocessing step where the value of Prefix needs to be known, or why else
is "Prefix ++ Rest = Something" not allowed even when Prefix is bound?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171025/e7f85f92/attachment.htm>

More information about the erlang-questions mailing list