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.
How to undo a scripted namespace ?
Re: How to undo a scripted namespace ?
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.
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.
-
- Posts: 439
- Joined: Wed Oct 01, 2008 9:39 am
Re: How to undo a scripted namespace ?
Hi Pierre and Phil,
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
'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
Re: How to undo a scripted namespace ?
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!
Re: How to undo a scripted namespace ?
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
Re: How to undo a scripted namespace ?
I was writing "off the top of my head" and here's a clearer way to do exactly the same thing:
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.
{('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 sampleboth the above show a readonly namespace but
: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
↑⎕SRC clone.sub"How do they DO that?"
:Namespace sub
b←2
g←{that}
:EndNamespace
Re: How to undo a scripted namespace ?
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
Re: How to undo a scripted namespace ?
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?
Is there any way to get around this?
Ray Cannon
Please excuse any smelling pisstakes.
Please excuse any smelling pisstakes.
Re: How to undo a scripted namespace ?
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).
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).