Re: Short-cut evaluation Question

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

----- Original Message ----- 
From: "Travis Beaty" <twbeaty at osage.net>
To: <EUforum at topica.com>
Subject: Short-cut evaluation Question


> 
> 
> Hello everyone!
> 
> I've got a question here about short-cut evaluation.  As reference here, I'm 
> using the Linux version of the 2.4 interpreter.  I'm pretty sure this is a 
> bug between my ears as opposed to a bug in the interpreter, but I'd like to 
> get some clarification on this.
> 
> I have the following type declaration:
> 
> 
> global type Widget(object o)
> 
> if not atom(o) then
> return false
> else
> return (o = 0 or TypesMatch(o, "QWidget") or IsBaseClass(o, "QWidget"))
> end if
> 
> end type
>

Short-cut eval does not work with return. Only with 'if' and 'while'.
> 
> Now then, in this particular instance I have confirmed via trace that o is 
> equal to zero.  It seems to me that since we are testing using "or" in the 
> return statement, if any expression in the test evaluates to "true," then the 
> entire expression would be true.  If that is the case, then short-cut 
> evaluation should stop processing the expression at that point and return 
> true.
> 
> Thus, in the case of the return statement here, the interpreter should see 
> that, indeed, o = 0, and then return true.  But it is not ... it in instead 
> evaluating TypesMatch(o, "QWidget"), which is causing my library to become 
> quite upset, since o is a NULL pointer.
> 
> Now, it would be easy for me to add the line
> 
> elsif o = 0 then
> return true
> 
> But apparently I'm not understanding something about short-cut evaluation 
> here.  Could anyone enlighten me?
> 
> Thanks,
> 
> Travis W. Beaty
> Osage, Iowa.
> 
> -- 
> Infancy, n.:
> The period of our lives when, according to Wordsworth, "Heaven lies
> about us."  The world begins lying about us pretty soon afterward.
> -- Ambrose Bierce
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
>

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

Search



Quick Links

User menu

Not signed in.

Misc Menu