| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.2.1 A minimal example
Here is an example for the implementation of a function with two arguments that is not further evaluated:
DECLARE_FUNCTION_2P(myfcn) REGISTER_FUNCTION(myfcn, dummy()) |
Any code that has seen the DECLARE_FUNCTION line can use myfcn()
in algebraic expressions:
{
...
symbol x("x");
ex e = 2*myfcn(42, 1+3*x) - x;
cout << e << endl;
// prints '2*myfcn(42,1+3*x)-x'
...
}
|
The dummy() option in the REGISTER_FUNCTION line signifies
"no options". A function with no options specified merely acts as a kind of
container for its arguments. It is a pure "dummy" function with no associated
logic (which is, however, sometimes perfectly sufficient).
Let's now have a look at the implementation of GiNaC's cosine function for an example of how to make an "intelligent" function.
