File: macro.dem

package info (click to toggle)
maxima-sage 5.42.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 147,292 kB
  • sloc: lisp: 382,572; fortran: 14,666; perl: 14,365; tcl: 11,123; sh: 4,487; makefile: 2,517; ansic: 444; xml: 23; awk: 17; sed: 17
file content (45 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* ==================================================================== */
/* file: macro.dem     */

/* First, we'll play with some macros that do stack manipulation.
   A stack behaves like a pile of physical objects. You can pile
   more things on top of it or you can examine/remove the top object.
   Classically, the operators PUSH and POP apply to stacks. Let's
   try some examples... */

/* push -- adds a value to top of a stack */

push(value,stackname)::=buildq([value,stackname],
		stackname:cons(value,stackname))$

/* pop -- removes a value from top of a stack */

pop(stackname)::=buildq([stackname],
			block([temp:first(stackname)],
			      stackname:rest(stackname),temp))$

a:[];
push('foo,a);
push('bar,a);
a;
pop(a);
a;
pop(a);
a;

/* Now let's write a function-defining function. Suppose we have some
   function that we feel like we are always recycling by making just a few
   minor changes and leaving most of it intact ... eg, 

	poly1(x):=x^3+45*x^2+432*x+1
	poly2(x):=x^3+45*x^2+432*x+2
	... etc.

   We might consider writing a macro for ourselves to save us the typing
   done by defining this new each time. eg, ...  */

polydef(n)::=buildq([name:concat('poly,n),n],
		    name(x):=x^3+45*x^2+432*x+n);
member('poly83,functions);
polydef(83);
dispfun(poly83);