On Wed, Oct 24, 2012 at 9:45 AM, Staffan Tylen <staffan.tylen@gmail.com> wrote:

I'm not sure what you were expecting.   But in both m1 and m2 you pass back the same object you passed in.  So in the main part of the program a and b both point to the same object.

Since they are the same object any change made to b is a change made to a.

In m3 you create a new object and pass that object back.  Now in the main program a points to one object and b points to a second object.  A change made to the second object will not be seen in the first object.


The point I was trying to make is that ooRexx and the USE ARG statement differs significantly from just ARG, at least in non-ooRexx environments. This was all new to me, because USE ARG works with pointers while ARG does what the copy method does, creates a copy of the input argument. At least it works so in the mainframe Rexx that I'm used to, where you cannot modify a caller's argument because you get a copy of it.

Well, actually, no it does not differ.  The ARG instruction deals with just strings, which are immutable.  If all you are passing are string values, then there is no way to alter the value of the string object such that the change would be visible from both variable values.  This is true whether you are using ARG or USE ARG.  It is only because you are using array objects, which do have mutable internal state can you see the changes. 

And this has nothing at all to do with the USE ARG instruction, which is really just a glorified assignment statement.  You can produce the same effect with just inline assignment statements:

a = .array~of(1)

myarg = a   -- essentially what USE ARG does
myarg[1] = 2   -- update the internal array state

b = myarg   -- same effect as your return statement

say a[1]  -- displays "2"

replace the assignment of myarg with "myarg = a~copy", and you get the same effect as your m3 version.  The variables no longer refer to the same object, so the changes are not visible via variable "a".

Rick

Staffan


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users