 *** Welcome to SAD Ver.1.4.4.2k64 built at 2026-10-19 14:46:59 +0900 ***
 *** Today: 00:35:54 Tuesday 11/17/2026 ***
 OFF LOG;ON ECHO;READ 77 ;           1
FFS;
 *** SADScript Initialization: /mnt/d/work/SAD-master/SAD-master/Packages/init.n ***
 *** Run time Environment:     /mnt/d/work/SAD-master/SAD-master/Packages/init.local.n ***
 RFSW RADCOD RAD  FLUC  INTRA POL   COD  DAPER EMIOU K64   FOURI SMEAR
   F     F     F     T     F     F     T     F     F     T     F     T
 (* オプション: 規則 name->value を末尾に取り、Override[] で既定値と合わせる *)
 f1[x_, opt___Rule] := Module[{o = Override[opt, Scale->1, Offset->0]},
   Scale*x + Offset /. o];
 Print["f1 ", f1[3], " ", f1[3, Scale->2], " ", f1[3, Offset->10, Scale->2]];
f1 3 6 16
 (* 既定値つき引数 *)
 f2[x_, n_:2, m_:1] := x^n + m;
 Print["f2 ", f2[3], " ", f2[3, 3], " ", f2[3, 3, 5]];
f2 10 28 32
 (* Return と Break *)
 f3[l_List] := Module[{r = 0},
   Scan[If[# < 0, Return["negative found"]] &, l];
   Do[If[l[[i]] > 100, Return[i]], {i, Length[l]}];
   "none"];
 Print["f3 ", f3[{1, -1}], " ", f3[{1, 200}], " ", f3[{1, 2}]];
f3 negative found 2 none
 f4[n_] := Module[{k = 0}, While[True, k++; If[k^2 > n, Return[k]]]];
 Print["f4 ", f4[50]];
f4 8
 (* 再帰 *)
 fact[0] = 1;
 fact[n_] := n*fact[n - 1];
 Print["fact ", fact[10]];
fact 3628800
 gcd[a_, 0] := a;
 gcd[a_, b_] := gcd[b, Mod[a, b]];
 Print["gcd ", gcd[48, 18]];
gcd 6
 hanoi[0, _, _, _] := 0;
 hanoi[n_, a_, b_, c_] := hanoi[n - 1, a, c, b] + 1 + hanoi[n - 1, c, b, a];
 Print["hanoi ", hanoi[6, 1, 2, 3]];
hanoi 63
 (* 副作用と戻り値 *)
 f5[x_] := (Print["  side effect x=", x]; x^2);
 Print["f5 ", f5[4]];
  side effect x=4
f5 16
 (* 引数の個数で別定義 *)
 f6[] := "none"; f6[a_] := "one"; f6[a_, b_] := "two"; f6[a__] := "many";
 Print["f6 ", f6[], f6[1], f6[1, 2], f6[1, 2, 3]];
f6 noneonetwomany
 (* 評価を保留する引数: SetAttributes[HoldAll] *)
 SetAttributes[twice, HoldAll];
 twice[e_] := (e; e);
 k = 0; twice[k++]; Print["HoldAll twice k=", k];
HoldAll twice k=2
 (* ユーザー定義関数の定義の表示 *)
 Print["Definition ", Definition[fact]];
Definition Hold[{fact:=fact,fact[0]:=1,fact[n_]:=(n fact[-1+n])}]
 Exit;
Out[1]:= Exit
 FFS                  end:  CPU time =     0.001 sec
 Design orbit length =   1.0000000000000000     
 RFSW RADCOD RAD  FLUC  INTRA POL   COD  DAPER EMIOU K64   FOURI SMEAR
   T     F     F     T     F     F     T     F     F     T     F     T
 In[2]:=  ???-getbuf-end of input stream
