From: eric@sejnet.sunet.se (Eric Thomas)
Newsgroups: comp.lang.rexx
Subject: Re: do over stem
Date: 26 Aug 92 02:53:38 GMT
Reply-To: ERIC@SEARN.SUNET.SE
Organization: SUNET, Stockholm, Sweden

In article <ANDERS.92Aug25001604@lise3.lise.unit.no>, anders@lise3.lise.unit.no (Anders Christensen) writes:
> In article <179f67INNkfm@stanley.cis.Brown.EDU> Andre_Lehovich@Brown.Edu (Andre Lehovich) writes:
>> I want to be able to loop a variable over a stem, like so:
>>[...]
>> do i over foo.
>>   say i
>> end
>
> OK, here are some possible problems, or at least some points which has
> to be cleared up:
> 
> 1) You can in general not expect to get the list in any predefined
>    order.

I don't care about the order.

> 2) What if you set a new compound variable during the loop.

The behaviour should be well defined, either a run-time error or a consistent
behaviour (you always/never see the new variable), I don't care either since I
won't set new variables in the loop.

> 3) Tails can contain any character, not just "nice" whole numbers

This is precisely what I would have liked the "do over" for, 6 years ago. Now
it's too late, I am moving away from REXX as fast as I can.

> why do you want to
> do this? It does not add anything to the language that you can't
> easily control in other ways. 

No but it saves me a lot of programming time and would significantly improve
performance while decreasing memory requirement for some programs. I can't
count the number of times I had to write code like:

 list = ''
 Do <whatever, read a file or something>
    If blah Then
     Do
        k.x = something
        list = list x
     End
    (...)
    Select
      When bluh Then
        Do
           k.x = something
           list = list x
        End
    (...)
    End
 End

When your stem has 20 tails, it is only a royal pain in the butt to program
this way. But when it has 5000 and you are happily adding the 5001st
userid@node to the nice 150kb 'list' variable, then copying it back into
'list', and off we go to number 5002, it hurts. It doesn't only hurt you, it
hurts the whole system to spend your life copying buffers of 150kb to a scratch
150kb location, appending 20 bytes, and copying back to another 150kb buffer,
then releasing the first one. Of course you don't do that, you do:

 li = 1
 Do <whatever, read a file or something>
    If blah Then
     Do
        k.x = something
        If Length(list.li) < 4000
         Then list.li = list.li x
         Else
          Do
             li = li + 1
             list.li = x
          End
     End
    (...)
    Select
      When bluh Then
        Do
           k.x = something
           If Length(list.li) < 4000
            Then list.li = list.li x
            Else
             Do
                li = li + 1
                list.li = x
             End
        End
      (...)
    End
 End

Even more entertaining to code, even more intuitive to understand, but at least
the paging volume doesn't go into one of its fits of schyzophrenia during which
it thinks it is a washing machine and acts as such. The only REXX construct
that scales up is the stem, so why should I have to use a stupid linear
variable and duplicate a lot of information (especially when the stem doesn't
store that much data) when all I need is a way to run over all the existing
tails of the stem?

By the way, I have implemented such a stem system in PASCAL. Variables are
presented in the order in which they were created. If you create a new variable
in the loop, you will see it before the loop ends. If you drop a variable you
have not seen yet, you will not see it. If you drop the current one, you will
see the next one just the same. It wasn't particularly difficult to implement,
and it would have been very easy to generate an error code or run-time error if
you attempt to touch the stem while it is being scanned.

  Eric
Newsgroups: comp.lang.rexx