how to parameterise local variables?



On Fri, Jul 25, 2008 at 6:45 AM, Oliver Kullmann
<O.Kullmann at swansea.ac.uk> wrote:

>> If the answer is eval_string, almost certainly you probably meant
>> to ask a different question.

> Aha, so "parse_string" is the right function to use!

Erm, actually what I'm getting at is that it's probably more effective
to work with Maxima expressions directly (constructing expressions
via apply, funmake, subst, buildq, macros, or whatever).

> Just to make an example, if I want to create a function which
> just takes its argument and uses it for the definition of local
> variables, returning a, I would use
>
> f(L) := ev(buildq([L],block(L,a)),eval)$

I didn't try it, but I think this could be a macro, which is just
a function which quotes its arguments, and evaluates its return
value. E.g. f (L) ::= buildq ([L], block (L, a));
See also macroexpand.

> Isn't it just the opposite, *only* by dynamic scoping can we prevent
> the trouble?

Well, I guess it would be OK to allow both lexical and dynamic scope.

> There is only one thing, perhaps I could use it here:
> In my "unit test" test system I write "higher order test functions",
> e.g.,
>
> /* Concept: f(x) is defined for x=1, returns 77. */
> okltest_concepttobetested(f) := (
>  assert(f(1) = 77),
>  true)$

Maxima has a built-in test system, invoked by run_testsuite and
also batch("foo.mac", test) . Test scripts are pairs of expressions,
the first is an input and the second is the expected output.
Maybe you could use that instead of inventing a test system.

> The little problem here is that if "f" is a globally defined function,
> then this overwrites the parameter.
> Thus my test files all contain a "kill(f);".
> But one could use "sanitize" instead.

Also you could write block(local(f), f(x) := ..., ...) .

best

Robert Dodier