为上下文路径创建别名?
我希望能够通过 s'Graph
和 c'Graph
来引用 System'Graph
和 Combinatorica'Graph
(以及与 Combinatorica 冲突的其他函数)有办法做到这一点吗?
按照西蒙的想法,以下似乎可以工作
{Set @@ {ToExpression["c" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["Combinatorica`*"];
{Set @@ {ToExpression["s" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["System`*"];
现在cCompleteGraph[5]
和sCompleteGraph[5]
返回Combinatorica
和System
图表分别
1 月 8 日更新 为了供将来参考,这是我最终用来将 GraphUtilities、Combinatorica 和内置图形功能一起使用的方法。它通过将所有 Combinatorica 函数(例如 Graph
)重新映射到 cGraph
来解决冲突,并更改 $Post
以在每次评估时从 ContextPath 中删除 GraphUtilities 和 Combinatorica,这是必要的,因为GraphUtilities'ToCombinatoricaGraph
在每次调用时将 Combinatorica
添加到 $ContextPath
中。
总而言之,在每个会话开始时执行以下代码。 Combinatorica func 现在是 cfunc
,GraphUtilities func 是 GraphUtilities'func
,内置 func 只是 func
Needs["Combinatorica`"];
combNames = Names["Combinatorica`*"];
{Set @@ {ToExpression["c" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["Combinatorica`*"];
Needs["GraphUtilities`"];
$ContextPath = DeleteCases[$ContextPath, "Combinatorica`"];
$Post = ($ContextPath =
DeleteCases[$ContextPath,
"Combinatorica`" | "GraphUtilities`"]; #) &;
I'd like to be able to do s'Graph
and c'Graph
to refer to System'Graph
and Combinatorica'Graph
(and other functions conflicting with Combinatorica) is there a way to do this?
Following Simon's idea, the following seems to work
{Set @@ {ToExpression["c" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["Combinatorica`*"];
{Set @@ {ToExpression["s" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["System`*"];
Now cCompleteGraph[5]
and sCompleteGraph[5]
return Combinatorica
and System
graphs respectively
Update Jan 8th
For future reference, this is the method I ended up using to use GraphUtilities
, Combinatorica
and built-in graph functionality together. It resolves conflict by remapping all combinatorica functions like Graph
to cGraph
and changes $Post
to remove GraphUtilities and Combinatorica from ContextPath on each evaluation, necessary because GraphUtilities'ToCombinatoricaGraph
adds Combinatorica
to $ContextPath
at every call.
To summarize, execute the code below at start of each session. Combinatorica func is now cfunc
, GraphUtilities func is GraphUtilities'func
, and built-in func is just func
Needs["Combinatorica`"];
combNames = Names["Combinatorica`*"];
{Set @@ {ToExpression["c" <> Last[StringSplit[#, "`"]]],
ToExpression[#]}} & /@ Names["Combinatorica`*"];
Needs["GraphUtilities`"];
$ContextPath = DeleteCases[$ContextPath, "Combinatorica`"];
$Post = ($ContextPath =
DeleteCases[$ContextPath,
"Combinatorica`" | "GraphUtilities`"]; #) &;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
比如:
当然,这是在非常低的水平上工作的,所以要小心。
Something like:
Of course, this is working at a very low level, so take care.