maxima - matchdeclare 不会接受第一个参数作为变量

maxima - matchdeclare won't accept first argument to be a variable

考虑以下陈述:

(%i1) matchdeclare([a,b], constantp);
(%o1)                                done
(%i2) defmatch(match, a*x+b);
(%o2)                                match
(%i3) match(2*x+3);
(%o3)                           [b = 3, a = 2]

我想在一个函数中概括这个模式。但后来它似乎不再起作用了:

(%i1) matchForm(test, form, constants) := block(
    matchdeclare(constants, constantp),
    defmatch(match, form),
    match(test)
);
(%o1) matchForm(test, form, constants) :=
  block(matchdeclare(constants, constantp), defmatch(match, form), match(test))
(%i2) test: 2*x+3;
(%o2)                               2 x + 3
(%i3) form: a*x+b;
(%o3)                               a x + b
(%i4) constants: [a,b];
(%o4)                               [a, b]
(%i5) matchForm(test, form, constants);
defmatch: evaluation of atomic pattern yields: a x + b
(%o5)                                false

稍微调试一下,问题似乎是 matchdeclare 不接受参数作为变量。有什么方法可以像我在 maxima 中尝试制作的那样制作功能吗?

我没试过,但是:也许你可以通过

得到你想要的效果
apply (matchdeclare, [constants, 'constantp]),

这将在调用 matchdeclare 之前计算 constants