Guidance
指路人
g.yi.org
Guidance Forums / Reginald Rexx / Stem tail substitution

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Stem tail substitution
#12554
Posted by: PeterJ 2008-12-06 16:16:18
the following code sequence returns an error:

CB.peter.0=5
var='Peter'
say cb.var

CB.Peter has no value.

It seems Reginald stem tails become case sensitive if created/accessed via tail substition.

Whereas 
Cb.Fred=5
say cb.fred

is case insensitive.
 
Is this behaviour intended? I couldn't check how Z/OS Rexx behaves.

Peter
Message2.
#12555
Posted by: Jeff Glatt 2008-12-06 19:27:12 Last edited by: Jeff Glatt 2009-03-04 13:43:13 (Total edited 2 times)
Yep, tail names are case-sensitive. There's a discussion of this in "The REXX Language -> Variable Arrays".
Message3.
#12557
Posted by: PeterJ 2008-12-06 19:42:19
ok, understand!
I just wonder why then

Cb.Fred=5
say cb.fred

works as if there was no difference between Cb.Fred and Cb.fred

No problem for me, I just like to understand ...
Message4.
#12558
Posted by: Doug Arndt 2008-12-06 22:29:21 Last edited by: Jeff Glatt 2009-03-04 13:49:29 (Total edited 3 times)
I believe all undefined variables are internally defined as their upper case name, at least used to be, the NOVALUE catch confuses that.

Try this...

Cb.Fred=5
say cb.fred
say cb.FRED

var = 'FRED'
say cb.var

You'll note they all work. But if you put a  "say Fred" in there, that fails due to NOVALUE. (With legacy Reginald, it used to give "FRED". Everything used to default to the uppercase value, but now you'll crash).
Doug
Message5.
#12561
Posted by: Jeff Glatt 2008-12-07 06:26:57 Last edited by: Jeff Glatt 2009-03-04 13:51:01 (Total edited 8 times)
What you do is take advantage of substitution itself to use a variable name that is not all upper case:
/* Assign a value that is mixed case to a variable that
 * we intend to use as a tail name
 */
i = 'Peter'

/* The variable "i" is being used as a tail name. Therefore its
 * value is substituted. The substituted value is "Peter".
 * So the variable (being set to 1) is "CB.Peter". This is a
 * different variable than "CB.PETER", or "CB.peter", etc.
 */
cb.i = 1

/* See above comment for the substitution of "i". */
SAY cb.i
I just wonder why then

Cb.Fred=5
SAY cb.fred

works as if there was no difference between Cb.Fred and Cb.fred

This works because, when REXX loads a script, it automatically upper-cases everything except what is inbetween quotes (ie, a literal string). So your script gets loaded as:

CB.FRED = 5
SAY CB.FRED

Notice that everything not in quotes is converted to upper-case. So, the mixed case in your original script is irrelevant. The variables names match up once the script is loaded.

So tail names that you specify in the script always take on upper-case. You therefore normally don't run into problems until you do that tail assignment above, which is what Peter did:
/* Everything not in quotes is automatically upper-cased.
 * So the following line, when loaded is actually:
 *
 * CB.PETER = 5
 */
cb.peter = 5

VAR = 'Peter'

/* The variable "var" is being used as a tail name. Therefore its
 * value is substituted. The substituted value is "Peter".
 * So the variable (being displayed) is "CB.Peter". This is a
 * different variable than "CB.PETER", which was set to 5 above.
 * In fact, "CB.Peter" was never assigned a value, so what is
 * displayed is the variable name "CB.Peter". Actually, Reginald Lite
 * automatically raises the NOVALUE condition here to alert you
 * to a potential problem.
 */
SAY cb.var
The moral of the story:

When you intend to use a variable as a tail name, make sure the variable's value is numeric (ie, defeats substitution), or is all upper-case. (Or, the variable was never assigned a value, in which case its value is the variable name upper-cased).
cb.peter = 5

/* NOTE: All upper-case value */
VAR = 'PETER'

SAY cb.var
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0