J concepts in SC | SuperCollider 3.11.1 Help

submited by
Style Pass
2021-06-15 18:30:05

The J programming language is a successor of APL (http://www.jsoftware.com). These languages are made for processing arrays of data and are able to express complex notions of iteration implicitly.

The following are some concepts borrowed from or inspired by J. Thinking about multidimensional arrays can be both mind bending and mind expanding. It may take some effort to grasp what is happening in these examples.Filling arrays

iota fills an array with a counterz = Array.iota(2, 3, 3); z.rank; // 3 dimensions z.shape; // gives the sizes of the dimensions z = z.reshape(3, 2, 3); // reshape changes the dimensions of an array z.rank; // 3 dimensions z.shape;

fill a multidimensional array// 2 dimensions Array.fill([3,3], { 1.0.rand.round(0.01) }); Array.fill([2,3], {|i,j| i@j }); // 3 dimensions Array.fill([2, 2, 2], { 1.0.rand.round(0.01) }); Array.fill([2, 3, 4], {|i,j,k| [i, j, k].join }); // a shorter variant of the above: {|i,j,k| [i, j, k].join } ! [2, 3, 4]; // more dimensions Array.fill([2, 2, 4, 2], {|...args| args.join }); Creating arrays

using dup to create arrays(1..4) dup: 3; 100.rand dup: 10; {100.rand} dup: 10; {100.rand} dup: 3 dup: 4; {{100.rand} dup: 3} dup: 4; {|i| i.squared} dup: 10; {|i| i.nthPrime} dup: 10; { |i, j, k| i * j } dup: [5, 5]; // multidimensional dup

Leave a Comment