Proper command syntax to copy entire namespace

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

Proper command syntax to copy entire namespace

Postby jmosk on Fri Aug 02, 2013 12:43 am

I have a namespace #.space1 and I would like to make a copy of it in #.space2. How can I copy all of the functions in namespace space1 without having to tag each function with the path from space1.

)cs #
)save <wsid>
)cs #.space2
)copy <wsid> space1.name1 space1.name2 ... - will copy name1 and name2 but I don't want to put the prefix on 30 function names

I tried )copy <wsid> space1 - thinking the entire space would be copied but it does not.

Is there a way to specify the entire namespace? Is there a way to specify a list of functions in the desired source namespace to be copied without having to prefix each name with the namespace ID? I should point out that the names being copied from space1 also happen to be in the # namespace, so I need to make sure it does not pull in the wrong copy. Needs to pull in the #.space1 copy and not the # copy.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Proper command syntax to copy entire namespace

Postby Phil Last on Fri Aug 02, 2013 9:11 am

If you mean you want the contents of space1 in space2 then this:
      #.space1.('#.space2'⎕NS ⎕NL⍳10)

which probably needs explanation.

Of several calling sequences for ⎕NS the one used here takes a name left argument (⍺) and a namelist right argument (⍵). A namespace named for ⍺ is created if it doesn't already exist. If ⍺ is not fully qualified it will be created in the context in which the expression is evaluated. The space is then populated with the items named in ⍵. If those names are not fully qualified they are copied from the context in which ⎕NS executes. Notice in the above that both ⎕NS and ⎕NL execute inside #.space1 but ⍺ is qualified to target the root. So the names in ⍵ are from space1 and ⎕NS recognises them as such.

If you mean you want the result to be #.space2.space1 with space1 being the only item in space2 then:
      '#.space2'⎕NS'#.space1'
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Proper command syntax to copy entire namespace

Postby DanB|Dyalog on Fri Aug 02, 2013 7:31 pm

)COPYing ws space1 from within space2 will only copy space1, not its contents.

If you wish to copy (clone) an entire space you can use
Code: Select all
'space2' ⎕NS ⎕OR 'space1'

If your namespace happens to be SALTed (it is found on file as a text document) you can select items from it like this:
Code: Select all
]load /mydir/space1 -disperse=name1 name2... -target=space2
DanB|Dyalog
 

Re: Proper command syntax to copy entire namespace

Postby jmosk on Fri Aug 02, 2013 10:36 pm

'space2' ⎕NS ⎕OR 'space1' is pretty obscure as opposed to a )copy command. It would appear that this command will copy all the functions in namespace space1 to a new namespace space2. If space2 already exists, will it overwrite the function with the same names, leave the existing functions in space2 which have different names than in space1 intact, and will it copy any new function names in namespace space1 into namespace space2?

What syntax could be used if I had say 6 specific functions in namespace space1 that I wanted to copy into namespace space2 instead of the entire namespace space1 being copied into namespace space2. Functions f1, f2, f3, f4, f5 and f6. I wish to avoid having to use #.space1.f1 #.space1,f2 etc.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Proper command syntax to copy entire namespace

Postby Phil Last on Sat Aug 03, 2013 7:22 am

)COPY and ⎕CY each copy an entire workspace or a set of named items into the space from which it is called. The named items can include other spaces but they will be copied in their entirety, not dispersed as a set of members. If the named items are not fully qualified their (partially qulified) names will be assumed to be relative to the root (#). So the ONLY way to use copy for what you want is to do it exactly the way that you reject.

⎕NS really is the way to do it whether in conjunction with the highly questionable ⎕OR or using a more conventional method. It also avoids the possibility that the saved workspace has been overwritten or indeed never saved; you get actual copies of the items currently in memory rather than arbitrarily old versions or those saved from another source.

To answer your second question, replace the reference to ⎕NL⍳10 in the first solution above with the specific list of simple names. You can even assign the list to a variable and name that instead:
      #.space1.list←↑'fn0' 'fn1' 'fn2' ...
#.space1.('#.space2'⎕NS list)
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Proper command syntax to copy entire namespace

Postby jmosk on Sat Aug 03, 2013 11:32 am

Thanks Dan. I wasn't rejecting the solution, I was only pointing out that it is not as straight forward as a simple command like )copy.

Can you please explain the syntax of the name list command ⎕NL and how to interpret the ⎕NL ⍳10 statement? This is unclear. And exactly how does one interpret the ⍺ and ⍵ parameters of the ⎕NS command. This will help to make the command syntax you specified more understandable. As I understand it, the ⎕OR that Dan specified is required to change the representation of a character vector into an internal representation that would be acceptable by the ⎕NS command.

Thank you for the explanation as the documentation I read was a bit confusing.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Proper command syntax to copy entire namespace

Postby DanB|Dyalog on Sun Aug 04, 2013 12:42 pm

⎕OR "packs" an object (fn, var, ns) into a single entity.
Something usually frowned upon as it is often incompatible from one version to the next version of APL (internal representation may change).
Nonetheless it can come in handy as in this case here where you want to clone an ENTIRE ns.

⎕NL takes integers as right arg, each denoting a special "class" (e.g. 2=var, 3=fn). The available classes today range from 1 (label) to 9 (ns).
By using ⍳10 you cover the numbers 0..9 or 1..10 which includes 1..9 regardless of ⎕IO.

⎕NS' parameters are left (⍺): the name to use for you ns, right: (⍵) the names of the objects you want to include in this new ns. Note that if the ns name already exists the 2 nss will be merged and the objects brought in will replace any existing one.

The execution of ANY fn usually happens in the current ns (unless ⎕PATH is involved). If you want the execution to happen elsewhere, in another ns, you can use the dot syntax to make it so. Ex: 'newname' THERE.⎕NS ListofNamesYouWant
Do here ⍺ is 'newname', ⍵ is ListofNamesYouWant and the execution will happen in ns THERE.
DanB|Dyalog
 

Re: Proper command syntax to copy entire namespace

Postby jmosk on Sun Aug 04, 2013 3:45 pm

Dan - In the # namespace, I executed '#.temp' ⎕NS ⎕OR '#.spacetoclone' which copied the namespace spacetoclone to the namespace temp. But you indicated that if the namespace already exists (temp) that the namespaces would be merged. So I executed this same command a second time. According to what you said, this should copy everything again overriding what was already copied to temp. But doing the command a second time produces a DOMAIN ERROR. Only the first execution was successful.
+←--------------------------------------------------------------→
+ Jay Moskowitz
+←--------------------------------------------------------------→
+ http://www.linkedin.com/in/jay-moskowitz-5745b83
+
User avatar
jmosk
 
Posts: 69
Joined: Thu Jul 18, 2013 5:15 am

Re: Proper command syntax to copy entire namespace

Postby DanB|Dyalog on Mon Aug 12, 2013 11:46 am

This is wrong but I cannot reproduce this error at my end.
Can you give a specific example? And which version are you using (try ]uversion)
DanB|Dyalog
 

Re: Proper command syntax to copy entire namespace

Postby Vince|Dyalog on Wed Aug 14, 2013 12:15 pm

Hi Jay,

I can reproduce a domain error which I think is the same as yours.

I have logged this issue as 9845. We use an internal, unnamed symbol as part of our .Net interface implementation. It is this that is causing the domain error in the ⎕NS ⎕OR operation.

There are 2 ways to accomplish what you want to do.

1)
Phil Last’s suggestion where he said:
If you mean you want the contents of space1 in space2 then this:

Code: Select all
#.contest2013.('#.temp2' ⎕NS ⎕NL ⍳10)


2) Our Workspace Explorer tool can do the copy as well.

Regards,

Vince
Vince|Dyalog
 
Posts: 413
Joined: Wed Oct 01, 2008 9:39 am


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest