DownValuesFunction[sym]
表示一个函数,在编译时使用附加于 sym 的定义.


DownValuesFunction
DownValuesFunction[sym]
表示一个函数,在编译时使用附加于 sym 的定义.
更多信息

- DownValuesFunction 可被直接用在已编译代码中.
- DownValuesFunction 可被用在 FunctionDeclaration 指定的已编译声明中.
- DownValuesFunction 规范通常使用 Typed 给出类型注释.
- DownValuesFunction 被编译时,它会根据符号声明创建一个函数并对其进行编译.
- 使用 DownValuesFunction 的声明可使用多态类型.
- 支持以下模式构造:
-
_ 匹配一个参数 x_ 匹配名称被设为 x 的参数 _h 若标头为 h 则匹配 x_?test 若 test[x] 的结果为 True 则匹配 p/;cond 若 cond 的结果为 True 则匹配 Except[p] 若 p 不匹配则匹配 p1|p2 若 pi 之一匹配则匹配 f[g[p]] 匹配复合表达式(用于惰性表达式和压缩数组) __,___ 匹配一个序列(用于惰性表达式)
范例
打开所有单元 关闭所有单元基本范例 (1)
定义一个求平方函数,并使用它的定义为整数类型的参数创建一个编译函数:
或者,使用 FunctionDeclaration 将函数的定义与类型规范关联在一起:
范围 (13)
多个声明 (1)
匹配标头 (1)
Make a polymorphic declaration that uses the definition:
Compile a function that uses the declaration with an argument that does not match the head:
Call the function with an integer and that uses the definition that does not match the head:
Compile a function that uses the declaration with an argument that does match the head:
Call the function with a real and that uses the definition that matches the head:
模式测试 (1)
条件 (1)
Except (1)
编译使用 Except 的模式:
Alternatives (1)
复合模式 (1)
应用 (1)
Symbol Definitions (1)
引用符号的 FunctionDeclaration:
可能存在的问题 (5)
更新 (1)
DownValuesFunction 使用的是进行编译时使用的定义:
技术笔记
相关指南
-
▪
- 代码编译
文本
Wolfram Research (2022),DownValuesFunction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/DownValuesFunction.html (更新于 2025 年).
CMS
Wolfram 语言. 2022. "DownValuesFunction." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/DownValuesFunction.html.
APA
Wolfram 语言. (2022). DownValuesFunction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/DownValuesFunction.html 年
BibTeX
@misc{reference.wolfram_2025_downvaluesfunction, author="Wolfram Research", title="{DownValuesFunction}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/DownValuesFunction.html}", note=[Accessed: 16-September-2025]}
BibLaTeX
@online{reference.wolfram_2025_downvaluesfunction, organization={Wolfram Research}, title={DownValuesFunction}, year={2025}, url={https://reference.wolfram.com/language/ref/DownValuesFunction.html}, note=[Accessed: 16-September-2025]}