Returns a FoscPattern.
Pattern.
| indices | Gets indices of pattern. |
| inverted | Is true when pattern is inverted. |
| operator | Gets operator of pattern. |
| patterns | Gets paterns of pattern. |
| payload | Gets payload of pattern. |
| period | Gets period of pattern. |
| sum | (weight) |
| nil | [TODO] |
| & | Intersection (logical AND) of two patterns. Synonymous with sect. |
| – | Intersection (logical XOR) of two patterns. Synonymous with symmetricDifference. |
| asCompileString | |
| format | |
| invert | Inverts pattern in place. |
| sect | Intersection (logical AND) of two patterns. |
| size | |
| storeArgs | |
| str | |
| symmetricDifference | Intersection (logical XOR) of two patterns. |
| union | Union (logical OR) of two patterns. |
| booleanVector | Gets boolean vector of pattern applied to input sequence with size. |
| getMatchingItems | Gets matching items from container, selection, or sequenceable collection. |
| matchesIndex | Is true when pattern matches index taken under totalLength. |
| reverse | Reverses pattern. |
| rotate | Rotates pattern by index n. |
Matches three indices in every eight.
p = FoscPattern(#[0,1,7], period: 8);
n = 16;
n.collect { |i| [i, p.matchesIndex(i, n)] }.join("\n");[ 0, true ]
[ 1, true ]
[ 2, false ]
[ 3, false ]
[ 4, false ]
[ 5, false ]
[ 6, false ]
[ 7, true ]
[ 8, true ]
[ 9, true ]
[ 10, false ]
[ 11, false ]
[ 12, false ]
[ 13, false ]
[ 14, false ]
[ 15, true ]Matches three indices in every sixteen.
p = FoscPattern(#[0,1,7], period: 16);
n = 16;
n.collect { |i| [i, p.matchesIndex(i, n)] }.join("\n");[ 0, true ]
[ 1, true ]
[ 2, false ]
[ 3, false ]
[ 4, false ]
[ 5, false ]
[ 6, false ]
[ 7, true ]
[ 8, false ]
[ 9, false ]
[ 10, false ]
[ 11, false ]
[ 12, false ]
[ 13, false ]
[ 14, false ]
[ 15, false ]Works with improper indices.
p = FoscPattern(#[16,17,23], period: 16);
n = 16;
n.collect { |i| [i, p.matchesIndex(i, n)] }.join("\n");[ 0, true ]
[ 1, true ]
[ 2, false ]
[ 3, false ]
[ 4, false ]
[ 5, false ]
[ 6, false ]
[ 7, true ]
[ 8, false ]
[ 9, false ]
[ 10, false ]
[ 11, false ]
[ 12, false ]
[ 13, false ]
[ 14, false ]
[ 15, false ]Sieve from opening of Xenakis’s Psappha.
~sieve_1a = FoscPattern.indices(#[0,1,7], 8);
~sieve_1b = FoscPattern.indices(#[1,3], 5);
~sieve_1 = ~sieve_1a & ~sieve_1b;
~sieve_2a = FoscPattern.indices(#[0,1,2], 8);
~sieve_2b = FoscPattern.indices(#[0], 5);
~sieve_2 = ~sieve_2a & ~sieve_2b;
~sieve_3 = FoscPattern.indices(#[3], 8);
~sieve_4 = FoscPattern.indices(#[4], 8);
~sieve_5a = FoscPattern.indices(#[5,6], 8);
~sieve_5b = FoscPattern.indices(#[2,3,4], 5);
~sieve_5 = ~sieve_5a & ~sieve_5b;
~sieve_6a = FoscPattern.indices(#[1], 8);
~sieve_6b = FoscPattern.indices(#[2], 5);
~sieve_6 = ~sieve_6a & ~sieve_6b;
~sieve_7a = FoscPattern.indices(#[6], 8);
~sieve_7b = FoscPattern.indices(#[1], 5);
~sieve_7 = ~sieve_7a & ~sieve_7b;
~sieve = ~sieve_1 | ~sieve_2 | ~sieve_3 | ~sieve_4 | ~sieve_5 | ~sieve_6 | ~sieve_7;
~sieve.booleanVector(size: ~sieve.period);[ 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0 ]Gets indices of pattern.
Is true when pattern is inverted.
Gets operator of pattern.
Gets paterns of pattern.
Gets payload of pattern.
Gets period of pattern.
Example
p = FoscPattern.indices(#[0], period: 3) | FoscPattern.indices(#[0], period: 4);
p.period;12
p = FoscPattern.indices(#[0], period: 3);
p.period;3(weight)
Gets sum of pattern.
Sum defined equal to number of indices in pattern.
Returns nonnegative integer.
Example
a = FoscPattern(#[0,2,3]);
a.sum;3[TODO]
Example
a = "abcde";
p = FoscPattern.first(2) union: FoscPattern.last(2);
p.getMatchingItems(a);[ $a, $b, $d, $e ]Intersection (logical AND) of two patterns. Synonymous with sect.
Example
a = "abcde";
p = FoscPattern.first(3) & FoscPattern.last(3);
p.getMatchingItems(a);[ $c ]Intersection (logical XOR) of two patterns. Synonymous with symmetricDifference.
Example
a = "abcde";
p = FoscPattern.first(2) -- FoscPattern.last(2);
p.getMatchingItems(a);[ $a, $b, $d, $e ]Example
p = FoscPattern.indices(#[0,1,2], 5);
p.cs;FoscPattern([ 0, 1, 2 ], 5)Example
p = FoscPattern.indices(#[0,1,2], 5);
p.format;FoscPattern([ 0, 1, 2 ], 5)Inverts pattern in place.
Example
p = FoscPattern.indices(#[0,1,3], 4);
p.booleanVector;[ 1, 1, 0, 1 ]
p.invert;
p.booleanVector;[ 0, 0, 1, 0 ]Intersection (logical AND) of two patterns.
Example
a = "abcde";
p = FoscPattern.first(3) sect: FoscPattern.last(3);
p.getMatchingItems(a);[ $c ]Example
p = FoscPattern.first(2);
p.size;2
p = FoscPattern.first(2) | FoscPattern.last(2);
p.size;0Example
a = FoscPattern.indices(#[0,1,2], 5);
a.str;FoscPattern([ 0, 1, 2 ], 5)Intersection (logical XOR) of two patterns.
Example
a = "abcde";
p = FoscPattern.first(2) symmetricDifference: FoscPattern.last(2);
p.getMatchingItems(a);[ $a, $b, $d, $e ]Union (logical OR) of two patterns.
Example
a = "abcde";
p = FoscPattern.first(2) union: FoscPattern.last(2);
p.getMatchingItems(a);[ $a, $b, $d, $e ]Gets boolean vector of pattern applied to input sequence with size.
size is set to size of pattern when no value is specified for size.
p = FoscPattern.indices(#[4,5,6,7]);FoscPattern([ 4, 5, 6, 7 ])
p.booleanVector(4);[ 0, 0, 0, 0 ]
p.booleanVector(8);[ 0, 0, 0, 0, 1, 1, 1, 1 ]
p.booleanVector(16);[ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 ]
p.booleanVector;[ 0, 0, 0, 0, 1, 1, 1, 1 ]Two part pattern with logical OR (union).
p = FoscPattern.first(3) | FoscPattern.last(3);
p.booleanVector(8);[ 1, 1, 1, 0, 0, 1, 1, 1 ]Vector of inverted pattern.
p.invert;
p.booleanVector(8);[ 0, 0, 0, 1, 1, 0, 0, 0 ]Gets matching items from container, selection, or sequenceable collection.
Example
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern.indices(#[4,5,6,7]);
p.getMatchingItems(a);[ $e, $f, $g, $h ]
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern.indices(#[8,9], period: 10);
p.getMatchingItems(a);[ $i, $j, $s, $t ]
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern.first(4);
p.getMatchingItems(a);[ $a, $b, $c, $d ]
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern.last(3);
p.getMatchingItems(a);[ $x, $y, $z ]
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern.first(1) | FoscPattern.last(2);
p.getMatchingItems(a);[ $a, $y, $z ]
a = "abcdefghijklmnopqrstuvwxyz";
p = FoscPattern(#[0,-2,-1]);
p.getMatchingItems(a);[ $a, $y, $z ]Is true when pattern matches index taken under totalLength.
Example
p = FoscPattern.indices(#[0,1,7], period: 8);
16.collect { |i| [i, p.matchesIndex(i, 16)] }.join("\n");[ 0, true ]
[ 1, true ]
[ 2, false ]
[ 3, false ]
[ 4, false ]
[ 5, false ]
[ 6, false ]
[ 7, true ]
[ 8, true ]
[ 9, true ]
[ 10, false ]
[ 11, false ]
[ 12, false ]
[ 13, false ]
[ 14, false ]
[ 15, true ]Reverses pattern.
Returns new pattern.
Example
p = FoscPattern(#[0,1,3], 4);
p.booleanVector(8);[ 1, 1, 0, 1, 1, 1, 0, 1 ]
p = p.reverse;
p.booleanVector(8);[ 1, 0, 1, 1, 1, 0, 1, 1 ]Example
p = FoscPattern.first(3) | FoscPattern.last(1);
p.booleanVector(6);[ 1, 1, 1, 0, 0, 1 ]
p = p.reverse;
p.booleanVector(6);[ 1, 0, 0, 1, 1, 1 ]Rotates pattern by index n.
Returns new pattern.
Example
p = FoscPattern(#[0,1,3], 4);
p.booleanVector(8);[ 1, 1, 0, 1, 1, 1, 0, 1 ]
p = p.rotate(1);
p.booleanVector(8);[ 1, 1, 1, 0, 1, 1, 1, 0 ]
p = p.rotate(-1);
p.booleanVector(8);[ 1, 1, 0, 1, 1, 1, 0, 1 ]Example
p = FoscPattern.first(3) | FoscPattern.last(1);
p.booleanVector(6);[ 1, 1, 1, 0, 0, 1 ]
p = p.rotate(1);
p.booleanVector(6);[ 1, 1, 1, 1, 0, 0 ]
p = p.rotate(-1);
p.booleanVector(6);[ 1, 1, 1, 0, 0, 1 ]