Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > copy an array
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 20th March 00:37
cobolman
External User
 
Posts: 1
Default copy an array



Is it possible in plain rexx (not object) to copy an array, in the same
way you copy a single variabel?

Clearly this syntax does not work:
array2 = array1

I've made a workaround using to loops:
/* copy array */
do i = 0 to 100
do j = 0 to 10
interpret "array2.i.j = array1.i.j"
end
end

Is there a more 'performance friendly' way to do this?

Thanks!!
  Reply With Quote


 


2 20th March 05:22
rick mcguire
External User
 
Posts: 1
Default copy an array



Well, you can start by getting rid of interpret. It's completely
unnecessary and very expensive from a performance standpoint.

/* copy array */
do i = 0 to 100
do j = 0 to 10
array2.i.j = array1.i.j
end
end
  Reply With Quote
3 20th March 05:22
rony
External User
 
Posts: 1
Default copy an array


Also, you could try the following:

a=.array~new /* create an array */
a[1,2]=11 /* fill it */
a[2,3]=22 /* fill it */
b=a~copy /* create a copy of the array 'a' */
say "a:" a[1,2] a[2,3] /* show array 'a' */
say "b:" b[1,2] b[2,3] /* show array 'b' */

say "---"

b[1,2]=33 /* replace an entry in copied array */
say "a:" a[1,2] a[2,3] /* show array 'a' */
say "b:" b[1,2] b[2,3] /* show array 'b' */

Yields:

a: 11 22
b: 11 22
---
a: 11 22
b: 33 22

HTH,

---rony
  Reply With Quote
4 20th March 05:22
rony
External User
 
Posts: 1
Default copy an array


Also, if you insist on using stems, you could do the following in ooRexx (<http://www.ooRexx.org>):

a.1.2=11 /* fill it */
a.2.3=22 /* fill it */

b.=a.~copy /* create a copy of the stem 'a.' (ooRexx) */

say "a:" a.1.2 a.2.3 /* show stem 'a.' */
say "b:" b.1.2 b.2.3 /* show stem 'b.' */

say "---"

b.1.2=33 /* replace an entry in copied setm */
say "a:" a.1.2 a.2.3 /* show stem 'a.' */
say "b:" b.1.2 b.2.3 /* show stem 'b.' */

Yields:

a: 11 22
b: 11 22
---
a: 11 22
b: 33 22

[Remark: the tilde (~) is the message operator in ooRexx, left of it is the receiver, right of it
the name of the message. In ooRexx "everything is an object", hence you can send the "copy" message
to a stem (object) as well and receive a copy of the receiving object (a stem).]


HTH,

---rony
  Reply With Quote
5 20th March 05:22
cobolman
External User
 
Posts: 1
Default copy an array


Rick,

Thanks!! The interpret is as you stated useless, but still .. I was
looking for an other way of copying the array

---------
rony:

This code

Will only work in Object Rexx, which is not the version which I am
using.
But thanks!
  Reply With Quote
6 20th March 05:22
rony
External User
 
Posts: 1
Default copy an array


Maybe you can get access to an external Rexx function like "SysStemCopy" or the like (you did not
mention the Rexx version you are using)?

Regards

---rony

P.S.: "Object Rexx" executes normal Rexx programs normally (you do not have to use the OO parts of
ooRexx, but could take advantage from time to time of some of its benefitial features, like the
built-in "copy" mechanism, or external functions like the aforementioned "SysStemCopy"). ooRexx is
free, opensource (actually using the original IBM code for Object REXX) and about a month ago a
newer version got released. (Installing doesn't even take a minute.)
  Reply With Quote
7 20th March 05:22
arthur t.
External User
 
Posts: 1
Default ooRexx vs. Regina (was Re: copy an array)**


In Message-ID:<eeot6l$1gao$1@trane.wu-wien.ac.at>,


I make extensive use of Patrick McPhee's function packages.
If I were to switch from Regina to ooRexx, would I have to forego
these packages and recode? (I suspect the answer is "yes", but I
thought it worth an ask.)

Current system:
parse source output (edited): WIN32 COMMAND
parse version output: REXX-Regina_3.3(MT) 5.00 25 Apr 2004
Microsoft Windows 2000 [Version 5.00.2195]

--
Arthur T. - ar23hur "at" intergate "dot" com
Looking for a good MVS systems programmer position
  Reply With Quote
8 20th March 05:22
ml
External User
 
Posts: 1
Default copy an array


Which part of "not object" don't you understand? :-o

---
  Reply With Quote
9 20th March 05:22
gerard schildberger
External User
 
Posts: 1
Default copy an array


|> Is it possible in plain rexx (not object) to copy an array, in the same
|> way you copy a single variabel?
|>
|> Clearly this syntax does not work:
|> array2 = array1
|>
|> I've made a workaround using to loops:
|> /* copy array */
|> do i = 0 to 100
|> do j = 0 to 10
|> interpret "array2.i.j = array1.i.j"
|> end
|> end
|>
|> Is there a more 'performance friendly' way to do this?

| Well, you can start by getting rid of interpret. It's completely
| unnecessary and very expensive from a performance standpoint.
|
| /* copy array */
| do i = 0 to 100
| do j = 0 to 10
| array2.i.j = array1.i.j
| end
| end

Even faster yet:

do i=0 for 100
do j=0 for 10
array2.i.j=array1.i.j
end
end

And even faster still:

do j=0 for 10
do i=0 for 100
...
end
end
__________________________________________________ ___Gerard S.
  Reply With Quote
10 20th March 05:22
eric h.
External User
 
Posts: 1
Default ooRexx vs. Regina (was Re: copy an array)**


I'm not certain about those packages specifically but MOST stuff that
runs on Regina will work on ooRexx with no mods. There was an issue here
or there when I converted but overall it's been pretty painless. I'm
looking at the packages right now and I THINK that some of their
functionality has been integrated with ooRexx so you might have to do
some recoding but maybe nothing too drastic. You could always run a test
system to see if it'll work for you or how much work it would take to
make it work for your needs.
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666