[erlang-questions] guard expression restriction

James Hague <>
Thu Dec 2 21:34:15 CET 2010


On Thu, Dec 2, 2010 at 3:34 AM, Ulf Wiger <>wrote:
>I wrote in a previous mail that tackling abstract patterns, higher-order
>patterns, and parameterised receive (possibly in one single approach)
>would have a more revolutionary effect on Erlang programming than
>user-defined guards, as it would make it possible to do things that are
>very hard or awkward to do today.

I agree with this!

The issue I have with user defined guards is that there's a major blow to
predictability. The compiler does a wonderful job of generating optimal code
for pattern matching. (You can break that by putting boolean expressions all
over the place, yes.) With user-defined guards, especially if those guards
can be arbitrary and involve message sending or calls to other modules, then
pattern matching can degenerate into linear sequences of checks, and you've
got to start thinking about how to order statements in patterns. But this
isn't enough of a reason to say that user defined guards shouldn't be
implemented.

It does need be weighed against what else we should be shooting for. How
much do user defined guards really buy in terms of increasing
expressiveness? Abstract patterns would be HUGE in terms of making many
problems cleaner and more concise. User-defined guards not nearly so much.

James


More information about the erlang-questions mailing list