=================================================================== RCS file: /home/cvs/OpenXM/src/asir-contrib/testing/tr.rr,v retrieving revision 1.2 retrieving revision 1.3 diff -u -p -r1.2 -r1.3 --- OpenXM/src/asir-contrib/testing/tr.rr 2005/04/02 05:56:57 1.2 +++ OpenXM/src/asir-contrib/testing/tr.rr 2005/04/03 11:05:21 1.3 @@ -1,10 +1,10 @@ -/* $OpenXM$ */ -/* $Id: tr.rr,v 1.2 2005/04/02 05:56:57 takayama Exp $ */ +/* $OpenXM: OpenXM/src/asir-contrib/testing/tr.rr,v 1.2 2005/04/02 05:56:57 takayama Exp $ */ +/* $Id: tr.rr,v 1.3 2005/04/03 11:05:21 takayama Exp $ */ /* OpenXM版の Risa/Asir で実行のこと. OpenXM 版の関数を用いるため. */ -/* $Id: tr.rr,v 1.2 2005/04/02 05:56:57 takayama Exp $ +/* $Id: tr.rr,v 1.3 2005/04/03 11:05:21 takayama Exp $ このファイルは quotetolist でリストに変換したデータに対して パターンマッチおよびそれを応用した変形を行う. tr.oxt の仕様とことなり quotetolist で変換したものを扱う. @@ -20,15 +20,22 @@ def dprint0(X) { if (Debug) print(X,0); } +/* quotetolist の逆関数. ただし文字列で */ +def listtoquote_str(L) { + return quote_input_form_quote_list(L); +} def qt_node(F) { - return [F[0],F[1]]; + if (type(F) == 17) F=quotetolist(F); + return [rtostr(F[0]),rtostr(F[1])]; } /* Number of child */ def qt_nchild(F) { + if (type(F) == 17) F=quotetolist(F); return length(F)-2; } def qt_child(F,K) { + if (type(F) == 17) F=quotetolist(F); return F[K+2]; } @@ -48,7 +55,8 @@ def tr_match0(F,P) { } Node = qt_node(F); Node2 = qt_node(P); - if (Node2 == ["function","pn"]) return 2; + /* pn に何の制約もなければ 2 を戻す. */ + if (Node2 == ["function","pn"]) return tr_check_pn(F,P); if (Node != Node2) return 0; N = qt_nchild(F); if (N != qt_nchild(P)) return 0; @@ -60,6 +68,25 @@ def tr_match0(F,P) { return 1; } +/* + P の例: P = pn("x"); P=pn("x",qt_is_integer(x)); + P は [function,pn,[internal,x],[function,is_int,[internal,x]]] + FF は ["is_int","x"] + テストデータ. + tr_check_pn(quote(1/2),quote(pn("x",qt_is_integer(x)))); +*/ +def tr_check_pn(F,P) { + if (type(F) ==17) F=quotetolist(F); + if (type(P) == 17) P=quotetolist(P); + N=qt_nchild(P); + if (N == 1) return 2; + X = rtostr(qt_child(P,0)[1]); + BindingTable = [[X,F]]; + FF = [rtostr(qt_child(P,1)[1]),rtostr(qt_child(P,1)[2][1])]; + R = tr_apply_function0(FF,BindingTable); + return R; +} + /* F と P が tr_match0 するとき bindingTable をもどす. [[変数の名前(文字列), 値(list)], ...] */ @@ -71,7 +98,7 @@ def tr_make_binding(F,P) { Node2 = qt_node(P); if (Node2 == ["function", "pn"]) { - Ans = append(Ans,[[P[2][1],F]]); + Ans = append(Ans,[[rtostr(P[2][1]),F]]); return Ans; } N = qt_nchild(F); @@ -118,12 +145,12 @@ def tr_apply_function0(Q,BindTable) { N = length(BindTable); /* BindTable の右辺値を quote(...) なる文字列に */ for (I=0; I nn(f(nn(x),nn(y))) + qt_map_arg(nn,quote(1/4+f(x))) --> + テストは test4(). +*/ +def qt_map_arg(F,Q) { + F = rtostr(F); + if (type(Q) == 17) Q=quotetolist(Q); + if (rtostr(Q[0]) == "internal") { + T = listtoquote_str(Q); + return eval_str( "quote("+F+"("+T+"))" ); + } + /* node の子供を F で評価する. */ + N = qt_nchild(Q); + L = []; + for (I=0; I