[comp.lang.rexx] Iterating on Stems

jeffv@bisco.kodak.com (Jeff Van Epps) (03/10/91)

Hi gang.  I just got ARexx, and I've translated some Perl scripts to Arexx.
The Perl scripts used associative arrays, for which the ARexx equivalent
seems to be "stems" or "compound symbols".  Putting data in worked fine,
but getting them out was more complicated than necessary.

PERL:    while (($key,$value) = each(assocary)) { /* stuff */ }

ARexx:   ???

The question is, once you've stored the data, how do you get the system
to iterate over the "array", telling you the keys?

I solved it by storing the keys at the same time as the data, in a more
normal array (keys.1  keys.2  keys.3  etc.), with a count of how many keys
have been processed so far.  But this strikes me as a kludgy workaround for
a missing language feature.  Does the language feature exist and I just
missed it??

-- 
If the From: line says nobody@kodak.com, don't believe it.

    Jeff Van Epps          jeffv@bisco.kodak.com
                           rochester!kodak!bisco!jeffv

mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) (03/12/91)

In article <1991Mar9.215906.4976@ssd.kodak.com> jeffv@bisco.kodak.com (Jeff Van Epps) writes:
   I solved it by storing the keys at the same time as the data, in a more
   normal array (keys.1  keys.2  keys.3  etc.), with a count of how many keys
   have been processed so far.  But this strikes me as a kludgy workaround for
   a missing language feature.  Does the language feature exist and I just
   missed it??

That's pretty much the canonical way to do things. When I asked an
implementer about this, the answer was:

	"Because it's not a simple problem".

In Perl, it's simple - you have a one dimensional array, and are done
with it. In Rexx, you have multi-diminsional arrays. It's not uncommon
to do things like, though this is extreme):

array.index			/* Type information */
array.index.name		/* print name */
array.index.function		/* Name of function to invoke */
array.index.number		/* Numeric value */
array.index.string		/* String value */
array.index.multivalue		/* Multivalued object. */
array.index.multivalue.1	/* Type for this value */
array.index.multivalue.1.{function,number,string,multivalue}
array.index.multivalue.2
etc.

So, what would you have a Rexx version of "each(months)" return? The
list of values index can take on? That gives you all named objects,
but makes dealing with the multi-valued objects somewhat harder. The
list of all complete stems? That gives you everything, but requires
filtering them after the fact.

BTW, if you can come up with a good solution, I believe that people
who are on - or have the ear of people who are on - the ANSI Rexx
committee are listening in. So it may show up in a later version.

	<mike


--
He was your reason for living				Mike Meyer
So you once said					mwm@pa.dec.com
Now your reason for living				decwrl!mwm
Has left you half dead

jimm@amiga.UUCP (Jim Mackraz) (03/12/91)

(Jeff Van Epps) writes:
)Hi gang.  I just got ARexx, and I've translated some Perl scripts to Arexx.
)The Perl scripts used associative arrays, for which the ARexx equivalent
)seems to be "stems" or "compound symbols".  Putting data in worked fine,
)but getting them out was more complicated than necessary.
)
)PERL:    while (($key,$value) = each(assocary)) { /* stuff */ }
)
)ARexx:   ???
)
)The question is, once you've stored the data, how do you get the system
)to iterate over the "array", telling you the keys?
)
)I solved it by storing the keys at the same time as the data, in a more
)normal array (keys.1  keys.2  keys.3  etc.), with a count of how many keys
)have been processed so far.  But this strikes me as a kludgy workaround for
)a missing language feature.  Does the language feature exist and I just
)missed it??

Isn't that a bitch?  That's bugged me often.  Since external host
programs can access and modify a running script/exec's symbol table
(using the RVI methods), it struck me that this "missing piece"
would have been very useful.  Note that even the compiled host
program using RVI cannot iterate the stems..

The method you describe, using numbers as stem fields, is common.
People often place the count in keys.0.

You could also be more "symbolic" with fields foo.Name, foo.Addrress,
foo.Phone, foo.ExtraPhone, foo.Fax, and so on, and stash the field
name list in foo.Fields = "Name Address Phone ExtraPhone"

Then you could say something like:

	do i = 1 to words( foo.Fields )
	    field = word( foo.Fields, i )
	    say field||':' foo.Fields
	    end

    jimm
-- 
--- opinions expressed herein are my own. ---
"... Because they can."
		- profound punchline to joke about dogs