diff --git a/content/mimiumの配列実装.md b/content/mimiumの配列実装.md index 5ce55825..9d36a604 100644 --- a/content/mimiumの配列実装.md +++ b/content/mimiumの配列実装.md @@ -76,4 +76,47 @@ impl Machine{ } } -``` \ No newline at end of file +``` + + +## 用途 + +例えばcatさんに作ってもらったこの辺の再帰を用いたコードがあるとする + +```rust +fn gen_metalic_rec(times,freq,oscproto){ + if(times>0){ + let next = gen_metalic_rec(times-1,freq*1.176,oscproto) + let osc = oscproto(); + | | { osc(freq) + next() } + }else{ + | | 0.0 + } +} +fn gen_metalic(times,freq){ + let gen = gen_metalic_rec(times,freq,| | square_0); + | | gen() / times +} +let lowest_freq = 200.0 +let myoscbank = gen_metalic(6,lowest_freq) +``` + +こういう組み込み関数を与えて、 + +```rust +extern enumerate_by: (times,init:float,(x:float,acc:float)->float)->[float] +``` + +```rust + +fn metalic(times,lowest_freq){ + let freqs = enumerate_by(times,lowest_freq, |_x,acc| acc*1.167) + let res = map(freqs,|f| `square_0(liftf(f))) + |> foldl(_, |x,acc| `{ $x + $acc } ) + `{$res / liftf(times)} +} +fn dsp(){ + metalic!(6,200) +} + +```