illegal guard

Thomas Arts thomas@REDACTED
Mon Jan 17 08:56:13 CET 2000


Bob Smart wrote:

Simply said: A guard may not contain a function that computes something,
at most a test. In your first example you compute the integer 33 in a guard,
which is not allowed. In the second example, the computation has been 
performed on beforehand and the guard is only a test.

One of the reasons for this is that guards
should be easy to implement and very fast to check (for example an
infinite computation in a guard would somehow be catastrophic).

/Thomas


> Why is this an illegal guard
> 
> -module(t).
> -export([test/0]).
> 
> test() ->
>   if
>     33 == list_to_integer("33") -> 99;
>     true -> 88
>   end.
> 
> but this is ok
> 
> -module(t).
> -export([test/0]).
> 
> test() ->
>   Num = list_to_integer("33"),
>   if
>     33 == Num -> 99;
>     true -> 88
>   end.
> 
> Bob



More information about the erlang-questions mailing list