Copying all objects in a namespace

General APL language issues
Post Reply
michaelk
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am

Copying all objects in a namespace

Post by michaelk »

Probably a silly question, but if I wish to copy all objects in a namespace in workspace W to a namespace in a different workspace X is there a simple way to do this?
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Copying all objects in a namespace

Post by Phil Last »

michaelk wrote:Probably a silly question, but if I wish to copy all objects in a namespace [#.source.ns] in workspace W to a namespace [#.target.ns] in a different workspace X is there a simple way to do this?


You could try this; I'm afraid I've had time to test it only once right now.

      )XLOAD W
      ⎕SE.toBeCopied←'#.source.ns.'∘,¨#.source.ns.⎕nl-⍳10
      )XLOAD X
      ⎕SE.toBeCopied #.target.ns.⎕CY 'W'
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Copying all objects in a namespace

Post by Phil Last »

Sorry missed ↑ or ⊃ for mix depending on ⎕ML
      ⎕SE.toBeCopied←'#.source.ns.'∘,¨#.source.ns.⎕nl-⍳10
                     ∧
at point of caret   
JohnS|Dyalog

Re: Copying all objects in a namespace

Post by JohnS|Dyalog »

This alternative uses essentially the same method as Phil's:

      )xload X
...
      )copy dfns refws
...
      (refws'W').source.('#.target' ⎕ns ⎕nl ⍳10)

      )erase refws

See http://www.dyalog.com/dfnsdws/n_refws.htm
alexbalako
Posts: 16
Joined: Mon Nov 30, 2009 8:58 pm

Re: Copying all objects in a namespace

Post by alexbalako »

Now I am confused.
Why next will not work?
)cs Target
#.Target
)copy SourceWS Source.namespace
or:
'Source.namespace' Target.⎕CY 'SourceWS'
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Copying all objects in a namespace

Post by Phil Last »

Because #.Target will end up containing namespace namespace rather than the contents of namespace.
alexbalako
Posts: 16
Joined: Mon Nov 30, 2009 8:58 pm

Re: Copying all objects in a namespace

Post by alexbalako »

Phil, I know the difference and not arguing with your solution, but wander if that is what was asked in original question :)
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Copying all objects in a namespace

Post by Phil Last »

I see what you mean. I guess if it doesn't matter what the resultant namespace is called then the straightforward solution fulfils the requirement. We can always create a global ref with the name of our choice.

In fact moving items from one space to another with a different name can have repercussions if the code makes use of named refs be they absolute or relative. So it's probably safer if it is the same.

The way APL# is going it looks as though at some time in the future we won't have the choice. All refs to a space will be equally the "actual" space their having no fixed abode. Just as #.thisSpace.(3) and #.thatSpace.(3) refer to the same number 3. Or do they?
Post Reply