Skip to content

Instantly share code, notes, and snippets.

@yotamorimoto
Last active February 7, 2026 15:32
Show Gist options
  • Select an option

  • Save yotamorimoto/2272598 to your computer and use it in GitHub Desktop.

Select an option

Save yotamorimoto/2272598 to your computer and use it in GitHub Desktop.
{ } カーリーブラッケットは関数
関数の中で、音の鳴り方や、計算などができる
f = {};
SC では、小文字のアルファベットは、変数(関数や値などを格納する)
デフォルトで s にはサーバが格納されている
s.boot; // サーバ起動
s.isKindOf(Server); // s はサーバですか? yes -> true, no -> false が出力
計算
f = { 1 + 2 / 2 };
実行
f.value;
引数(実行時に値を渡す)
f = { |in| in * 3 };
実行
f.value(2); // 引数で渡される 2 *(かける)3 で 6 が出力
プログラムが複数行にわたる時、() 括弧を使う
() 括弧でくくられたブロックは、括弧のすぐあとをダブルクリックすると
ブロックごと選択できるので、選択後、実行する
(
f = { |aNumber|
var anotherNumber; // 関数内で変数をつくる
anotherNumber = aNumber + 1; // 変数に「引数+1」を代入
aNumber * anotherNumber; // 関数内の最後の行が結果として返る
};
)
f.value(2); // 実行
実践
引数つきの関数を作る
(
f = { |x, y|
var z;
z = x * 2;
x - y - z;
};
)
f.value(10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment