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

Richard O'Keefe <>
Thu Jun 11 23:46:39 CEST 2009

On 11 Jun 2009, at 9:53 pm, Roberto Ostinelli wrote:
> 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.

Surely this is in a FAQ somewhere?

There used to be a 'cond' proposal.
As I understand it, the idea was that
	cond E -> B end
	case E of true -> B end

	cond E -> B ; Rest end
	case (fun () -> case E
                           of true  -> {X1,...,Xn}
                            ; false -> false
	  of {X1,...,Xn} -> B
	   ; false -> cond Rest end

where X1,...,Xn are the variables that are bound by E.

I don't know what happened to 'cond'.  It certainly never got
implemented, which is fair enough, because we really do not need it.
EEP-0025 (which was intended to have the same semantics with
respect to the scope of bindings introduced in E) does the same
kind of thing with
	case      E1 of true  -> B1
	; or case E2 of true  -> B2
	; or case E3 of true  -> B3
                       ; false -> B0

But all this is over-elaborate.  As argued at length in the threads
we've had on this subject, over-using Boolean is often a mistake in
_any_ programming language.  It is always best to discuss concrete
examples, but so far, there is almost always a better way to do it
than 'if', and when there isn't, usually a redesign of the function
you want to call makes _everything_ better.

More information about the erlang-questions mailing list