Move definition from one context to Global`
If you really want this, you can do e.g. the following:
Block[{$ContextPath = {"System`", "DEF`"}},
Scan[
(Context[#] = "Global`") &,
Names["DEF`*"]
]
]
Here, Block
was used just to make sure that Names
will return short symbol string names, rather than fully-qualified ones.
This will move all symbols from DEF`
to Global`
, which automatically make DEF`
context empty, and it will be then automatically removed from a list of available contexts, as per Contexts[]
.
On my system, Mathematica 10.1 under Windows, I got an error using Leonid's code:
Context::cxdup: Cannot set Context[DEF`x] to Global`, since a symbol already exists with name x and context Global`. >>
I seem to need something like this to avoid it:
Block[{$ContextPath = {"System`", "DEF`"}},
Scan[(Quiet[Remove @@ {"Global`" <> StringTrim[#, __ ~~ "`"]}];
Context[#] = "Global`") &, Names["DEF`*"]]]