=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/asir.texi,v retrieving revision 1.13 retrieving revision 1.19 diff -u -p -r1.13 -r1.19 --- OpenXM/src/asir-doc/parts/asir.texi 2003/12/20 13:38:44 1.13 +++ OpenXM/src/asir-doc/parts/asir.texi 2014/03/11 01:46:19 1.19 @@ -1,4 +1,4 @@ -@comment $OpenXM: OpenXM/src/asir-doc/parts/asir.texi,v 1.12 2003/12/18 10:26:20 ohara Exp $ +@comment $OpenXM: OpenXM/src/asir-doc/parts/asir.texi,v 1.18 2005/07/25 12:23:05 takayama Exp $ \BJP @node ユーザ言語 Asir,,, Top @chapter ユーザ言語 Asir @@ -227,7 +227,13 @@ Use of lists enables to write programs more easily, sh comprehensible than use of structure like C programs. \E +\BJP @item +ユーザ定義函数における一行ヘルプ. Emacs-Lisp に類似した機能である. +詳しくは, @xref{ユーザ定義函数} を見よ. +\E + +@item \JP ユーザ定義函数におけるオプション指定. \EG Options can be specified in calling user defined functions. @@ -236,6 +242,26 @@ comprehensible than use of structure like C programs. @end itemize \BJP +@noindent +Asir では次の語句がキーワードとして定められている. +@itemize +@item C 言語に由来: + +@code{break}, @code{continue}, @code{do}, @code{else}, @code{extern}, +@code{for}, @code{if}, @code{return}, @code{static}, @code{struct}, +@code{while} +@item C 言語からの拡張: + +@code{def}, @code{endmodule}, @code{function}, @code{global}, +@code{local}, @code{localf}, @code{module} +@item 函数: + +@code{car}, @code{cdr}, @code{getopt}, @code{newstruct}, @code{map}, +@code{pari}, @code{quote}, @code{recmap}, @code{timer} +@end itemize +\E + +\BJP @node ユーザ定義函数の書き方,,, ユーザ言語 Asir @section ユーザ定義函数の書き方 \E @@ -461,9 +487,8 @@ All the program variables are initialized to the value \BJP @item 不定元 小文字で始まり, アルファベット, 数字, @samp{_} からなる文字列, -またはシングルクオートで囲まれた文字列. - -不定元とは, 多項式環を構成する際に添加される変数をいう. @b{Asir} に +またはシングルクオートで囲まれた文字列, もしくは函数形式. +不定元とは, 多項式環を構成する際に添加される変数をいう. @b{Asir} に おいては, 不定元は値をもたない超越的な元であり, 不定元への値の代入は 許されない. \E @@ -484,6 +509,9 @@ x x^2+x+1 [5] A='Dx'*(x-1)+x*y-y; (y+Dx)*x-y-Dx +[6] function foo(x,y); +[7] B=foo(x,y)*x^2-1; +foo(x,y)*x^2-1 @end example @end table @@ -1423,8 +1451,53 @@ After @samp{|} one can append any number of options se [100] xxx(1,2,x^2-1,[1,2,3]|proc=1,index=5); @end example +\BJP +さらに, オプションを @code{key1=value1,key2=value2,...} のように +@samp{,} で区切って渡す代わりに, 特別なキーワード @code{option_list} +とオプションリスト @code{[["key1",value1],["key2",value2],...]} +を用いて渡すことも可能である. +\E +\BEG +Optinal arguments may be given as a list +with the key word @code{option_list} +as +@code{option_list=[["key1",value1],["key2",value2],...]}. +It is equivalent to pass the optional arguments as +@code{key1=value1,key2=value2,...}. +\E +@example +[101] dp_gr_main([x^2+y^2-1,x*y-1]|option_list=[["v",[x,y]],["order",[[x,5,y,1]]]]); +@end example + \BJP +特に, 引数なしの @code{getopt()} はオプションリストを返すので, +オプションをとる関数から, オプションをとる関数を呼び出すときには有用である. +\E +\BEG +Since @code{getopt()} returns an option list, +the optional argument @code{option_list=...} is useful when +we call functions with optional arguments from +a function with optional arguments to pass +the all optional parameters. +\E + +@example +% cat foo.rr +def foo(F) +@{ + OPTS=getopt(); + return factor(F|option_list=OPTS); +@} +@end example + +@example +[3] load("foo.rr")$ +[4] foo(x^5-1|mod=11); +[[1,1],[x+6,1],[x+2,1],[x+10,1],[x+7,1],[x+8,1]] +@end example + +\BJP @node モジュール,,, ユーザ定義函数の書き方 @subsection モジュール \E @@ -1483,6 +1556,8 @@ def demo() @{ モジュールは入れ子にはできない. モジュールの中だけで使う大域変数は @code{static} で宣言する. この変数はモジュールの外からは参照もできないし変更もできない. +@code{static} 変数はすべての関数定義の前に宣言しないといけない. +パーサーがワンパスのため, 宣言のない変数は自動的に局所変数とみなされるからである. モジュールの外の大域変数は @code{extern} で宣言する. \E \BEG @@ -1493,7 +1568,10 @@ and A variable of a module is declared with the key word @code{static}. The static variables cannot be refered nor changed out of the module, but it can be refered and changed in any functions in the module. -A global variable which can be refered and changed at any place +The @code{static} variables must be declared before the definitions of functions, +because the one-path parser of asir automatically assume variables as local variables +if there is no declaration for them. +A global variable which can be refered and changed in or out of the module is declared with the key word @code{extern}. \E @@ -1559,7 +1637,7 @@ The below is an example of demand loading. \E @example -if (!module_definep("stack")) load("stack.rr") $ +if (!module_definedp("stack")) load("stack.rr") $ @end example \BJP @@ -1609,6 +1687,38 @@ def demo() @{ module stack; /* The body of the module stack */ endmodule; +@end example + +\BJP +モジュールの中からトップレベルで定義されている関数を呼ぶには, +下の例のように @code{::} を用いる. +\E +\BEG +In order to call functions defined in the top level from the inside +of a module, we use @code{::} as in the example below. +\E +@example +def afo() @{ + S = "afo, afo"; + return S; +@} +module abc; +localf foo,afo $ + +def foo() @{ + G = ::afo(); + return G; +@} +def afo() @{ + return "afo, afo in abc"; +@} +endmodule; +end$ + +[1200] abc.foo(); +afo, afo +[1201] abc.afo(); +afo, afo in abc @end example @table @t