[Albert Reiner <areiner@tph.tuwien.ac.at>] Re: [Maxima] splicing list of optional arguments in function call
Subject: [Albert Reiner <areiner@tph.tuwien.ac.at>] Re: [Maxima] splicing list of optional arguments in function call
From: Stavros Macrakis
Date: Wed, 15 Sep 2004 15:47:06 -0400
The [x] form of argument (like &rest in Lisp) is a convenience feature
which makes recursive use problematic. Same thing for quoted-argument
functions in old Lisps (fexpr, flambda, etc.). If I'm going to use
[x] at all (and I hesitate to), I *always* have a fixed-argument form
of the function, e.g.
foo(a,[b]) := foo_list(a,b)$
foo_list(a,b) :=
if inpart(a,0)="="
then foo_list(inpart(a,1)-inpart(a,2),b)
else ....
Compared to a solution using buildq/splice, this is simpler, clearer,
and more efficient.
buildq is a very special-purpose function used for constructing code,
typically in macro definitions. There, the behavior that you find
surprising is precisely the desired behavior (not an "issue"). The
problem is that in your case, you are using the same variable
environment both to construct the code and to execute it, which pretty
much guarantees problems.
The way to avoid the problems you're having is not to try to twist
buildq into solving a problem it was not designed for, but to keep
things clean and simple.
-s