On Sat, Oct 1, 2016 at 10:23 AM, Marshall Lochbaum <[email protected]> wrote:
> J's arrays are immutable in normal use. When you write (2 (7}) a), J
> makes a new copy of (a), changes the value at index 2 to a 7, and
> returns that array, which is now unrelated to (a). There's no way to
> modify the original array using (}) alone.
>
> J has had an exception to this general rule for a while, in-place
> assignment. If you write
> a =: 2 (7}) a
> then J will modify the contents of (a) to replace index 2 with a 7. This
> is a mutable operation, and it changes other copies of (a) as well: if
> you executed (b =: a) before that line then the value of (b) would
> change.

This statement (that the value of (b) would change here) is not the
case, and a simple test should show that it's not the case:

test=:3 :0
  a=:i. 8
  b=:a
  a=:2 (7)} a
  a,:b
)

   test''
0 1 2 3 4 5 6 2
0 1 2 3 4 5 6 7

That said, there is an exception to that abstraction that J's arrays
are immutable in normal use, where modifying one variable modifies
another, and that is where the contents of both variables are shared
with the operating system (specifically, where they are both mapped to
the same file, and that file is modifiable).

But that is not what we are talking about here.

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to