AddFunction - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Printer

  

AddFunction

  

add function definition to Printer module

  

AddFunctions

  

add functions

  

GetFunction

  

get function definition from Printer module

 

Calling Sequence

Parameters

Description

Function Signatures

Using Multiple Function Signatures

Examples

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 [type1,...,typen]::type0, 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 [type1,...,typen]::type0 - This indicates that fname is a function accepting n 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 integer:: and numeric::numeric.  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.

withCodeGeneration:

PrinterLanguageDefinitionDefaultPrinter:

Printer:-AddFunctionsin,numeric::numeric,sin

sin,

(1)

Printer:-AddFunction("csc", [numeric]::numeric,
    proc(a) Printer:-Print("1.0/sin(",a,")") end proc, numeric='double');

procaPrinter:-Print1.0/sin(,a,)end proc,

(2)

See Also

AddLibrary

Printer