Page 1 of 1

Copying all objects in a namespace

Posted: Mon Dec 27, 2010 1:54 am
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?

Re: Copying all objects in a namespace

Posted: Mon Dec 27, 2010 10:48 am
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'

Re: Copying all objects in a namespace

Posted: Mon Dec 27, 2010 10:54 am
by Phil Last
Sorry missed ↑ or ⊃ for mix depending on ⎕ML
      ⎕SE.toBeCopied←'#.source.ns.'∘,¨#.source.ns.⎕nl-⍳10
                     ∧
at point of caret   

Re: Copying all objects in a namespace

Posted: Mon Dec 27, 2010 2:50 pm
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

Re: Copying all objects in a namespace

Posted: Mon Jan 03, 2011 6:29 pm
by alexbalako
Now I am confused.
Why next will not work?
)cs Target
#.Target
)copy SourceWS Source.namespace
or:
'Source.namespace' Target.⎕CY 'SourceWS'

Re: Copying all objects in a namespace

Posted: Tue Jan 04, 2011 9:27 am
by Phil Last
Because #.Target will end up containing namespace namespace rather than the contents of namespace.

Re: Copying all objects in a namespace

Posted: Wed Jan 05, 2011 8:31 pm
by alexbalako
Phil, I know the difference and not arguing with your solution, but wander if that is what was asked in original question :)

Re: Copying all objects in a namespace

Posted: Wed Jan 05, 2011 11:27 pm
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?