DO x in /A(rray) array_name ...

May 20, 2008
10,624
81
Syracuse, NY, USA
I've been using arrays a lot and I'm tired of typing
Code:
do i=0 to %@dec[%@arrayinfo[array_name,1]]
and later having to refer to %array_name[%i].

[And I don't know if you can overload "/A".]

But it would be very convenient to be able to process a 1-D array like this.
Code:
do x in /A array_name ...
and later refer to %x.
 
Aug 23, 2010
587
7
I think just
Code:
DO x IN %[array]
…
ENDDO
should work.
Or add @ARRAY[] variable function for that purpose.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,221
78
Albuquerque, NM
prospero.unm.edu
How about:
Code:
rem  Any array:
DO x IN AROWS arrayname

rem  Array with at least two dimensions:
DO x IN ACOLS arrayname
This is all just syntax sugar. It doesn't have to be implemented by Rex. A plugin can massage command parameters. Or you could write an alias or two.
 
May 20, 2008
10,624
81
Syracuse, NY, USA
How about:
Code:
rem  Any array:
DO x IN AROWS arrayname

rem  Array with at least two dimensions:
DO x IN ACOLS arrayname
This is all just syntax sugar. It doesn't have to be implemented by Rex. A plugin can massage command parameters. Or you could write an alias or two.
1-D would be fine with me and I suspect relatively easy compared to that one. If /A(rray) isn't available, I like /V(ector); after all a vector is a 1xN array.
 
May 20, 2008
10,624
81
Syracuse, NY, USA
I think just
Code:
DO x IN %[array]
…
ENDDO
should work.
Or add @ARRAY[] variable function for that purpose.
It doesn't.
Code:
v:\> setarray a[10] & do i=0 to 9 (set a[%i]=%i)

v:\> do x in %[a] echo %x
Usage : DO [n | FOREVER]
And I wouldn't expect it to work. "%[a]" is a reference to the environment variable whose name is "a".
Code:
v:\> set a=2

v:\> echo %[a]
2
What would @ARRAY[] do?