[erlang-questions] guard expression restriction
Hynek Vychodil
hynek@REDACTED
Thu Dec 2 11:44:32 CET 2010
On Thu, Dec 2, 2010 at 9:37 AM, Kostis Sagonas <kostis@REDACTED> wrote:
> 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)
>> end;
>> 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.
>
Anyway, this rewritten version doesn't behaves like guards because it
should be more like:
f(Arguments) ->
case catch Expression
of true -> Body
; _ -> f'(Arguments)
end;
f(Vars) -> f'(Vars).
or even worse
f(Arguments) ->
try Expression
of true -> Body
; _ -> f'(Arguments)
catch
_:_ -> f'(Arguments)
end;
f(Vars) -> f'(Vars).
because soon or late one would write throw(true) inside Expression.
>> 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
> allowed.
>
> Kostis
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
--
--Hynek (Pichi) Vychodil
Analyze your data in minutes. Share your insights instantly. Thrill
your boss. Be a data hero!
Try GoodData now for free: www.gooddata.com
More information about the erlang-questions
mailing list