Return UNDEFINED from a function [message #50730] |
Wed, 11 October 2006 15:57 |
MarioIncandenza
Messages: 231 Registered: February 2005
|
Senior Member |
|
|
Unfortunately, this appears to be possible. This is somewhere between
a) another example of what a dunderhead I am, and b) a serious flaw in
the IDL compiler, and I'm not sure where right now.
Witness this function:
function return_undefined,this=this,that=that
on_error,2
if n_elements(this) ne 0 then thisthat=0
if n_elements(that) ne 0 then thisthat=1
return,thisthat
end
Now, in IDL:
% Compiled module: RETURN_UNDEFINED.
IDL> test=return_undefined()
% Variable is undefined: <UNDEFINED>.
% Execution halted at: $MAIN$
IDL> help,return_undefined()
<Expression> UNDEFINED = <Undefined>
This is the actual root cause of the "Variable is undefined:
<UNDEFINED>" error I experienced a few months back.
What's going on here is that IDL never checks to see if the value in
the RETURN statement is defined. So, if you use HELP, you can
immediately tell that your function is for some reason trying to return
an undefined variable. But if you use PRINT, or simply try to assign
the results, you get this profoundly unhelpful error.
Shouldn't the RETURN statement check to see that its argument is
defined? Am I wrong that this is bad compiler behavior?
--Edward H.
|
|
|