【发布时间】:2014-10-05 08:26:49
【问题描述】:
我正在通过阅读 Maxima 手册来学习。
Maxima 有许多内置函数和全局变量。 我担心会覆盖已经存在的同名函数或变量。
有没有一种方便的方法可以避免 Maxima 中的名称冲突?
【问题讨论】:
标签: maxima
我正在通过阅读 Maxima 手册来学习。
Maxima 有许多内置函数和全局变量。 我担心会覆盖已经存在的同名函数或变量。
有没有一种方便的方法可以避免 Maxima 中的名称冲突?
【问题讨论】:
标签: maxima
如果您在谈论命名空间,- 不,我从未听说过 Maxima 中的命名空间。
解决问题的最简单方法是为用户定义的变量和函数编写前缀
另一个选项是通过describe(FUNCTIONNAME) 检查函数\变量是否已经存在。如果它打印文本,则函数是预定义的 =)
代码示例:
a:1;
b:2;
map:3;
map(describe, values);
(%o25) 1
(%o26) 2
(%o27) 3
No exact match found for topic a.
Try ?? a (inexact match) instead.
No exact match found for topic b.
Try ?? b (inexact match) instead.
Function: map (<f>, <expr_1>, ..., <expr_n>)
Returns an expression whose leading operator is the same as that
....
....
There are also some inexact matches for map.
Try ?? map to see them.
(%o28) [false,false,true]
【讨论】:
Robert Dodier有一个实验包
http://sourceforge.net/p/maxima/code/ci/master/tree/share/contrib/namespaces
(%i1) load("namespaces")$
(%i2) in_namespace(foo);
(%o2) #<PACKAGE "$FOO">
(%i3) z: 42;
(%o3) 42
(%i4) in_namespace(maxima)$
(%i5) z;
(%o5) z
(%i6) foo|z;
(%o6) 42
【讨论】: