[erlang-questions] illegal guard expression: filelib:is_dir(H)
Mon Feb 15 03:26:13 CET 2010
On Feb 15, 2010, at 1:07 AM, Michael Turner wrote:
> Could be worse, y'know. At least Erlang "if" guards are checked in
> the order written. Dijkstra introduced the term "guard" using if ...
> syntax as well, but if more than one guard was true, one of the
> statements was selected "non-deterministically" -- at least if you
> believe Wikipedia.
> On the whole, I'd prefer the guards at Guantanamo.
Dijkstra's guarded command language goes with a semantics and
a >>design method<< in which you write non-overlapping guards
unless you have >>demonstrated<< that in case of overlap it
really does not matter which statement you pick.
The classic example is
if X <= Y -> Max := Y
 Y <= X -> Max := X
(a) if X = Y then it really does not matter which assignment you choose
(b) conventional practice introduces an entirely artificial
asymmetry between the two cases
(c) in more complicated cases, it is easier to reason about each
choice because, amongst other things, the condition under which
this choice is _explicit_, it's not "this and not that and not
the other and not some other thing".
Like Erlang's 'if' and 'case', the execution of guards in Dijkstra's
notation is not allowed to have side effects. So you can't tell
what order the guards were tested in except in cases where you've
demonstrated that you don't care.
The reference to Guantanamo is, um, hyperbolic, to put it mildly.
More information about the erlang-questions