I totally agree! I have avoided using mapped files because they violate good
programming practices. One must go to great lengths to avoid the pitfalls of
mapped files when writing a script. Many scripts supplied
by JSoftware and by others modify x and y in explicit definitions. And
assigning y to another name and then modify it is just as bad. Big no-no's
for mapped files.
As to passing mapped files references by name, looks to me that J always
passes by name, but if the local name is modified the name reference is
removed and the local name is given separate storage. Why not do the same
thing with mapped files? Why do they have to be special? As long as the
contents of the local name are not modified no extra memory will be
allocated.
foo=:3 : 0
r=.7!:0''
vv=.y
r=.r,7!:0''
vv=.>:y
r=.r,7!:0''
vv=.y
r=.r,7!:0''
)
7!:0''
5880256
w=.?1000000$0
foo w
14270144 14270272 22658880 14270272
Notice that "vv" in "foo" above has to be passed by name but if "foo"
modifies the local reference it very nicely avoids to "by name" pitfall
making it work like passing "by value".
If someone wants to modify a file, them only allow doing it by using the
original name used to map the file.
On 3/31/07, Joey K Tuttle <[EMAIL PROTECTED]> wrote:
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm