registerFunction

Registers a function with the given name and function body. A function cannot register if its body has invalid syntax or if its definition has already been used.

@safe nothrow
bool
registerFunction
(
dstring funcdef
,
dstring funcbody
)

Parameters

funcdef dstring

The definition of the function to register.

funcbody dstring

The body of the function to register.

Return Value

Type: bool

True if the function successfuly registers, false otherwise.

Examples

dstring func = "x + 1"d;
assert(registerFunction("a(x) = num(num)"d,func));
func = "x^^2 + 2^^2 j- 3"d;
assert(!registerFunction("a(x) = num(num)"d,func));
func = "x.3";
assert(!registerFunction("a(x) = num(num)"d,func));
func = "()";
assert(!registerFunction("a(x) = num(num)"d,func));
func = "x ^ 3";
assert(!registerFunction("a(x) = num(num)"d,func));
func = "x +";
assert(!registerFunction("a(x) = num(num)"d,func));
assert(!registerFunction("a(x) = num(num)"d,"x ++ 1"d));
assert(registerFunction("b(x) = num(num)"d, "x"d));
registerFunction("a(x) = num(num)"d,func); //Fails on MacOS without this.
assert(!registerFunction("a(x) = num(num)"d, "x"d));

Meta