Discussion:
Looping with alpha characters
(too old to reply)
Lizette Koehler
2017-06-27 19:15:06 UTC
Permalink
Raw Message
This is just to make sure I am not going down the wrong path.



I need to create a loop that will be based on Alpha Characters



So



Do I = a to j

End



To do this, I think the only process is to use the C2D in the DO part



Do I = C2D(a) to C2D(j)

End



Is that correct? Or is there a better way?

Thanks





Lizette Koehler

statistics: A precise and logical method for stating a half-truth inaccurately




----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2017-06-27 19:30:48 UTC
Permalink
Raw Message
Post by Lizette Koehler
This is just to make sure I am not going down the wrong path.
I need to create a loop that will be based on Alpha Characters
So
Do I = a to j
End
To do this, I think the only process is to use the C2D in the DO part
Do I = C2D(a) to C2D(j)
End
Is that correct? Or is there a better way?
More generally, to loop over a discontiguous collection of
characters (I hate EBCDIC!), I abuse PARSE:

S = 'abcdefghijklmnopqrstuvwxyz'
/* or S = xrange( 'a', 'i' )xrange( 'j', 'r' )xrange( 's', 'z' ) */
do while S>>''
parse value S with I 2 S
....
end

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Horacio Villa
2017-06-27 19:35:58 UTC
Permalink
Raw Message
C2D(a) gives me 54997, while with C2D(j) I get 209.

Horacio Villa


----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2017-06-27 19:44:03 UTC
Permalink
Raw Message
Post by Horacio Villa
C2D(a) gives me 54997, while with C2D(j) I get 209.
What does:
signal on novalue
say C2D(a) C2D(j)
print?

Then:
say C2D('a') C2D('j')

(Lizette made the same mistake.)

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Paul Gilmartin
2017-07-05 15:26:29 UTC
Permalink
Raw Message
@horacio : It's just because, in your context, a is initialized with "ON"
while j is not initialized and is assumed to have the value of "J".
Try ;
C2D("a") ==> 129
C2D("j") ==> 145
@lizette : The principle is good but you should quote a and j ("a" and "j")
to avoid uppercase translation.
Do I = C2D("a") to C2D("j")
car = D2C(l)
say car
...
End
"I"? "l"? Whatever. Even if Lizette intends the implied uppercase,
I prefer to quote all character constants explicitly. This also
avoids @horacios' surprise. I enforce this on myself by using SIGNAL
ON NOVALUE everywhere.
Beware : It will work fine because EBCDIC codes of characters from a to j
abcdefghi:::::::jk
where ":" stands for non dispayable character (under ISPF).
And it might work if coded and tested on an ASCII platform, then
suddenly fail in EBCDIC. I prefer solutions that explicitly enumerate
the desired value set.

-- gil

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Gerard Schildberger
2017-06-27 19:39:12 UTC
Permalink
Raw Message
Post by Lizette Koehler
This is just to make sure I am not going down the wrong path.
I need to create a loop that will be based on Alpha Characters
So
Do I = a to j
End
To do this, I think the only process is to use the C2D in the DO part
Do I = C2D(a) to C2D(j)
End
Is that correct? Or is there a better way?
If you meant to code (for lowercase letters):

do i='a' to 'j' ...


{as you have it coded, REXX will uppercase the A and J
to uppercase.)


do i=c2d('A') to c2d('J') /*using uppercase letters. */
if ¬datatype(d2c(i), 'M') then iterate /*Not a letter? Then skip.*/
...something processed here...
end /*i*/


This could be extended to 'Z' (instead of 'J').

As coded, this will also work for an ASCII machine as well as EBCDIC.

It should be noted that there are other characters (in EBCDIC)
between (both lower and uppercase versions) the letters
'I' and 'J', as well as between
'R' and 'S' (most of which are probably not displayable).
__________________________________ Gerard Schildberger
Mike Holder
2017-06-27 19:49:21 UTC
Permalink
Raw Message
Why not convert the number to an alphabetic character?

DO XX = 1 to 10
I = SUBSTR('abcdefghij',XX,1)
...
END XX

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of Lizette Koehler
Sent: Tuesday, June 27, 2017 3:16 PM
To: TSO-***@VM.MARIST.EDU
Subject: Looping with alpha characters

This is just to make sure I am not going down the wrong path.



I need to create a loop that will be based on Alpha Characters



So



Do I = a to j

End



To do this, I think the only process is to use the C2D in the DO part



Do I = C2D(a) to C2D(j)

End



Is that correct? Or is there a better way?

Thanks





Lizette Koehler

statistics: A precise and logical method for stating a half-truth inaccurately




----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Lizette Koehler
2017-06-27 20:42:30 UTC
Permalink
Raw Message
One of my considerations is that the number of letters used, might change.

At this time, it is sequential - a b c d e...x but there is a possibility that
some or any of the letters might be removed or altered in the sequence.

After a couple of offlist posts, I like this idea so far. Then if anything
changes, code changes are minimal.

Vars = 'a b c d e f g '
Do I = 1 to Words(Vars)
MyVar = Word(vars,i)
Say MyVar
End

Lizette
Post by Mike Holder
-----Original Message-----
Mike Holder
Sent: Tuesday, June 27, 2017 12:50 PM
Subject: Re: [TSO-REXX] Looping with alpha characters
Why not convert the number to an alphabetic character?
DO XX = 1 to 10
I = SUBSTR('abcdefghij',XX,1)
...
END XX
-----Original Message-----
Sent: Tuesday, June 27, 2017 3:16 PM
Subject: Looping with alpha characters
This is just to make sure I am not going down the wrong path.
I need to create a loop that will be based on Alpha Characters
So
Do I = a to j
End
To do this, I think the only process is to use the C2D in the DO part
Do I = C2D(a) to C2D(j)
End
Is that correct? Or is there a better way?
Thanks
Lizette Koehler
statistics: A precise and logical method for stating a half-truth inaccurately
----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Ze'ev Atlas
2017-06-27 23:23:31 UTC
Permalink
Raw Message
That is the best way to do it.  You do not care about the values of the letters and you may change the order at will Ze'ev Atlas



From: Lizette Koehler <***@MINDSPRING.COM>
To: TSO-***@VM.MARIST.EDU
Sent: Tuesday, June 27, 2017 4:44 PM
Subject: Re: [TSO-REXX] Looping with alpha characters

One of my considerations is that the number of letters used,  might change.

At this time, it is sequential - a b c d e...x  but there is a possibility that
some or any of the letters might be removed or altered in the sequence.

After a couple of offlist posts, I like this idea so far.  Then if anything
changes, code changes are minimal.

  Vars = 'a b c d e f g '
  Do I = 1 to Words(Vars)
    MyVar = Word(vars,i)
    Say MyVar
  End

Lizette
Post by Mike Holder
-----Original Message-----
Mike Holder
Sent: Tuesday, June 27, 2017 12:50 PM
Subject: Re: [TSO-REXX] Looping with alpha characters
Why not convert the number to an alphabetic character?
DO XX = 1 to 10
  I = SUBSTR('abcdefghij',XX,1)
...
END XX
-----Original Message-----
Sent: Tuesday, June 27, 2017 3:16 PM
Subject: Looping with alpha characters
This is just to make sure I am not going down the wrong path.
I need to create a loop that will be based on Alpha Characters
So
Do I = a to j
End
To do this, I think the only process is to use the C2D in the DO part
Do I = C2D(a) to C2D(j)
End
Is that correct?  Or is there a better way?
Thanks
Lizette Koehler
statistics: A precise and logical method for stating a half-truth inaccurately
----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX




----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Jeremy Nicoll
2017-06-27 23:47:49 UTC
Permalink
Raw Message
Post by Ze'ev Atlas
That is the best way to do it.  You do not care about the values of the
letters and you may change the order at will Ze'ev Atlas
Sent: Tuesday, June 27, 2017 4:44 PM
Subject: Re: [TSO-REXX] Looping with alpha characters
One of my considerations is that the number of letters used,  might change.
At this time, it is sequential - a b c d e...x  but there is a possibility that
some or any of the letters might be removed or altered in the sequence.
After a couple of offlist posts, I like this idea so far.  Then if anything
changes, code changes are minimal.
  Vars = 'a b c d e f g '
  Do I = 1 to Words(Vars)
    MyVar = Word(vars,i)
    Say MyVar
  End
/IF/ you really do think that the options - here individual characters -
might be
arbitrarily sized words in future, then yes.

But the code that a rexx interpreter executes to count the number of
words in
a string is far more complicated than just returning the length of a
string. And
each time around the loop when you ask for successive words from the
string
rexx has to start all over again counting words along the string to find
the one
you want.

With short strings as here it'll make little difference, but why waste
cpu cycles?

letters = "abcdefg"
do l = 1 to length(letters)
lthletter = substr(letters,l,1)
say lthletter
end

is FAR less work for the interpreter. If you have to chop words out of
a string
then eg

sentence = "the cat sat on the mat under
the elephant "
do forever
parse var sentence firstwrd sentence
say firstwrd
if sentence = "" then leave
end

or something like that is better. There's no need to count the number
of words,
nor expensive location of (eg) the millionth word in a very long
sentence.
--
Jeremy Nicoll - my opinions are my own.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Ze'ev Atlas
2017-06-28 03:56:06 UTC
Permalink
Raw Message
You are correctI liked the concept rather than the implementation. Ze'ev Atlas

From: Jeremy Nicoll <***@LETTERBOXES.ORG>
To: TSO-***@VM.MARIST.EDU
Sent: Tuesday, June 27, 2017 7:49 PM
Subject: Re: [TSO-REXX] Looping with alpha characters
Post by Ze'ev Atlas
That is the best way to do it.  You do not care about the values of the
letters and you may change the order at will Ze'ev Atlas
  Sent: Tuesday, June 27, 2017 4:44 PM
  Subject: Re: [TSO-REXX] Looping with alpha characters
   
One of my considerations is that the number of letters used,  might change.
At this time, it is sequential - a b c d e...x  but there is a possibility that
some or any of the letters might be removed or altered in the sequence.
After a couple of offlist posts, I like this idea so far.  Then if anything
changes, code changes are minimal.
  Vars = 'a b c d e f g '
  Do I = 1 to Words(Vars)
    MyVar = Word(vars,i)
    Say MyVar
  End
/IF/ you really do think that the options - here individual characters -
might be
arbitrarily sized words in future, then yes.

But the code that a rexx interpreter executes to count the number of
words in
a string is far more complicated than just returning the length of a
string.  And
each time around the loop when you ask for successive words from the
string
rexx has to start all over again counting words along the string to find
the one
you want.

With short strings as here it'll make little difference, but why waste
cpu cycles?

letters = "abcdefg"
do l = 1 to length(letters)
      lthletter = substr(letters,l,1)
      say lthletter
end

is FAR less work for the interpreter.  If you have to chop words out of
a string
then eg

sentence = "the  cat sat                on the mat              under 
  the elephant  "
do forever
    parse var sentence firstwrd sentence
    say firstwrd
    if sentence = "" then leave
end

or something like that is better.  There's no need to count the number
of words,
nor expensive location of (eg) the millionth word in a very long
sentence.
--
Jeremy Nicoll - my opinions are my own.

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX



----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
David W Noon
2017-06-27 21:42:14 UTC
Permalink
Raw Message
On Tue, 27 Jun 2017 12:16:04 -0700, Lizette Koehler
(***@MINDSPRING.COM) wrote about "[TSO-REXX] Looping with alpha
characters" (in <00c201d2ef79$d3c77070$7b565150$@mindspring.com>):

[snip]
Post by Lizette Koehler
To do this, I think the only process is to use the C2D in the DO part
Do I = C2D(a) to C2D(j)
End
Almost correct. Try:

DO i = C2D('a') TO C2D('j')

/* Extract the letter. */
l = D2C(i)

END

You need to wrap the letters in apostrophes to prevent 2 things:
i) variable substitution;
ii) case folding to capitals.

An alternative way that is independent of ASCII/EBCDIC considerations is
to iterate over a string, thus:

/* This string generates correct binary code points for
whatever encoding the system uses. */
letters = 'abcdefghijklmnopqrstuvwxyz'

last_letter = INDEX(letters, 'j') /* Or whatever last letter. */

DO i = 1 TO last_letter

/* Extract letter. */
l = SUBSTR(letters, i , 1)

END

HTH
--
Regards,

Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
***@googlemail.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Gerard Schildberger
2017-06-27 22:30:05 UTC
Permalink
Raw Message
-------- snipped --------
Post by David W Noon
An alternative way that is independent of ASCII/EBCDIC considerations is
/* This string generates correct binary code points for
whatever encoding the system uses. */
letters = 'abcdefghijklmnopqrstuvwxyz'
last_letter = INDEX(letters, 'j') /* Or whatever last letter. */
DO i = 1 TO last_letter
/* Extract letter. */
l = SUBSTR(letters, i , 1)
END
Another version could be:

letters= 'abcdefghijklmnopqrstuvwxyz' /*the lower-case alphabet. */
last_letter= 'j' /*the last lower-cased letter. */

do i=1 until x==last_letter /*loop through alphabet 'til ... */
x=substr(letters, i, 1) /*extract a letter from alphabet.*/
say 'x=' x /*or something else productive. */
end /*i*/



Or, if you prefer WHILEs:


do i=1 while x¬==last_letter /*loop through alphabet while ...*/
.
.
.
__________________________________________________ Gerard Schildberger
Robin
2017-06-27 23:54:54 UTC
Permalink
Raw Message
I probably don't understand your requirement (loop ?) but suspect what you
are looking for is the ability to increment a given alpha character to the
next letter in the alphabet. I had that requirement and experimented to find
that the most efficient method in REXX was to use the builtin TRANSLATE
function

Alpha_Add:
Return translate(arg(1),'
ABCDEFGHIJKLMNOPQRSTUVWXYZ','ABCDEFGHIJKLMNOPQRSTUVWXYZA')

-----Original Message-----
From: TSO REXX Discussion List [mailto:TSO-***@VM.MARIST.EDU] On Behalf Of
Lizette Koehler
Sent: June 27, 2017 3:16 PM
To: TSO-***@VM.MARIST.EDU
Subject: [TSO-REXX] Looping with alpha characters

This is just to make sure I am not going down the wrong path.



I need to create a loop that will be based on Alpha Characters



So



Do I = a to j

End



To do this, I think the only process is to use the C2D in the DO part



Do I = C2D(a) to C2D(j)

End



Is that correct? Or is there a better way?

Thanks





Lizette Koehler

statistics: A precise and logical method for stating a half-truth
inaccurately




----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions, send email
to ***@VM.MARIST.EDU with the message: INFO TSO-REXX

----------------------------------------------------------------------
For TSO-REXX subscribe / signoff / archive access instructions,
send email to ***@VM.MARIST.EDU with the message: INFO TSO-REXX
Loading...