Skip to content

Instantly share code, notes, and snippets.

@yotamorimoto
Last active March 30, 2017 16:05
Show Gist options
  • Select an option

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

Select an option

Save yotamorimoto/2275601 to your computer and use it in GitHub Desktop.
stream, pattern, and routine
Stream はオブジェクトのストリーム(流れ)で .next メッセージを受け「流れる」
Pattern はストリームの設計図
パターンオブジェクトのひとつ Pseries を使って
0から始まり、2ずつ増える、5個のストリームをつくる
p = Pseries(0, 2, 5).asStream;
p.next;
p.next;
p.next;
p.next;
p.next;
p.next; // 5回目以降は nil が返る
配列からストリームをつくる
配列は [ ] でつくる(他の方法は Array クラスのヘルプ参照)
p = Pseq([6, 5, 1, 2.5, -100], inf).asStream; // inf キーワードによって無限に繰り返す
20.do { p.next.postln; }; // number.do {} で関数を20回実行
実践1
Pgeom, Pbrown, Pwhite を使ってストリームを定義し実行する
実践2
Pseq, Pser, Prand, Pxrand, Pwrand, Pshuf と配列を使ってストリームを定義、実行する
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment