1 /* ==================================================================== */
4 /* First, we'll play with some macros that do stack manipulation.
5 A stack behaves like a pile of physical objects. You can pile
6 more things on top of it or you can examine/remove the top object.
7 Classically, the operators PUSH and POP apply to stacks. Let's
8 try some examples... */
10 /* push -- adds a value to top of a stack */
12 push(value,stackname)::=buildq([value,stackname],
13 stackname:cons(value,stackname))$
15 /* pop -- removes a value from top of a stack */
17 pop(stackname)::=buildq([stackname],
18 block([temp:first(stackname)],
19 stackname:rest(stackname),temp))$
30 /* Now let's write a function-defining function. Suppose we have some
31 function that we feel like we are always recycling by making just a few
32 minor changes and leaving most of it intact ... eg,
34 poly1(x):=x^3+45*x^2+432*x+1
35 poly2(x):=x^3+45*x^2+432*x+2
38 We might consider writing a macro for ourselves to save us the typing
39 done by defining this new each time. eg, ... */
41 polydef(n)::=buildq([name:concat('poly,n),n],
42 name(x):=x^3+45*x^2+432*x+n);
43 member('poly83,functions);