Aleksi Niemelwrote:

> Matz:
>
> > |Q4: is there some way to redefinine "if (null) then ... else
> > .... end"
> > |to do neither the then nor the else statement!
> >
> > Sorry, there's no such way.  I've learned users often go beyond
> > designers' imagination.
>
> Lame work-around:
>
> def null
>   raise "bypassing both then and else"
> end
>
> puts "before if"
> begin
>   if null then
>     puts "then"
>   else
>     puts "else"
>   end
> rescue
>   puts "whee... skipped if"
> end
> puts "after if"
>
> before if
> whee... skipped if
> after if
>
>         - Aleksi

Matz wrote:

>
> But this is intersting.  If someone would come up with nice solution
> proposal, I'd like to consider implementing it (maybe).
>
>                                                         matz.

I think that a special exception handling mechanism could be implemented to give this behaviour.
So far in exception handlers we have concepts such as 'return' and 'retry', the new one could be called 'continue' or 'break'.

The behaviour would be such that it effectively assumes the presence of a rescue clause after every statement, and so a 'continue' simply abandons the current calling chain, returns a 'null' and proceeds to the next statement.

This could be used to skip the then .... else ... actions as demonstrated above, and also to implement solution to Q3 below

----
Q.3 given the code below is there a way to exit a call chain as follows

a=null
a.nice.way.to.avoid.testing.for.nil.all.of.the.time
[rescue] #assumed
    puts "having raised an axception, the handlers behaviour is to 'continue' which will arrive here"
[end]
#I want to get <HERE> as fast as possible!

----

I dont know how the performance of exception handling compares to that of message sending. If exception handling is that bad then it might be more efficient just to do the 11 message sends (in the example)

------

Well Matz, I hope that the material I have sent to the list inspires you! I think it would be great to have null implemented as part of the Ruby language!



regards

Keith


p.s Now all I have to do is persuade you to change the indexing of arrays to start from 1 rather 0 and we would have a perfect scripting language. :-)