comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Empty FOREACH loop
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Empty FOREACH loop [message #75101] Tue, 15 February 2011 06:14 Go to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 2/14/11 8:08 pm, Paulo Penteado wrote:
>
> I also get the temporary variables stuff, and agree that things like
>
> foreach el,!null do print,el
> foreach el,[] do print,el
> foreach el,{} do print,el
>
> Should all do nothing, with no errors.
>
> But if foreach is given a named variable that is !null it does nothing
> as expected:
>
> IDL> n=!null
> IDL> foreach el,n do print,el

Even more interesting:

IDL> print, !version
{ x86_64 darwin unix Mac OS X 8.0.1 Oct 5 2010 64 64}
IDL> groups = !null
IDL> foreach g, groups do help, g

But:

IDL> print, !version
{ x86_64 linux unix linux 8.0 Jun 18 2010 64 64}
IDL> groups = !null
IDL> foreach g, groups do help, g
% Variable is undefined: GROUPS.
% Execution halted at: $MAIN$

This must be a fix in 8.0.1. I will do some more research, but sheds
some light on the original situation that was causing me some problems
debugging.

Mike
--
www.michaelgalloy.com
Research Mathematician
Tech-X Corporation
Re: Empty FOREACH loop [message #75107 is a reply to message #75101] Mon, 14 February 2011 19:08 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
I also get the temporary variables stuff, and agree that things like

foreach el,!null do print,el
foreach el,[] do print,el
foreach el,{} do print,el

Should all do nothing, with no errors.

But if foreach is given a named variable that is !null it does nothing
as expected:

IDL> n=!null
IDL> foreach el,n do print,el
IDL>

On Feb 14, 9:47 pm, Michael Galloy <mgal...@gmail.com> wrote:
> I was quite surprised when the following raised an error for me:
>
> IDL> foreach g, [] do help, g
> % Variable is undefined: <UNDEFINED>.
> % Execution halted at: $MAIN$
>
> Does this seem like unexpected behavior? I was expecting the loop just
> not to execute.
>
> Of course, whatever the right answer is, it shouldn't do this (as it
> does on my Mac):
>
> IDL> foreach g, [] do help, g
> % Temporary variables are still checked out - cleaning up...
>
> Mike
> --www.michaelgalloy.com
> Research Mathematician
> Tech-X Corporation
Re: Empty FOREACH loop [message #81734 is a reply to message #75101] Fri, 12 October 2012 14:33 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
> On 2/14/11 8:08 pm, Paulo Penteado wrote:
>>
>> I also get the temporary variables stuff, and agree that things like
>>
>> foreach el,!null do print,el
>> foreach el,[] do print,el
>> foreach el,{} do print,el
>>
>> Should all do nothing, with no errors.
>>
>> But if foreach is given a named variable that is !null it does nothing
>> as expected:
>>
>> IDL> n=!null
>> IDL> foreach el,n do print,el

Those examples are good, but today I realize I'd really like this to work (quietly do no iterations) if I use an undefined variable (such as an unfilled keyword variable):

IDL> foreach x, myUndefinedNonVariable do print,x
% Variable is undefined: MYUNDEFINEDNONVARIABLE.
% Execution halted at: $MAIN$

Would anyone else agree that with no elements in myUndefinedNonVariable, this should quietly do no iterations?

Cheers,
-Dick
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: dialog_pickfile crashing IDLDE
Next Topic: Pointer and structure question

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:10:06 PDT 2025

Total time taken to generate the page: 0.00640 seconds