1 // Evaluate a user defined function
6 #define F p3 // F is the function body
7 #define A p4 // A is the formal argument list
8 #define B p5 // B is the calling argument list
9 #define S p6 // S is the argument substitution list
12 eval_user_function(void)
16 // Use "derivative" instead of "d" if there is no user function "d"
18 if (car(p1
) == symbol(SYMBOL_D
) && get_arglist(symbol(SYMBOL_D
)) == symbol(NIL
)) {
23 F
= get_binding(car(p1
));
24 A
= get_arglist(car(p1
));
27 // Undefined function?
42 // Create the argument substitution list S
47 while (iscons(p1
) && iscons(p2
)) {
57 // Evaluate the function body
67 // Rewrite by expanding symbols that contain args
75 p2
= pop(); // subst. list
79 n
= rewrite_args_tensor();
86 push(car(p1
)); // Do not rewrite function name
99 // If not a symbol then done
107 // Try for an argument substitution first
119 // Get the symbol's binding, try again
121 p3
= get_binding(p1
);
124 push(p2
); // subst. list
128 push(p1
); // restore if not rewritten with arg
137 rewrite_args_tensor(void)
143 for (i
= 0; i
< p1
->u
.tensor
->nelem
; i
++) {
144 push(p1
->u
.tensor
->elem
[i
]);
147 p1
->u
.tensor
->elem
[i
] = pop();