Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Tools for Rebol Coders

From: joel:neely:fedex at: 8-Jan-2002 13:32

Hi, Greg, Sunanda, et al... Gregg Irwin wrote:
> > -- I write some code that calls something from your site > > that calls something from someone else's. And at some point > > it crashes with an "Error near a / b". > > > > Is that my code or yours or the other person's or a Rebol- > > supplied mezzanine function? I don't care how un-purist it > > is to expect the call stack to be printed. But I need it at > > this point or the application is dead in the water. > > I think this points out that we, as REBOL developers, need to > take into account the context in which our code is intended to > be used. I can appreciate being able to write simple reblets > that are self-contained and often times may get by with a > minimum of error handling and formal design. > > If you are writing code to be used in distributed applications, > you darn well better have everything error trapped and be as > helpful as possible when it comes to tracking down errors. I > think Design by Contract will be enormously helpful in that > regard but I haven't had time to work up a dialect implementing > it yet. >
Let's not forget what REBOL alreay provides, which most of us (myself included) probably don't use to full benefit. Pretend that I have some REBOL source files from elsewhere: 8<----"buggyfunc.r"--------------------------------------------- REBOL [] buggyfunc: func [a [integer!] b [integer!]] [a / b] 8<-------------------------------------------------------------- and 8<----"buggywrap.r"--------------------------------------------- REBOL [] buggywrap: func [n [integer!] /local r] [ r: copy [] either even? n [ repeat i n [append r 5040 / i]] [ repeat i n [append r 5040 / (8 - i)]] r ] 8<-------------------------------------------------------------- and now I want to use those bits of scriptage myself. I can write: 8<----"buggytest.r"--------------------------------------------- REBOL [] do %buggyfunc.r do %buggywrap.r testbug: func [n [integer!] /local r] [ either error? r: try [buggywrap n] [ print ["Oops! buggywrap blew up when called with" n "!"]] [ print ["Pretend to do something useful" newline tab mold r]] ] 8<-------------------------------------------------------------- which wraps the "untrusted" code in a TRY evaluation to let me know whether (and under what circumstances) the foreign code may cough and die.
>> do %buggytest.r >> testbug 5
Pretend to do something useful [720 840 1008 1260 1680]
>> testbug 6
Pretend to do something useful [5040 2520 1680 1260 1008 840]
>> testbug 7
Pretend to do something useful [720 840 1008 1260 1680 2520 5040]
>> testbug 8
Pretend to do something useful [5040 2520 1680 1260 1008 840 720 630]
>> testbug 9
Oops! buggywrap blew up when called with 9 ! I suspect that some creative uses of TRY would go a long way toward addressing the issues of making more robust code (even when it uses other, untrusted, foreign components). -jn-