|
Calling Sequence
|
|
Printer:-AddFunction(fname, signature, translation, libs, opts)
Printer:-AddFunctions(list1, list2, ...)
Printer:-GetFunction(fname, signature)
|
|
Parameters
|
|
Printer
|
-
|
Printer module
|
fname
|
-
|
string; name of function
|
signature
|
-
|
type signature for function fname
|
translation
|
-
|
string or procedure; translation for function fname
|
libs
|
-
|
(optional) equation of the form library=l
|
opts
|
-
|
(optional) equations of the form integer=iprec, numeric=nprec
|
list1, list2, ...
|
-
|
lists of the form [fname, signature, translation, libs, opts], with fname, signature, translation, libs, opts as defined above
|
|
|
|
|
Description
|
|
•
|
The AddFunction command defines an equivalent in a target language for a Maple function with name fname and function signature signature. The AddFunctions command defines multiple targets in a single calling sequence.
|
•
|
The GetFunction command returns a previously defined target language equivalent for fname.
|
•
|
The optional parameter libs is an equation of the form library=l, where l is a string or list of strings corresponding to libraries needed for translation to function properly in the target language. This is identical in effect to writing translation as a procedure, and including AddLibrary commands for each of the libraries in l in the body of translation.
|
|
|
Function Signatures
|
|
|
A function signature is an expression which is either a type, a expression of the form , or an expression of the form anything::type0. The meaning associated with each of these is as follows.
|
•
|
A type - This indicates that fname is a special constant (for example, Pi) with type signature.
|
•
|
An expression of the form - This indicates that fname is a function accepting arguments, with types given by type1 to typen respectively, with return type type0.
|
•
|
An expression of the form anything::type0 - This indicates that fname is a function accepting an arbitrary number of arguments of any type, with return type type0.
|
|
|
Using Multiple Function Signatures
|
|
•
|
There can be multiple function signatures for a function name fname. If so, CodeGeneration attempts to match a given function call with the most appropriate signature, based on context.
|
|
Note: Maple uses the set of recognized type signatures in its type deductions, so it is useful to include as many type signatures as possible, even when one type signature is a special case of another. For example, suppose an implementation of abs function can accept both integer and float input (returning integer or float output respectively). This is equivalent to the function signatures and . To avoid needless type coercions, both of these type signatures should be explicitly specified in the language definition.
|
|
|
Examples
|
|
Define target-language equivalents for the sin and csc functions.
>
|
|
>
|
|
>
|
|
>
|
Printer:-AddFunction("csc", [numeric]::numeric,
proc(a) Printer:-Print("1.0/sin(",a,")") end proc, numeric='double');
|
| (2) |
|
|
|