home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / demo / macro.dem < prev    next >
Encoding:
Text File  |  2003-02-09  |  1.3 KB  |  47 lines

  1. /* ==================================================================== */
  2. /* file: macro.dem     */
  3. /* At some point, we get the message: DISPLACE undefined */
  4.  
  5. /* First, we'll play with some macros that do stack manipulation.
  6.    A stack behaves like a pile of physical objects. You can pile
  7.    more things on top of it or you can examine/remove the top object.
  8.    Classically, the operators PUSH and POP apply to stacks. Let's
  9.    try some examples... */
  10.  
  11. /* PUSH -- Adds a value to top of a stack */
  12.  
  13. PUSH(VALUE,STACKNAME)::=BUILDQ([VALUE,STACKNAME],
  14.         STACKNAME:CONS(VALUE,STACKNAME))$
  15.  
  16. /* POP -- Removes a value from top of a stack */
  17.  
  18. POP(STACKNAME)::=BUILDQ([STACKNAME],
  19.             BLOCK([TEMP:FIRST(STACKNAME)],
  20.                   STACKNAME:REST(STACKNAME),TEMP))$
  21.  
  22. A:[];
  23. PUSH('FOO,A);
  24. PUSH('BAR,A);
  25. A;
  26. POP(A);
  27. A;
  28. POP(A);
  29. A;
  30.  
  31. /* Now let's write a function-defining function. Suppose we have some
  32.    function that we feel like we are always recycling by making just a few
  33.    minor changes and leaving most of it intact ... eg, 
  34.  
  35.     POLY1(X):=X^3+45*X^2+432*X+1
  36.     POLY2(X):=X^3+45*X^2+432*X+2
  37.     ... etc.
  38.  
  39.    We might consider writing a macro for ourselves to save us the typing
  40.    done by defining this new each time. eg, ...  */
  41.  
  42. POLYDEF(N)::=BUILDQ([NAME:CONCAT('POLY,N),N],
  43.             NAME(X):=X^3+45*X^2+432*X+N);
  44. MEMBER('POLY83,FUNCTIONS);
  45. POLYDEF(83);
  46. DISPFUN(POLY83);
  47.