How to undo a scripted namespace ?

SALT, SPICE, Subversion, etc...

How to undo a scripted namespace ?

Postby PGilbert on Wed Apr 22, 2015 12:12 am

Suppose that you have a scripted namespace that you have downloaded from the internet and that you have installed in your workspace. What would be the procedure to 'unscript-it' (without any text representation of the namespace).

Thanks in advance.
User avatar
PGilbert
 
Posts: 360
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to undo a scripted namespace ?

Postby Phil Last on Wed Apr 22, 2015 7:02 am

I believe SALT contains a facility to read a script and disperse its contents into the root. I don't know if you can target a normal or unnamed space created with ⎕NS.

Alternatively it's a one-liner dfn to do the same thing to a script that's already in the ws.
      {n⊣('n'⊣n←⎕NS'')⎕NS ⍵}
Using ⎕NS on it's own merely clones the script. It's a bit more complicated if the script is nested.
User avatar
Phil Last
 
Posts: 441
Joined: Thu Jun 18, 2009 6:29 pm

Re: How to undo a scripted namespace ?

Postby Vince|Dyalog on Wed Apr 22, 2015 9:30 am

Hi Pierre and Phil,

      'myns' ⎕ns ''
]load e:\tmp\ns_script.txt -disperse -target=#.myns
* 3 objects dispersed in #.myns


In this example, ns_script.txt is a namespace script in a UTF-8 file and #.myns is the (existing) namespace where you want the contents of the namespace script to go.

Regards,

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

Re: How to undo a scripted namespace ?

Postby Phil Last on Wed Apr 22, 2015 9:52 am

Looks good Vince. The target space must be "named" (created using dyadic ⎕NS) but otherwise is fine. Also rebuilds the hierarchy for a nested script as named container spaces correctly unlike my one-liner above. Well done Dan!
User avatar
Phil Last
 
Posts: 441
Joined: Thu Jun 18, 2009 6:29 pm

Re: How to undo a scripted namespace ?

Postby PGilbert on Wed Apr 22, 2015 11:56 am

Thanks Phil and Vince this is answering my question. I was looking at something like Phil explained. I did not want to save the namespace to file and recall the file with 'disperse'. But just to show the alternative in case of 'complex' namespace:

Code: Select all
]save #.myns1 d:\myns1.txt   ⍝ Will save #.myns1 as a text file

'myns2' ⎕ns ''               ⍝ Creates an empty namespace named 'myns2'

⍝ Load back 'myns1' into 'myns2' but unscripted
]load d:\myns1.txt -disperse -target=#.myns2 
User avatar
PGilbert
 
Posts: 360
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to undo a scripted namespace ?

Postby Phil Last on Wed Apr 22, 2015 5:43 pm

I was writing "off the top of my head" and here's a clearer way to do exactly the same thing:
      {('n'⎕ns⍵)⊢n←⎕ns''}
but as usual I write before researching and it seems I'm not on top of the latest developments.
My reference to nested spaces was because until I last looked the above would only have copied vars, fns and ops and would have left subspaces behind or in some cases it gave a DOMAIN ERROR - I never managed to identify precisely what cases or why - possibly something to do with external and cross refs.
I'm afraid I'm one who usually looks for a work-around rather than reporting a bug because I reason that if it doesn't already work I must be the first to try so probably it was never intended to do that and no-one else will want it anyway.
Well it turns out things have progressed and now it does copy subspaces. Strangely it gives a mix of scripted and non-scripted in terms of its behaviour with regard to both ⎕ED and ⎕SRC.
      ↑⎕SRC sample
:Namespace sample
a←1
f←{this}
:Namespace sub
b←2
g←{that}
:EndNamespace
:EndNamespace
clone← {('n'⎕ns⍵)⊢n←⎕ns''} sample
↑⎕src clone
NONCE ERROR
↑⎕SRC clone

)ed clone
)ed clone.sub
both the above show a readonly namespace but
      ↑⎕SRC clone.sub
:Namespace sub
b←2
g←{that}
:EndNamespace
"How do they DO that?"
User avatar
Phil Last
 
Posts: 441
Joined: Thu Jun 18, 2009 6:29 pm

Re: How to undo a scripted namespace ?

Postby DanB|Dyalog on Thu Apr 23, 2015 12:46 pm

You can use SALT's Load program with -source=no to bring back a namespace without its source:
Code: Select all
      ↑⎕src ns
:Namespace ns
    a←⍳3     
    ∇ foo   
      a     
    ∇       
:EndNamespace
      ]save ns /tmp/
\tmp\ns.dyalog
      )erase ns
      ]load /tmp/ns -source=no
#.ns
DanB|Dyalog
 

Re: How to undo a scripted namespace ?

Postby ray on Tue May 12, 2015 3:26 pm

When I tried using the ]load user command to "unscript" a class, it fails with a domain error, because according to the STATUS message, the class script contains a base class (#.MiPage) and an :Include statement (:Include #HTMLInput).

Is there any way to get around this?
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 111
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

Re: How to undo a scripted namespace ?

Postby DanB|Dyalog on Tue May 12, 2015 8:06 pm

You cannot "unscript" a class. You can turn a scripted namespace into a non-scripted ns but not a class.
I believe the DOMAIN error you are seeing is unrelated to the "unscripting" but is simply due to the fact that the base class is not around.
Even if there was no base class or :included ns the resulting space would be useless because it could not reconstruct names in it (most would be private and the public ones are ⎕CR resistant).
DanB|Dyalog
 


Return to Source Code Management

Who is online

Users browsing this forum: No registered users and 1 guest