How to eval a "quoted" expression?



> I'm trying to conpare MAXIMA with LISP.

Though there are some similarities, there are also some big differences.

> It seems a single quote stands for QUOTE and double single 
> quote stands for EVAL.

The semantics of Maxima single-quote are more complicated than Lisp
quote.  Single-quote of an expression does correspond to Lisp quote:

     '(print(3)) => print(3)

but keep in mind that *simplification* is orthogonal to evaluation:

     '(print(3+4)) => print(7)

Single-quote of a function in function-application context applies the
*noun form* of the function to the (evaluated) arguments:

     'print(print(3)) prints 3 and returns print(3)
     print('print(3)) prints print(3) and returns print(3)

A noun form function stays unevaluated:

     ev('print(3)) => print(3)

By default, noun form functions display the same as verb form functions.
This can be confusing, so I'd recommend turning on the noundisp flag so
the difference will be visible:

(C1) print(3);
3 
(D1)                            3
(C2) '(print(3));
(D2)                         PRINT(3)
(C3) ev(d2);
3 
(D3)                            3
(C4) 'print(3);
(D4)                         PRINT(3)
(C5) ev(d4);
(D5)                         PRINT(3)
(C6) noundisp:true;
(D6)                           TRUE
(C7) c1;
(D7)                         PRINT(3)
(C8) c2;
(D8)                       '(PRINT(3))
(C9) c3;
(D9)                          EV(D2)
(C10) c4;
(D10)                       'PRINT(3)
(C11) c5;
(D11)                         EV(D4)
(C12) d1;
(D12)                           3
(C13) d2;
(D13)                        PRINT(3)
(C14) d3;
(D14)                           3
(C15) d4;
(D15)                       'PRINT(3)
(C16) d5;
(D16)                       'PRINT(3)


Compare with quoting the whole expression:

     '( print(print(3)) ) returns print(print(3))
     print( '(print(3)) ) prints print(3) and returns print(3)

----------------------------

Double-quote in Maxima doesn't correspond directly to anything in Lisp.
It is a *read-time* substitution of a value.  So for example:

   v: 'vv1;
   vv1: 'vvv1;
   vv2: 'vvv2;

   [v, ''v, v: 'vv2, v, ''v] => [vv1, vvv1, vv2, vv2, vvv1]

Note that the fifth result is NOT affected by setting v to 'vv2.

Compare

   [v, ev(v), v: 'vv2, v, ev(v)] =>  [vv2, vvv2, vv2, vv2, vvv2]

  

> How can I make eq2 be evaluated to 101?

Nouns can be evaluated by verbs either by using the "nouns" flag to
"ev", or by naming the specific noun in the arguments to ev:

   p1(x):=print(['p1,x]);
   p2(x):=print(['p2,x]);

   qq: ['p1(4),'p2(5)] => ['p1(4), 'p2(5)]

   ev(qq) => ['p1(4), 'p2(5)] ------same thing
   ev(qq,nouns) prints [p1, 4] and [p2, 5] and returns [[p1, 4], [p2,
5]]
   ev(qq,p1) prints [p1, 4] and returns [[p1, 4], 'p2(5)].

The noun form is actually kept as the operator of the expression (not as
some sort of quoting operator surrounding the expression):

   apply( op('p1(3)), [9] ) => 'p1(9)
   apply(op('(p1(3))),[9]) prints [p1, 9] and returns [p1, 9]

   ?print(op('p1(3))) -> %p1      -- print internal form
   ?print(op('(p1(3)))) -> $p1 

   op('p1(3)) - op('(p1(3))) => p1 - p1  -- these are two different
things

      (note that noundisp only affects the display of nouns when
       they are applied to arguments)

I don't like all this complexity, but that is the way Maxima currently
works.

     -s