检查符号是否已定义 [英] Checking if a symbol is defined
问题描述
有没有一种简单的方法来检查是否有 x 的定义?我需要一个函数形式为 f
,f[_]
或 f[_][_]
并返回 True
如果有它的定义
Is there an easy way to check if there's a definition for x? I need a function that takes
something of the form f
,f[_]
or f[_][_]
and returns True
if there's a definition for it
确切地说,我使用 f[x]=b 和 g[x][y]=z 之类的结构来存储东西,我需要检查 f[x] 是否对某些中的每个 x 都有定义列表,如果 g[x][y] 对某组值中的每个 x,y 都有定义
To be really concrete, I'm storing things using constructs like f[x]=b, and g[x][y]=z and I need to check if f[x] has definition for every x in some list and if g[x][y] has a definition for every x,y in some set of values
推荐答案
如果我理解正确的话,我认为 ValueQ
函数就是你要找的.如果变量或函数已定义,则返回 true,如果尚未定义,则返回 false.
If I understood correctly I think the function ValueQ
is what you are looking for. It will return true if a variable or a function has been defined and false if it has not been defined.
在 http://reference.wolfram.com/mathematica/ref/ValueQ 阅读更多.html
这篇关于检查符号是否已定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!