2017-09-14 2 views
1

다음과 같은 문장을 고려 할 첫 번째 인수를 허용하지 않습니다 :최대 - matchdeclare 변수

(%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 동의하지 않습니다. 맥시마에서 만들려고하는 것처럼 기능을 만드는 방법이 있습니까?

답변

1

나는,하지만이 시도하지 않은 : 아마도 당신이 matchdeclare를 호출하기 전에 constants을 평가합니다

apply (matchdeclare, [constants, 'constantp]), 

를 통해 원하는 효과를 얻을 수 있습니다.

+0

나는 이것을 시도했지만 작동하지 않는 것 같습니다. – Kasper

+0

적용 적용 (defmatch, [일치, 형식] )' – Kasper

+0

나는 그것이 작동하게되어서 기쁩니다. –