Argument evaluation



Harald,

The observed results are consistent with the theory stated by
 the current version of the Maxima documentation,

  `::=' defines a function (called a "macro" for historical reasons)
  which quotes its arguments, and the expression which it returns
  (called the "macro expansion") is evaluated in the context from
  which the macro was called.  A macro function is otherwise
  the same as an ordinary function.

(The text shown at http://maxima.sourceforge.net/docs/manual/en/maxima_5.html
is up to date, or close to it.)

> (%i4) mytest1(foo);
> (%o4)                        [[1, 2, 3], a, b, c]

Within mytest1, x is bound to 'foo.
When mytest1 (foo) is evaluated, cons (foo, [a, b, c]) is
evaluated, yielding [foo, a, b, c].
That is then evaluated in the context from which mytest1
was called, yielding [[1, 2, 3], a, b, c].

I'll omit discussion of mytest2 and mytest3 since the
reasoning is pretty much the same.

macroexpand can shed some light on questions of this kind,

  macroexpand (mytest1 (foo)); => [foo, a, b, c]

  macroexapnd (mytest2 (foo));
    => 2ND argument value `foo' to cons was not a list

If the goal is evaluate cons (or whatever) in the calling context
(instead of within the macro), it is customary to use buildq, e.g.,

  mytest2b (x) ::= buildq ([x], cons ([a, b, c], x));

  macroexpand (mytest2b (foo)); => cons([a, b, c], foo)

  mytest2b (foo); => [[a, b, c], 1, 2, 3]


HTH
Robert Dodier