Re: Scope_VarFetch Bug or Feature? [message #47500] |
Tue, 14 February 2006 18:00  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
retsil@iinet.net.au writes:
> I think that Scope_VarFetch certainly opens up a lot of possibilities.
> At first I thought that it was just a hack tool for IDL, but it
> actually has some legitamite uses.
I can't really believe (or discuss) what I am doing with
it. But, yes, I am very, very impressed. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
|
|
|
Re: Scope_VarFetch Bug or Feature? [message #47505 is a reply to message #47504] |
Tue, 14 February 2006 14:33   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
=?ISO-8859-2?Q?F=D6LDY_Lajos?= writes:
> well, you can check it first:
>
> help, out=s, (Scope_VarFetch(names[j], Level=1, /Enter))
> if strpos(s, 'UNDEFINED =') gt 0 then print, 'Undefined'
>
> (you can't retrieve an undefined variable, but you can get a
> reference to it :-)
>
> And I think the ENTER keyword works, it just creates an undefined
> variable :-) You can create a defined variable by
>
> (Scope_VarFetch('something_new', Level=1, /Enter))=0
Ah, now all that screwy parentheses stuff I remember from
a couple of months ago when I first starting looking at
SCOPE_VARFETCH is starting to make some sense to me! :-)
Thanks guys.
Cheers,
David
P.S. Let's just say we were burning about $1000/hour with
a room full of Ph.D. physicists trying to figure it out from
the documentation earlier today, to no avail. :-(
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Scope_VarFetch Bug or Feature? [message #47506 is a reply to message #47505] |
Tue, 14 February 2006 14:23   |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
Hi David,
well, you can check it first:
help, out=s, (Scope_VarFetch(names[j], Level=1, /Enter))
if strpos(s, 'UNDEFINED =') gt 0 then print, 'Undefined'
(you can't retrieve an undefined variable, but you can get a
reference to it :-)
And I think the ENTER keyword works, it just creates an undefined
variable :-) You can create a defined variable by
(Scope_VarFetch('something_new', Level=1, /Enter))=0
regards,
lajos
On Tue, 14 Feb 2006, David Fanning wrote:
> Folks,
>
> Here is a short test program and main-level program:
>
> ;*****************************************************
> PRO test
>
> names = Scope_Varname(Level=1,Count=varcount)
> FOR j=0,varcount-1 DO BEGIN
> Print, 'Fetching variable ' + names[j] + '...'
> mainvar = Scope_VarFetch(names[j], Level=1, /Enter)
> Help, mainvar
> ENDFOR
>
> END
>
> a = 5
> b = c
> test
>
> END
> ;*****************************************************
>
> Compile and run the main-level program. Yes, it will
> cause an error. Don't worry about it. :-)
>
> When the error occurs, you will have two variables at
> the main level (LEVEL=1 in SCOPE_ parlance), a and b.
> The variable a is equal to 5 and b is undefined.
>
> Now, just type "test" and the test program runs.
> It will find both variables at the main level.
> But, as far as I can tell there is no way to learn
> anything more about the variables unless I retrieve
> them. BUT, I can't retrieve an undefined variable.
> It causes an error. :-(
>
> (According to the documentation the ENTER keyword should
> cause a variable with the name I am trying to fetch (b, in
> this case) to be created at the main-level, but this
> doesn't seem to work either. At least I still get the error.
> This DOES seem like a bug to me.)
>
> This is all causing me some heartburn, because I need to
> retrieve variables at a particular level and save them.
> All works well unless I try to retrieve undefined variables,
> and in this particular application, I cannot assume there
> won't be undefined variables.
>
> Does this seem like a bug to you, or a feature? Is the
> only alternative to CATCH the error?
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
|
|
|
|
Re: Scope_VarFetch Bug or Feature? [message #47551 is a reply to message #47500] |
Thu, 16 February 2006 14:41  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Tue, 14 Feb 2006 19:00:21 -0700, David Fanning wrote:
> retsil@iinet.net.au writes:
>
>> I think that Scope_VarFetch certainly opens up a lot of possibilities.
>> At first I thought that it was just a hack tool for IDL, but it actually
>> has some legitamite uses.
>
> I can't really believe (or discuss) what I am doing with it. But, yes, I
> am very, very impressed. :-)
IDLWAVE uses the precursor to SCOPE_VARFETCH, the undocumented
ROUTINE_NAMES, to allow pulling and examining variables from other
calling stack levels while stopped deep in a calling sequence. I like
to think that that pushed RSI over the edge to bundle it into a
supported set of routines (that and I bugged one of the developers
about it mercilessly). It's very useful. In object/widget code, I
often have a "Send project to command line" choice, which lets people
play with the object directly.
JD
|
|
|