matching with append

by David Weldon

I was recently reading this example, and I was totally surprised by the syntax in the is_authorized example. Apparently you can use the ++ operator to to pattern match. For example:

> "pajamas:" ++ Color = "pajamas:blue".

Color now has the value “blue”. Be aware that this trick has it’s limitations – as far as I can tell it only works with a single variable and a single constant in the order given above.

It pays to read other people’s code – you’ll never know what interesting tidbits you may find.