Richard A. O'Keefe
Tue May 24 04:33:08 CEST 2005
Thomas Lindgren <> wrote:
As far as I can tell, there are three problems with
1. Guards should run quickly. Since there are
non-constant time guards already, this does not seem
to be a big issue in practice. It may be related to
It is not a big problem in practice because at least some of us
carefully *avoid* the non-constant-time guards. Is there a compiler
option I have missed to ask for warnings about them?
In summary, my main gripe with guards echoes yours: if
keeping guards restricted means we have to write
convoluted case-expressions instead of guards, what
have we gained?
The opportunity to look at our code and see that it can be rewritten
more cleanly without EITHER using nasty guards OR convoluted case-
expressions, perhaps? In order words, I deny the "HAVE TO" part of
So, IMO, guards could instead be generalized to
syntactic sugar for real expressions with no loss to
Really, there are two quite separate things here.
(1) Should "if" expressions be able to use general expressions?
(Since "case" expressions can, perhaps the answer is yes.)
(2) Should guards be able to use general expressions?
These are two quite separate things because there is no reason why
"if" expressions *have* to use guard syntax at all. We could
if E11 then E12
elif E21 then E22
case E11 of true -> E12 ; false ->
case E21 of true -> E22 ; false ->
end .... end end
in which case there would be no direct connection between "if"
and guards at all.
I suggest it is better to do that than to change guards.
More information about the erlang-questions