Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nested IFs

249 views
Skip to first unread message

A.D. Fundum

unread,
Aug 1, 2013, 9:27:42 AM8/1/13
to
What's a fast but readable Rexx-way to replace a lot of IFs?

The number of nested IFs and memory usage is becoming a bigger problem
than the speed, I'm about to ask what the nesting limit is. I can
think of several solutions, one will do. Words? Array of names?
Another surprise?

IF name<>'Fred' THEN DO
IF name<>'Freddy' THEN DO
IF name<>'Saundra' THEN DO
IF name<>'Sandra' THEN DO
IF name<>'F' THEN DO
...
IF name<>'S' THEN SAY 'Accepted!'
...
END
END
END
END
END


--

Jeremy Nicoll - news posts

unread,
Aug 1, 2013, 10:07:00 AM8/1/13
to
"A.D. Fundum" <what...@neverm.ind> wrote:

>What's a fast but readable Rexx-way to replace a lot of IFs?
>
>The number of nested IFs and memory usage is becoming a bigger problem
>than the speed, I'm about to ask what the nesting limit is. I can
>think of several solutions, one will do. Words? Array of names?
>Another surprise?

I think it's going to depend on what your different IFs are doing (unless
you really do mean the example below?), and also how many times it's going
to be executed. A sneakier method might be faster but require more time
spent setting something up.

>IF name<>'Fred' THEN DO
> IF name<>'Freddy' THEN DO
> IF name<>'Saundra' THEN DO
> IF name<>'Sandra' THEN DO
> IF name<>'F' THEN DO
> ...
> IF name<>'S' THEN SAY 'Accepted!'

I'd usually use for this

namelist = "Fred Freddy Saundra Sandra F S"
if wordpos(name,wordlist) == 0 then say "Accepted"

However it looks to me as if you might also be looking at abbreviations
(perhaps of any length?) of the names. For example, would you need to
consider SA, SAU, SAUN etc? That suggests to me that Abbrev() might need to
play a part. But then again, especially if there were many potential names
maybe I'd statically or dynamically create:

nams.F = "F FR FRE FRED FREDD FREDDY"
nams.S = "S SA SAN SAU SAND SAUN SANDR SAUND SANDRA SAUNDR SAUNDRA"

then: namelet1 = substr(name,1)
namelist = nams.namelet1
if wordpos(translate(name),wordlist) == 0 then ...

Of course if you need to put meaningful code at any of the other points in
the IF / IF / IF structure, then none of this will work.

--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".

A.D. Fundum

unread,
Aug 1, 2013, 10:42:28 AM8/1/13
to
> (unless you really do mean the example below?)

Yes, the example is a short version of historical reality and could
indeed include both "F" and "Foo", which should represent different
names.

> if wordpos(name,wordlist) == 0 then say "Accepted"

Thanks, your usual solution is good enough for me. I'll change the
code to WordPos().

> However it looks to me as if you might also be looking at
> abbreviations (perhaps of any length?) of the names.

It looks like that, but it are different names. IRL "F" can be Ford,
and "Foo" may be the name of some Bar. I already noticed that the
current code didn't use strict matching, i.e. "<>=" (IIRC), albeit so
far this situation doesn't occur because all names and abbreviations
in the IF-nests are unique.


--

LesK

unread,
Aug 1, 2013, 6:13:00 PM8/1/13
to
For character comparison, I don't think strict is necessary, but case is
honored.

Btw: For general purposes, Select/When is better than nested If's.

--

Les (Change Arabic to Roman to email me)

A.D. Fundum

unread,
Aug 1, 2013, 7:04:54 PM8/1/13
to
> For character comparison, I don't think strict is necessary

That seems to be true, today I added the first situation where strict
matching would have mattered.

> Btw: For general purposes, Select/When is better than nested If's.

The Rexx prototype app processes downloaded third-party data, so
patches may be required each day to solve all kinds of possible daily
disasters. It started with a few IFs, but today I had to add about 40
IFs, and the size of the (tokenized) code became yet another problem.
Hence the original ugly patches, as opposed to a designed solution,
but the code now is improved.

It's a kind of white-list, which ignores each read record (just a
"records=records-1"), unless "record.records" contains a known name.
The underlying data is the problem. Most of it is ignored. If there
would be an usuable web form filter, then the form-id of the web form
changes each time so I cannot use the filter. Well, it now works fine
with WordPos().


--

Gerard_Schildberger

unread,
Aug 1, 2013, 7:18:30 PM8/1/13
to
For what you were about to ask:

PC/REXX and Personal REXX have a limit of 13 nested IFs.
Regina has a limit of 908.
R4 >66,177 (so far; I have tested up to that amount).


I'm tempted to keep editing the REXX program and add more
and more IF/END statements, but it was getting tedious.

Perhaps others could find the limit of CMS and TSO REXXes,
as well as ooRexx and the REXX compiler.


The nested IFs are of a simple kind, as the kind above.


Of course, if you need to get around the IF limit for
your (or A) REXX, you could convert the IF statements into
a huge SELECT thingy:
__________________________________________________________
select /*a herd of names.*/
when name=='Fred' then nop
when name=='Freddy' then nop
when name=='Saundra' then nop
.
.
.
otherwise say 'Accepted'
end /*select a herd of names.*/
______________________________________ Gerard Schildberger


LesK

unread,
Aug 2, 2013, 3:46:18 AM8/2/13
to
A couple of other things to consider:

1-The length of the string that contains the names of the GoodGuys
2-The performance of WordPos()

It might be worth the effort to consider using a content addressable
array that contains an ok? flag for each valid name. Something like this:

goodguys='Fred Freddy Saundra Sandra'
ok?.=0
do while goodguys\=''
parse var goodguys name goodguys
ok?.name=1
end
do r=1 to records
parse var record.r name .
if ok?.name then call keep_record
end
exit

If GoodGuys becomes unwieldy, just change it to a stemmed variable, or
design it that way to begin with.

Porter Smith

unread,
Aug 2, 2013, 9:10:32 AM8/2/13
to
Gerard_Schildberger <gera...@rrt.net> wrote in news:1d05f482-f8c8-4316-
9109-5bb...@googlegroups.com:

> Perhaps others could find the limit of CMS and TSO REXXes,
> as well as ooRexx and the REXX compiler.


On my CMS Level 24 system when my test REXX got to level 125 it blew up
with this error:

DMS458E Error 11 running fn ft, line nn: Control stack full

Explanation: This message is issued if you exceed the limit of 250 levels
of nesting of control structures (DO-END, IF-THEN-ELSE, and so forth).


Note that the message explanation says 250 levels, but my program died at
125.

When I tried to compile it, I got this error

FANPAR0090S Maximum nesting level of 999 exceeded

So I guess the answer is 125, 250 or 999.



Rick McGuire

unread,
Aug 2, 2013, 9:17:07 AM8/2/13
to
On Friday, August 2, 2013 9:10:32 AM UTC-4, Porter Smith wrote:
> Gerard_Schildberger <gera...@rrt.net> wrote in news:1d05f482-f8c8-4316-
>
> 9109-5bb...@googlegroups.com:
>
>
>
> > Perhaps others could find the limit of CMS and TSO REXXes,
>
> > as well as ooRexx and the REXX compiler.
>
>
>
>
>
> On my CMS Level 24 system when my test REXX got to level 125 it blew up
>
> with this error:
>
>
>
> DMS458E Error 11 running fn ft, line nn: Control stack full
>
>
>
> Explanation: This message is issued if you exceed the limit of 250 levels
>
> of nesting of control structures (DO-END, IF-THEN-ELSE, and so forth).
>
>
>
>
>
> Note that the message explanation says 250 levels, but my program died at
>
> 125.

The limit is 250, but the IF counts as one and if you are using THEN DO after the IF, that's a second control structure.

Rick

Gerard_Schildberger

unread,
Aug 2, 2013, 1:53:09 PM8/2/13
to
On Friday, August 2, 2013 8:10:32 AM UTC-5, Porter Smith wrote:
> Gerard_Schildberger wrote:
>> Perhaps others could find the limit of CMS and TSO REXXes,
>> as well as ooRexx and the REXX compiler.

> On my CMS Level 24 system when my test REXX got to level 125 it blew up
> with this error:
>
> DMS458E Error 11 running fn ft, line nn: Control stack full
>
> Explanation: This message is issued if you exceed the limit of 250 levels
> of nesting of control structures (DO-END, IF-THEN-ELSE, and so forth).
>
> Note that the message explanation says 250 levels, but my program died at
> 125.
>
> When I tried to compile it, I got this error

> FANPAR0090S Maximum nesting level of 999 exceeded
>
> So I guess the answer is 125, 250 or 999.

Regarding the CMS level of 250 (125?), maybe that REXX was
"reserving" an ELSE clause for each of the IF clauses,
as it has no way of knowing at this point if there is an
ELSE clause or not, so REXX has to "set one aside"/reserve
a clause in case an ELSE is coded.
______________________________________ Gerard Schildberger


Jeremy Nicoll - news posts

unread,
Aug 2, 2013, 5:21:58 PM8/2/13
to
Gerard_Schildberger <gera...@rrt.net> wrote:

> Regarding the CMS level of 250 (125?), maybe that REXX was "reserving" an
> ELSE clause for each of the IF clauses, as it has no way of knowing at
> this point if there is an ELSE clause or not...

Long ago I used S-Algol, which deliberately had different forms of IF
dependent on whether or not an ELSE was expected. I can't quite remember
the syntax but it was something like

if <condition> do { }

vv

if <condition> then { } else {}

Not only did it make the compiler simpler to write, but actually it was very
useful in eyeballing code because you knew as soon as you saw "do" that
there wouldn't be an else section later on.

Peter J. Seymour

unread,
Aug 3, 2013, 3:40:23 AM8/3/13
to
On 2013-08-02 22:21, Jeremy Nicoll - news posts wrote:
> Gerard_Schildberger <gera...@rrt.net> wrote:
>
>> Regarding the CMS level of 250 (125?), maybe that REXX was "reserving" an
>> ELSE clause for each of the IF clauses, as it has no way of knowing at
>> this point if there is an ELSE clause or not...
>
> Long ago I used S-Algol, which deliberately had different forms of IF
> dependent on whether or not an ELSE was expected. I can't quite remember
> the syntax but it was something like
>
> if <condition> do { }
>
> vv
>
> if <condition> then { } else {}
>
> Not only did it make the compiler simpler to write, but actually it was very
> useful in eyeballing code because you knew as soon as you saw "do" that
> there wouldn't be an else section later on.
>
Only have a THEN if there is also an ELSE. I like it. (speaking as one
who has dabbled in compiler writing).

Gerard_Schildberger

unread,
Aug 3, 2013, 1:57:16 PM8/3/13
to
On Saturday, August 3, 2013 2:40:23 AM UTC-5, Peter J. Seymour wrote:
> On 2013-08-02 22:21, Jeremy Nicoll - news posts wrote:
> > Gerard_Schildberger wrote:
> >> Regarding the CMS level of 250 (125?), maybe that REXX was "reserving" an
> >> ELSE clause for each of the IF clauses, as it has no way of knowing at
> >> this point if there is an ELSE clause or not...

> > Long ago I used S-Algol, which deliberately had different forms of IF
> > dependent on whether or not an ELSE was expected. I can't quite remember
> > the syntax but it was something like
>
> > if <condition> do { }
> > vv
> > if <condition> then { } else {}
> >
> > Not only did it make the compiler simpler to write, but actually it was very
> > useful in eyeballing code because you knew as soon as you saw "do" that
> > there wouldn't be an else section later on.

> Only have a THEN if there is also an ELSE. I like it. (speaking as one
> who has dabbled in compiler writing).

The "only" would be problematic. That would break practically all existing
REXX code. Now, if it would be optional, the only problem would be the
added keyword for IF statements, "DO". I also admire the idea. It
would make perusing someone else's code much easier.

Another problem I see is IBM updating their REXXes. It's pretty stagnant
and IBM has many flavors of REXX to enhance. _________ Gerard Schildberger

LesK

unread,
Aug 3, 2013, 5:34:59 PM8/3/13
to
The only IBM updating activity for Rexx going on is for z/OS. All the
others are 'mature'.

Gerard_Schildberger

unread,
Aug 3, 2013, 6:26:41 PM8/3/13
to
On Saturday, August 3, 2013 4:34:59 PM UTC-5, LesK wrote:
> On 8/3/2013 1:57 PM, Gerard_Schildberger wrote:
> > On Saturday, August 3, 2013 2:40:23 AM UTC-5, Peter J. Seymour wrote:
> >> On 2013-08-02 22:21, Jeremy Nicoll - news posts wrote:
> >>> Gerard_Schildberger wrote:
---[---sniped---]---
> > Another problem I see is IBM updating their REXXes. It's pretty stagnant
> > and IBM has many flavors of REXX to enhance. _________ Gerard Schildberger

> The only IBM updating activity for Rexx going on is for z/OS. All the
> others are 'mature'.
> --
> Les (Change Arabic to Roman to email me)

I didn't know IBM was updating REXX.

What kind of activity is IBM doing?

I assume they aren't expanding/enhancing REXX(es) as
per the ANSI standard:

* stream I/O (LINEIN, LINEOUT, CHARIN, CHAROUT,
STREAM, and QUALIFY BIFs)
* DATE and TIME enhancements [2nd, 3rd arguments]
* addition of the CHANGESTR and COUNTSTR BIFs
* VALUE (for different pools [environmental variables])
* support for whitespace (in addition to spaces)
* support for CASELESS and LOWER options for PARSE
* other stuff ?

I read (I think at this newsgroup) that IBM won't
enhance the REXX compiler, and thus they won't make REXX
incompatible with the compiler) or some such sentiment.
____________________________________ Gerard Schildberger


Jeremy Nicoll - news posts

unread,
Aug 3, 2013, 7:22:59 PM8/3/13
to
Gerard_Schildberger <gera...@rrt.net> wrote:

> I didn't know IBM was updating REXX. What kind of activity is IBM doing?

I don't know, but REXX is (or was?) an integral part of some IBM products,
eg their mainframe automation tools. I think one can embed rexx code inside
ISPF panel definitions too, or at least make panel code directly call rexx
execs - dunno how.

Even pre-2000 when I last used SA/390 automation, under NetView, there were
netview-specific addressing environments for REXX, just as there are
TSO-specific ones etc. I would think they'd continue to support & add to
its use, even if they don't adapt the core language.

LesK

unread,
Aug 3, 2013, 8:19:34 PM8/3/13
to
Virgil Hein of IBM presented the Status of Rexx at the Rexx Symposium in
May. As I said before, the _only_ activity going on is for z/OS. Iirc,
it mostly has to do with supporting specific z/OS data access
requirements. z/OS has the *only* Rexx Support group, as I understand
it. Even then, they have limited resources and have to prioritize all
their Requirements. Rexx on all other platforms is considered 'mature'
and stable as defined by SAA or the individual platform.

Bob Martin

unread,
Aug 4, 2013, 2:36:55 AM8/4/13
to
in 55230 20130803 185716 Gerard_Schildberger <gera...@rrt.net> wrote:
>On Saturday, August 3, 2013 2:40:23 AM UTC-5, Peter J. Seymour wrote:
>> On 2013-08-02 22:21, Jeremy Nicoll - news posts wrote:
>> > Gerard_Schildberger wrote:
>> >> Regarding the CMS level of 250 (125?), maybe that REXX was "reserving" an
>> >> ELSE clause for each of the IF clauses, as it has no way of knowing at
>> >> this point if there is an ELSE clause or not...
>
>> > Long ago I used S-Algol, which deliberately had different forms of IF
>> > dependent on whether or not an ELSE was expected. I can't quite remember
>> > the syntax but it was something like
>>
>> > if <condition> do { }
>> > vv
>> > if <condition> then { } else {}
>> >
>> > Not only did it make the compiler simpler to write, but actually it was very
>> > useful in eyeballing code because you knew as soon as you saw "do" that
>> > there wouldn't be an else section later on.
>
>> Only have a THEN if there is also an ELSE. I like it. (speaking as one
>> who has dabbled in compiler writing).
>
>The "only" would be problematic. That would break practically all existing
>REXX code. Now, if it would be optional, the only problem would be the
>added keyword for IF statements, "DO". I also admire the idea. It
>would make perusing someone else's code much easier.

On early versions of Rexx the IF did not require a THEN.
I remember going through all my code in 1982 adding in the THENs.

Shmuel Metz

unread,
Aug 4, 2013, 1:31:49 PM8/4/13
to
In <o8uYFJ3iqTdG-pn2-WwJp6irUEd41@localhost>, on 08/01/2013
at 03:27 PM, "A.D. Fundum" <what...@neverm.ind> said:

>What's a fast but readable Rexx-way to replace a lot of IFs?

The Devil is in the details. For a nest of IF statements with no ELSE
clauses, use an and:

IF name¬='Fred' & name¬='Freddy' & name¬='Saundra' & name¬='Sandra' &
name¬='F' THEN DO;

Often a nest of IF ELSE IF can be replaced with a SELECT statment.

Sometimes the use of deeply nested IF really is the simplest and most
readable option.


--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spam...@library.lspace.org

A.D. Fundum

unread,
Aug 9, 2013, 11:15:42 AM8/9/13
to
>> I didn't know IBM was updating REXX. What kind of activity is IBM
doing?

> I don't know, but REXX is (or was?) an integral part of some IBM
products,

Is, for example the IBM-licensed product eComStation will still be
shipped with one of the most often used Rexx and ORexx interpreters.
This Rexx interpreter was as dead as the email address of some retired
fellow in e.g. the IBM NetRexx manuals, but an example of an actual
fix of "stable" code were the Y2K-related changes. In their own
README.1ST-words:

5.0 NEW FUNCTION

It is our policy not to include new function in
FixPaks. However, as with any policy there
may be exceptions. If any exception occurs
in the future, we will communicate them to you
in this section of the README.1ST.

5.1 QUERYING FILE DATES FOR FILES AFTER DEC 31, 1999 IN REXX


--

Shmuel Metz

unread,
Aug 13, 2013, 8:02:00 AM8/13/13
to
In <o8uYFJ3iqTdG-pn2-oR8KdKeKDdRw@localhost>, on 08/09/2013
at 05:15 PM, "A.D. Fundum" <what...@neverm.ind> said:

>Is, for example the IBM-licensed product eComStation will still be
>shipped with one of the most often used Rexx and ORexx interpreters.
>This Rexx interpreter was as dead as the email address of some
>retired fellow in e.g. the IBM NetRexx manuals, but an example of an
>actual fix of "stable" code were the Y2K-related changes. In their
>own README.1ST-words:

There is a major difference between updating the language and simply
adding a new function to a function package. AFAIK, IBM no longer
enhances REXX on any platform; certainly mot in NetView or TSO, much
less OS/2.
0 new messages