<div>Hi,</div>
<div> </div>
<div>You could also use an assertion macro (which was suggested to me a while back on this list):</div>
<div> </div>
<div>-define(match(ExpectedResult, Expr, Error),<br>    ExpectedResult = fun() -><br>        Res = (catch (Expr)),<br>        case Res of<br>            ExpectedResult     -> Res;<br>            _               -> throw({match_error, Error})
<br>        end<br>    end()).<br> </div>
<div>And use it like this:</div>
<div> </div>
<div>?match({ok,FD}, open(Name), open_file_error),</div>
<div>?match({ok,Data}, read(FD), read_data_error),</div>
<div>etc.</div>
<div> </div>
<div>Keeps the TradErl philosophy, but with better error reporting. And you don't need to figure out every possible error in either open() or read() (but you still can if you want or if you have to : the exception will be thrown before the failed assertion)
</div>
<div> </div>
<div> </div>
<div>Olivier</div>
<div><br> </div>
<div><span class="gmail_quote">On 11/6/06, <b class="gmail_sendername">Mats Cronqvist</b> <<a href="mailto:mats.cronqvist@ericsson.com">mats.cronqvist@ericsson.com</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Christian S wrote:<br>> On 11/6/06, Bob Ippolito <<a href="mailto:bob@redivi.com">bob@redivi.com</a>
> wrote:<br>>> On 11/6/06, Mats Cronqvist <<a href="mailto:mats.cronqvist@ericsson.com">mats.cronqvist@ericsson.com</a>> wrote:<br>>> > Richard A. O'Keefe wrote:<br>>> > > Dominic Williams <
<a href="mailto:xpdoka@dominicwilliams.net">xpdoka@dominicwilliams.net</a>> wrote:<br>>> > >       - returning tagged values vs. throwing<br>>> >    i hope you misremember, cause returning tagged tuples is truly
<br>>> abominable.<br>>> > only a closet C programmer would use that idiom.<br>><br>> How are tagged tuples bad? How do one reason for such an opinion?<br><br>  as a really dumb example, consider three functions open(Filename),
<br>read(FileDescriptor), and process_data(Data) that can either fail or return<br>useful data. in C you'd do something like this;<br><br>  if ( ( fd = open(name)) == NULL ) return -1;<br>  if ( read(fd,&data) == -1 ) return -2;
<br>  if ( process_data(&data,&pd) == -1 ) return -3;<br>  return 0;<br><br>  in Traditional Erlang something like this;<br><br>  {ok,FD} = open(Name),<br>  {ok,Data} = read(FD),<br>  {ok,PD} = process_data(Data),
<br><br>  in BettErl (tm);<br><br>  process_data(read(open(Name))),<br><br>  TradErl is more verbose and binds worthless intermediate variables.<br><br>  TradErl has poor error reporting.<br>  it will either succeed or fail with "badmatch". not very helpful. the BettErl
<br>function will either succeed or throw useful stuff like {couldnt_open,Name} or<br>{read_failure,enoent}, because that's how functions are written in BettErl; they<br>either returns proper data or throws something meaningful.
<br><br>  so, to answer your question, tagged tuples encourages verbose code with poor<br>error reporting.<br>  in short, bad style. IMO.<br><br>  mats<br><br>p.s. i'm aware there are some oopses in the meta-code (e.g. memory leaks). but i
<br>don't think that has any bearing on my conclusion.<br>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>