=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/asir.texi,v retrieving revision 1.9 retrieving revision 1.16 diff -u -p -r1.9 -r1.16 --- OpenXM/src/asir-doc/parts/asir.texi 2003/11/27 12:08:58 1.9 +++ OpenXM/src/asir-doc/parts/asir.texi 2004/07/04 00:16:43 1.16 @@ -1,4 +1,4 @@ -@comment $OpenXM: OpenXM/src/asir-doc/parts/asir.texi,v 1.8 2003/10/21 09:17:57 takayama Exp $ +@comment $OpenXM: OpenXM/src/asir-doc/parts/asir.texi,v 1.15 2004/07/03 15:50:34 ohara 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 @@ -371,6 +397,16 @@ In the second example, @code{c(N)} returns a vector, s @code{N+1}. @code{A[I]} is a vector of length @code{I+1}, and each element is again a vector which contains \E +@iftex +@tex +${_I}C_J$ +@end tex +@end iftex +@ifinfo +ICJ +@end ifinfo +\JP を要素とする配列である. +\EG as its elements. @noindent \BJP @@ -378,24 +414,12 @@ each element is again a vector which contains Emacs-Lisp の関数定義に類似の機能で、ヘルプ用の文字列である。 この例の場合、@code{help(add)} によってこの文字列が出力される。 \E - @table @t \JP @item 参照 \EG @item References @fref{help}. @end table -@iftex -@tex -${_I}C_J$ -@end tex -@end iftex -@ifinfo -ICJ -@end ifinfo -\JP を要素とする配列である. -\EG as its elements. - @noindent \BJP 以下では, C によるプログラミングの経験がない人のために, @b{Asir} 言語 @@ -462,9 +486,9 @@ All the program variables are initialized to the value \BJP @item 不定元 -小文字で始まり, アルファベット, 数字, @samp{_} からなる文字列 - -不定元とは, 多項式環を構成する際に添加される変数をいう. @b{Asir} に +小文字で始まり, アルファベット, 数字, @samp{_} からなる文字列, +またはシングルクオートで囲まれた文字列, もしくは函数形式. +不定元とは, 多項式環を構成する際に添加される変数をいう. @b{Asir} に おいては, 不定元は値をもたない超越的な元であり, 不定元への値の代入は 許されない. \E @@ -483,6 +507,11 @@ An indeterminate cannot have any value. No assignment x [4] X^2+X+1; 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 @@ -862,6 +891,19 @@ if ( expression1 ) @{ @noindent \JP としなければならない. +\BJP +@noindent +関数の中でなく, top level で @code{if} 文を用いるときは @code{$} または @code{;} +で終了する必要がある. +これらがないと次の文がよみとばされる. +\E +\BEG +@noindent +When @code{if} is used in the top level, the @code{if} expression should be +terminated with @code{$} or @code{;}. +If there is no terminator, the next expression will be skipped to be evaluated. +\E + \BJP @node ループ break return continue,,, ユーザ定義函数の書き方 @subsection ループ, @code{break}, @code{return}, @code{continue} @@ -1029,6 +1071,9 @@ statement, and the termination condition will be evalu \BJP 構造体とは, 各成分の要素が名前でアクセスできる固定長配列と思ってよい. 各構造体は名前で区別される. 構造体は, @code{struct} 文により宣言される. +構造体が宣言されるとき, asir は内部で構造体のそれぞれの型に固有の識別 +番号をつける. この番号は, 組み込み関数 @code{struct_type} により取得 +できる. ある型の構造体は, 組み込み関数 @code{newstruct} により生成される. 構造体の各メンバは, 演算子 @code{->} によりアクセスする. メンバが構造体の場合, @code{->} による指定は入れ子にできる. @@ -1055,8 +1100,16 @@ by @code{->} can be nested. 2 [5] A; @{1,2@} +[6] struct_type(A); +1 @end example +@table @t +\JP @item 参照 +\EG @item References +@fref{newstruct}, @fref{struct_type} +@end table + \BJP @node さまざまな式,,, ユーザ定義函数の書き方 @subsection さまざまな式 @@ -1226,8 +1279,11 @@ through @code{cpp}. This enables @b{Asir} user to use @code{#include} @* \BJP -@code{cpp} に特に引数を渡さないため, インクルードファイルは, -@code{#include} が書かれているファイルと同じディレクトリでサーチされる. +UNIX では インクルードファイルは, Asir のライブラリディレクトリ +(環境変数 @b{ASIR_LIBDIR} で指定されたディレクトリ) +と @code{#include} が書かれているファイルと同じディレクトリをサーチする. +UNIX 以外では @code{cpp} に特に引数を渡さないため, +@code{#include} が書かれているファイルと同じディレクトリのみをサーチする. \E \BEG Include files are searched within the same directory as the file @@ -1296,6 +1352,21 @@ because such comments cannot be nested. #define MAX(a,b) ((a)>(b)?(a):(b)) @end example +\BJP +@noindent +C のプリプロセッサを流用しているため, プリプロセッサは @code{$} を正しく処理できない. +たとえば @code{LIST} が定義されていても +@code{LIST$}は置換されない. @code{$} の前に空白をおいて +@code{LIST $} と書かないといけない. +\E +\BEG +@noindent +Since we are utilizing the C preprocessor, it cannot properly preprocess expressions +with @code{$}. +For example, even if @code{LIST} is defined, @code{LIST} in the expression +@code{LIST$} is not replaced. Add a blank before @code{$}, i.e., +write as @code{LIST $} to make the proprocessor replace it properly. +\E \BJP @node オプション指定,,, ユーザ定義函数の書き方 @@ -1380,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 @@ -1437,6 +1553,7 @@ def demo() @{ \BJP モジュールは @code{module} モジュール名 〜 @code{endmodule}で囲む. +モジュールは入れ子にはできない. モジュールの中だけで使う大域変数は @code{static} で宣言する. この変数はモジュールの外からは参照もできないし変更もできない. モジュールの外の大域変数は @code{extern} で宣言する. @@ -1566,3 +1683,9 @@ module stack; /* The body of the module stack */ endmodule; @end example + +@table @t +\JP @item 参照 +\EG @item References +@fref{module_list}, @fref{module_definedp}, @fref{remove_module}. +@end table