Guard questions

Craig Dickson <>
Tue Mar 30 23:14:10 CEST 1999


(1) Why is there no way to express "or" in a list of guards? "f(x) when a,
b" means "f(x) when a and b", but there seems to be no way to say "f(x) when
a or b"; instead, you have to say "f(x) when a -> do_something; f(x) when
b -> do_something." It's a mild annoyance at worst, but a curious one. It
seems to me that it would have been more obvious to use "and" instead of the
comma between guards, and allowed "or" and "xor" as well. I suspect there
was a conscious intent behind this design, but the reasoning behind it is
not obvious to me.

(2) Is there any behavioral or performance difference between the
expressions 2a and 2b below? It seems to me that they ought to be
equivalent. Are there technical or stylistic reasons to prefer one over the
other? (I tend to prefer 2b except when I need to refer to the whole record
in the function.)

    (2a) f(X) when record(X, x) -> X#x.field.

    (2b) f(#x{field = Field}) -> Field.

Thanks,

Craig





More information about the erlang-questions mailing list