[erlang-questions] illegal guard expression with lists:nth

Roberto Ostinelli roberto@REDACTED
Thu Jun 11 11:53:10 CEST 2009


On 11/giu/09, at 11:50, Pierpaolo Bernardi wrote:
>
> You cannot use any function you want in a guard, but only a few BIFs.
> length/1 is one of them, lists:nth/2 is not.
>
> Check the manual for "guard sequences".
>
> Ciao
> P.



On 11/giu/09, at 11:49, Robert Virding wrote:
> Sort of. :-) The reason is that if only allows guard tests and while  
> length/1 is a valid guard tests no calls to erlang functions are. So  
> if is really:
>
> if <guard test> -> ...;
>    <guard test> -> ...;
>    ...
> end
>
> That is why an else case is usually written as true -> ... as true  
> is a guard test which always succeeds.
>
> Robert
>

i do understand the point, and pierpaolo i know about guard sequences.

let's say mine is kind of a 'feature request', since 'case'  
expressions do allow this and 'if' ones, not. therefore i was  
questioning whether i'm missing a point why this shouldn't be done in  
practice.

r.


More information about the erlang-questions mailing list