[erlang-questions] (newbie) Using Functions as Guards in Erlang
Fri Jun 13 13:19:42 CEST 2008
On Fri, 13 Jun 2008 11:43:54 +0200, Fuad Tabba <>
> Being able to use a function with a guard seems like it would be the most
> elegant solution.
It could be useful and I admit I don't understand why is that prohibited
"side effects and infinite loops in guards are Evil" to which one can
compiler can refuse a guard function if it can't prove it to be safe").
I'm not a compiler expert, so maybe there's a good reason I'm missing.
> Any suggestions?
Maybe choose different data representation that allows you to pattern-match
node colour? Something along the lines of:
left, %% Left subtree. :: rb_node()
right, %% Right subtree. :: rb_node()
is_black, %% Red or black? :: bool()
data}). %% Contents. :: term()
Either that, or give up doing all the dispatch in function clauses; ie.
with having explicit 'case' statements (there's nothing wrong about them
all). Or restructure the code in different way, but it's hard to suggest
w/o seeing the rest of the module...
More information about the erlang-questions