[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Question about arrays





On Mon, Dec 31, 2018, 2:54 PM <klipklipklapklap@xxxxxxxxx wrote:
Hello list,

This code:
x=Array.fill(10, {arg s=10; 5.do{s=sin(s*(s-1))}; s=s+1;});

yields the same results as this:
x=Array.fill(10, {arg s; 5.do{s=sin(s*(s-1))}; s=s+1;});

i.e. the initial value of s seems to always be 0. Is there a way to start at a value other than 0?

The simplest answer is, use:

{
  arg index;
  var s = index + n;
  ...
}

in your function. You could also use

Array.series(start, finish).collect { arg s; ... }

or even more terse:

(start..finish).collect { args s; ... }

However the first is clearest IMO.

Brian


Thanks!