2008/6/13 Fuad Tabba <<a href="mailto:fuad@cs.auckland.ac.nz">fuad@cs.auckland.ac.nz</a>>:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks Doug and Jachym.<br><br>Jachym is right, Doug's suggestion would work if the guard was inside my function rather than at a top level context. I know that I could rewrite my code and convert it to a bunch of if statements, but I can't think of a way to write such code without it looking ugly.<br>

<br>Being able to use a function with a guard seems like it would be the most elegant solution.<br></blockquote><div><br>It would open a can of worms that I would rather see remain closed, specifically side effects and message passing. Just being able to declare something as "guard safe" wouldn't really help as the system would still have to be able to do something sensible in all cases. Otherswise you would be surprised what users can dream up. "<font size="2">It's hard to make a program foolproof because fools are so ingenious".<br>
<br></font></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Any suggestions?</blockquote><div><br>I used the following macros for just that case:<br>
<br></div></div><font size="2">%% {r,Left,Key,Val,Right}<br>
%% {b,Left,Key,Val,Right}<br>
%% empty<br>
<br>
-define(IS_RED(N), (is_tuple(N) andalso element(1, N) == r)).<br>
%% -define(IS_BLACK(N), not (is_tuple(N) andalso element(1, N) == r)).<br>
-define(IS_BLACK(N),<br>
    ((is_tuple(N) andalso (element(1, N) == b)) orelse (N == empty))).<br><br></font><font size="2">These are guard safe and usable on the rhs as well. If they are the most efficient I don't know.<br><br>I have also found another algorithm for deleting if you are interested which is a little faster. At least in my implementation. Deleting in RB-trees is not trivial.<br>
<br>Robert<br><br></font>