Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / define.cpp
blob21e7c1eb5bbf5e230964b89781a3bd567df93544
1 // Store a function definition
2 //
3 // Example:
4 //
5 // f(x,y)=x^y
6 //
7 // For this definition, p1 points to the following structure.
8 //
9 // p1
10 // |
11 // ___v__ ______ ______
12 // |CONS |->|CONS |--------------------->|CONS |
13 // |______| |______| |______|
14 // | | |
15 // ___v__ ___v__ ______ ______ ___v__ ______ ______
16 // |SETQ | |CONS |->|CONS |->|CONS | |CONS |->|CONS |->|CONS |
17 // |______| |______| |______| |______| |______| |______| |______|
18 // | | | | | |
19 // ___v__ ___v__ ___v__ ___v__ ___v__ ___v__
20 // |SYM f | |SYM x | |SYM y | |POWER | |SYM x | |SYM y |
21 // |______| |______| |______| |______| |______| |______|
23 // We have
25 // caadr(p1) points to f
26 // cdadr(p1) points to the list (x y)
27 // caddr(p1) points to (power x y)
29 #include "stdafx.h"
30 #include "defs.h"
32 #define F p3 // F points to the function name
33 #define A p4 // A points to the argument list
34 #define B p5 // B points to the function body
36 void
37 define_user_function(void)
39 F = caadr(p1);
40 A = cdadr(p1);
41 B = caddr(p1);
43 if (!issymbol(F))
44 stop("function name?");
46 // evaluate function body (maybe)
48 if (car(B) == symbol(EVAL)) {
49 push(cadr(B));
50 eval();
51 B = pop();
54 set_binding_and_arglist(F, B, A);
56 // return value is nil
58 push_symbol(NIL);