[erlang-questions] guard expression restriction
Thu Dec 2 09:37:55 CET 2010
Richard O'Keefe wrote:
> There is of course a fairly elementary transformation by means of
> which anyone who *really* needs a function call in a guard finds
> out that they don't.
> f(Arguments) when Expression -> Body;
> <rest of f>
> f(Arguments) ->
> case Expression
> of true -> Body
> ; false -> f'(Arguments)
> f(Vars) -> f'(Vars).
> where f' is the rest of f with the name changed.
Yes, Erlang is Turing complete as it is (so you can express in it any
algorithm you want to) and of course there is that transformation, but
do you really claim that the bulky code with the case statement and
having to factor the rest of f into a separate function is more
expressive and programmer-friendly than the one liner with the guard?
Sorry, but I do not see this.
> I'm not providing an example, because I've tried four and each of
> them was immediately better without trying to do this in guards...
Hmmm... In any case, the paper I mentioned in my previous mail contains
an example of more clear and succinct code when user-defined guards are
More information about the erlang-questions