DownValuesFunction
DownValuesFunction[sym]
represents a function that uses definitions attached to sym when compiling.
Details
- DownValuesFunction can be used directly in compiled code.
- DownValuesFunction can be used in compiled declarations specified by FunctionDeclaration.
- DownValuesFunction specifications typically use Typed to give type annotations.
- When DownValuesFunction is compiled, it creates a function from symbol declarations and compiles it.
- Declarations that use DownValuesFunction can use polymorphic types.
Examples
open allclose allBasic Examples (1)
Define a squaring function and use its definition to create a compiled function for the integer-typed case:
Use the compiled function with an integer argument:
Alternatively, use FunctionDeclaration to associate the definition of a function with a type specification:
Scope (5)
Multiple Definitions (5)
Several definitions attached to the same symbol can be used:
Make a declaration and compile a function that uses the definitions:
This calls the definition that uses a condition:
This calls the definition that uses a literal 2:
This calls the last catchall definition:
Definitions attached to a symbol can be used in more than one declaration with different types:
Make two declarations with different types and compile functions that use each:
Definitions attached to a symbol can be declared with a polymorphic type:
Make two declarations with different types and compile functions that use each:
Function declarations that use a symbol definition can call themselves:
Make a declaration and compile a function that uses it:
Function declarations that do not apply to all inputs can use a predicate to strip out:
Make a polymorphic declaration:
This compiles for a Boolean type, but the predicate for the Floor case is known to be False at compile time, so it is stripped out:
This compiles for a real type and uses the branch with the Floor:
Applications (1)
Symbol Definitions (1)
Declarations that use symbol definitions are useful if the declaration is used more than once:
A FunctionDeclaration that refers to the symbol:
A function that uses the symbol:
Compiled code for the function:
A vector plot based on the data that was created:
Possible Issues (3)
Updating (2)
DownValuesFunction uses the definitions used when the compilation is carried out:
The result uses the definitions in place when the compilation is done:
KernelFunction uses the definitions used when the computation is carried out:
The result uses the definitions in place when the computation is done:
Defintion Restrictions (1)
If there is no definition that applies to all cases, an error case will be added:
Patterns with a head specification are not supported:
Compound settings are not supported:
Sequence patterns are not supported:
Optional patterns are not supported:
Alternative patterns are not supported:
Alternative patterns are not supported:
Held patterns are not supported:
Verbatim patterns are not supported:
All the branches of pattern definitions must have a consistent type:
Text
Wolfram Research (2022), DownValuesFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/DownValuesFunction.html.
CMS
Wolfram Language. 2022. "DownValuesFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DownValuesFunction.html.
APA
Wolfram Language. (2022). DownValuesFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DownValuesFunction.html