newbie question

Richard A. O'Keefe ok@REDACTED
Tue May 24 04:33:08 CEST 2005


Thomas Lindgren <thomasl_erlang@REDACTED> wrote:
	As far as I can tell, there are three problems with
	arbitrary guards:
	
	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
	point 2.
	
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
your "if".

	So, IMO, guards could instead be generalized to
	syntactic sugar for real expressions with no loss to
	the language.
	
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
simply define

    if E11 then E12
    elif E21 then E22
    ...
    else En
    end

to mean
    case E11 of true -> E12 ; false ->
    case E21 of true -> E22 ; false ->
    ...
    En
    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 mailing list