Re: Crash or return forbidden value?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Shawn Pringle wrote:
> 
> CChris wrote:
> > 
> > Currently, the interpreter always checks the validity of any index or slice,
> > and errors out whenever a test fails.
> > 
> > My point is: there is no need to duplicate the testing made by the
> > interpreter,
> > and it should do the testing. Just allow RTFatal() to do something smarter,
> > like skipping the call or branching to some place. This would make the user
> > code more efficient (no duplicate tests) and cleaner, as part of the error
> > handling
> > will simply be in the backand, where it is already. 
> > 
> > CChris
> 
> What you are talking about here is building an Exception system into the
> interpreter. 

Exactly. In an earlier post, I was showing how Eiffel does it - simpler, but
less flexible.

 It would be analogous to try/throw/catch and Exceptions like
> in Java or C++.  Perhaps exceptions could be less invasive than adding C++ 
> syntax if say some new builtin routines such as a register_exception_routine
> were added.  Routines that are passed to that function would get called
> in case of exceptions.  There would have to be a special return mechanism
> for these functions.  They could return to the offending routine's caller.

Either the calling statement (retry) or the next one. Both have separate uses.

> 
> You can put in some kind of side effect like syntax keyword:
> onexception (s[6] = 4) {
>  ..
> }
> 
> 
> On the other hand, perhaps compiled code could remove the second check
> after an if statement.
> 
> s[6] = 5 -- check is done to make sure s is a sequence and 6 is a valid index
> 
> if sequence(s) and length(s) > 7 then
>       s[6] = 5 -- no check is made to make sure s is a sequence for the
>                 -- the user did it.  Additionally 7 and 6 are constants
>                 -- so index checking could be eliminated at compile time
>                 -- too.
> end if
> 
> Shawn Pringle

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu