Value for an Array that will not match any other Array.

General APL language issues

Value for an Array that will not match any other Array.

Postby paulmansour on Wed Nov 25, 2015 7:33 pm

So I want to initialize a variable that cannot match any other value provided by a user (another programmer, or anything really).

I came up with an empty namespace:

      ⎕NS ''


I think it is impossible to proved a value that will match the result of this.

I think there is no other value A(other than a class instance of some sort).

Am I right in both cases?
paulmansour
 
Posts: 375
Joined: Fri Oct 03, 2008 4:14 pm

Re: Value for an Array that will not match any other Array.

Postby StefanoLanzavecchia on Thu Nov 26, 2015 9:09 am

I asked myself the same question a few years ago and I came out with the same answer: an anonymous namespace is a wonderful unique value. It's a scalar and it can be given a reasonable appearance with []DF.
Its presence anywhere obviously blows the size of any until then homogenous array, but if used in in well controlled contexts is just marvelous.
I never had the problem of persisting it (in DCF files or send it through sockets) so I have no idea how it behaves there, if its identity it's preserved and so on.
User avatar
StefanoLanzavecchia
 
Posts: 93
Joined: Fri Oct 03, 2008 9:37 am

Re: Value for an Array that will not match any other Array.

Postby AndyS|Dyalog on Thu Nov 26, 2015 9:41 am

I have just added a check to the QAs to ensure that
      (⎕ns'')≢⎕ns''
1

with a comment that changing this would cause you problems.

The ideal solution should perhaps be based on associating UUIDs/GUIDs with the variables, but given that we do not have a built-in cross-platform mechanism for generating them, you would have to make a ⎕NA call or two to get them.
User avatar
AndyS|Dyalog
 
Posts: 245
Joined: Tue May 12, 2009 6:06 pm

Re: Value for an Array that will not match any other Array.

Postby Phil Last on Thu Nov 26, 2015 10:34 am

I too have used this mechanism but I doubt if
      z={N+←1 ⋄ ⎕ns''}⍣{⍺=z}z←⎕ns''⊣N←0
would not eventually return a 1, with N being ¯1+2*32 or some such.
User avatar
Phil Last
 
Posts: 576
Joined: Thu Jun 18, 2009 6:29 pm

Re: Value for an Array that will not match any other Array.

Postby AndyS|Dyalog on Fri Nov 27, 2015 8:57 am

I asked the developers about this, and they replied that each time you call ⎕ns'' the interpreter creates a new, independent object in the workspace. When comparing two refs, the interpreter looks to see if they are pointing to the same object in the workspace. Since they're not, the comparison fails.

I have been running your expression since yesterday; when I interrupted it N had a value greater than 2*33 ..
User avatar
AndyS|Dyalog
 
Posts: 245
Joined: Tue May 12, 2009 6:06 pm

Re: Value for an Array that will not match any other Array.

Postby JoHo on Fri Nov 27, 2015 9:53 am

Guessing about the implementation of ⎕NS in the background,
this could be running on only a few pooled unnamed namespaces:
could it be, that un-referenced NS is either re-used at the next loop or
garbage collected.
Would it make a difference to run this test like this:
Code: Select all
 z= {N+←1 ⋄ NSL,←⎕NS''}⍣{⍺=z}z←⎕NS''⊣ N←0⊣ NSL←''


EDIT1: corrected code to
Code: Select all
⍣{⍺=z}
User avatar
JoHo
 
Posts: 29
Joined: Sat Nov 28, 2009 12:51 pm
Location: Austria, EU

Re: Value for an Array that will not match any other Array.

Postby Phil Last on Fri Nov 27, 2015 1:55 pm

JoHo wrote:Would it make a difference to run this test like this:
I too wondered about gathering them but I guess WS FULL would ensue first.
Andy wrote:when I interrupted it N had a value greater than 2*33 ..
Me too!
Andy wrote:creates a new, independent object in the workspace
I guess that settles it. Good!
      )clear
clear ws
)wsid ws
was CLEAR WS
this←⎕ns''
)save
ws saved Fri Nov 27 13:39:53 2015
that←this
)copy ws this
.\ws saved Fri Nov 27 13:39:53 2015
this=that
0
⊢'cf'⎕fcreate 0
1
this ⎕fappend 1
that←⎕fread 1 1
this=that
0
Fairly convincing.
User avatar
Phil Last
 
Posts: 576
Joined: Thu Jun 18, 2009 6:29 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest