Next: , Previous: Expressions, Up: Expressions   [Contents][Index]

6.1 Introduction to Expressions

変数名として使えないたくさんの予約語があります。 これらを使うと、不可解な構文法エラーの原因となります。

integrate            next           from                 diff            
in                   at             limit                sum             
for                  and            elseif               then            
else                 do             or                   if              
unless               product        while                thru            
step                                                                     

Maximaのほとんどのものは式です。 括弧で囲み、コンマで区切ることで、式の列が構成できます。 これは、C言語のコンマ式に似ています。

(%i1) x: 3$
(%i2) (x: x+1, x: x^2);
(%o2)                          16
(%i3) (if (x > 17) then 2 else 4);
(%o3)                           4
(%i4) (if (x > 17) then x: 2 else y: 4, y+x);
(%o4)                          20

ループが返す値はあまり役に立たないdoneですが、Maximaではループでさえ式です。

(%i1) y: (x: 1, for i from 1 thru 10 do (x: x*i))$
(%i2) y;
(%o2)                         done

ところが、本当に欲しいものは、たぶん、実際に値を戻すコンマ式の3番目の項を含むことで得られます。

(%i3) y: (x: 1, for i from 1 thru 10 do (x: x*i), x)$
(%i4) y;
(%o4)                        3628800

Next: , Previous: Expressions, Up: Expressions   [Contents][Index]