Value for an Array that will not match any other Array.
7 posts
• Page 1 of 1
Value for an Array that will not match any other Array.
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:
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?
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: 420
- Joined: Fri Oct 03, 2008 4:14 pm
Re: Value for an Array that will not match any other Array.
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.
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.
-
StefanoLanzavecchia - Posts: 109
- Joined: Fri Oct 03, 2008 9:37 am
Re: Value for an Array that will not match any other Array.
I have just added a check to the QAs to ensure that
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.
(⎕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.
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
Re: Value for an Array that will not match any other Array.
I too have used this mechanism but I doubt if
z={N+←1 ⋄ ⎕ns''}⍣{⍺=z}z←⎕ns''⊣N←0would not eventually return a 1, with N being ¯1+2*32 or some such.
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Value for an Array that will not match any other Array.
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 ..
I have been running your expression since yesterday; when I interrupted it N had a value greater than 2*33 ..
-
AndyS|Dyalog - Posts: 257
- Joined: Tue May 12, 2009 6:06 pm
Re: Value for an Array that will not match any other Array.
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:
EDIT1: corrected code to
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}
-
JoHo - Posts: 37
- Joined: Sat Nov 28, 2009 12:51 pm
- Location: Austria, EU
Re: Value for an Array that will not match any other Array.
I too wondered about gathering them but I guess WS FULL would ensue first.JoHo wrote:Would it make a difference to run this test like this:
Me too!Andy wrote:when I interrupted it N had a value greater than 2*33 ..
I guess that settles it. Good!Andy wrote:creates a new, independent object in the workspace
)clearFairly convincing.
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
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group