David,

I want to go on record (again) saying that I think the
documented behavior of passing unrestricted references
when a noun names a mapped file is very dangerous. It
is very easy for a bug (say a typo) to lead to the
destruction of an entire existing database that may be
in use by others, or impossible to recreate.

Further, your example shows yet another kind of side
effect that seems to me to be very bad practice if not
outright pernicious - my hope is that your example will
persuade jsoftware to reconsider (and change) the local
references of mapped names to be READ-ONLY.

That is, changed so that an innocent looking line like
   y =. ''
cannot, in any case, cause the destruction of a file
mapped with a name like LIVEDATA to be destroyed by
something like -
  foo LIVEDATA
...

- joey


At 14:15  +0200 2007/03/31, david alis wrote:
I do hope that the following is a supported feature.

The documentation relating to mapped variables explains
that names refering to such variables are always treated
as references.
It explains that passing a mapped variable
into an explicit function means that the reference is passed,
meaning that x or y are no longer local copies. i.e. changing
the arguments changes the contents in the underlying file.

I have noticed that this reference property applies more
generally.

If I assign to a variable a boxed vector of mapped variables
then I can pass this variable into an explicit function
and manipulate the mapped variables directly.
(The code below demonstrates this feature).

This feature provides the valuable property of indirection
and offers an elegant way to modularise the implementation
of an application.

So far, however, I havent been able to find any reference
to this kind of behaviour thus I am nervous about using it.
Hence this posting.

Is there something I have missed in the documention?
Is this an undocumented feature that should be avoided?
Do either Roger or Eric have any guidance?


Regards

David


require'jmf'
  unmapall_jmf_''
  createjmf_jmf_'aa';10000
  createjmf_jmf_'bb';10000
  createjmf_jmf_'cc';10000

  map_jmf_'aa';'aa'
  map_jmf_'bb';'bb'
  map_jmf_'cc';'cc'

  ]xx=.5?.10
6 9 1 4 0

  aa=:100+xx
  bb=:200+xx
  cc=:300+xx

  xaa=:100+xx
  xbb=:200+xx
  xcc=:300+xx

  data  =: aa;bb;cc  NB. mapped variables
  xdata =: xaa;xbb;xcc  NB. ordinary variables

  data -: xdata
1

foo=: 4 : 0
NB. x is the data to be manipulated
'value index' =.y
 for_loop. i.#x
 do.
    4!:55 <'w'   NB. temporary name
    w=.>loop{x
    NB. if x contains mapped variables
    NB. then w has become a  reference
    w =. (loop+value) index }w
 end.
 i.0 0
)


  data foo 1 1   NB. mapped variables are changed
  data
+-----------------+-----------------+-----------------+
|106 1 101 104 100|206 2 201 204 200|306 3 301 304 300|
+-----------------+-----------------+-----------------+

  xdata foo 1 1 NB. ordinary variables are unchanged
  xdata
+-------------------+-------------------+-------------------+
|106 109 101 104 100|206 209 201 204 200|306 309 301 304 300|
+-------------------+-------------------+-------------------+

  data=:xdata   NB. reassign to contain ordinary data

  data foo 21 4
  data
+-------------------+-------------------+-------------------+
|106 109 101 104 100|206 209 201 204 200|306 309 301 304 300|
+-------------------+-------------------+-------------------+

  data  =: xaa;bb;xcc   NB. only the second item is mapped.
  data foo 10000 2
  data    NB. only the second item is changed.
+-------------------+-------------------+-------------------+
|106 109 101 104 100|206 2 10001 204 200|306 309 301 304 300|
+-------------------+-------------------+-------------------+
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to