From e2b4c3947fbefff353f8910c072bedd9772ebcab Mon Sep 17 00:00:00 2001 From: Lumi Pakkanen Date: Tue, 18 Jun 2024 11:46:06 +0300 Subject: [PATCH] Improve stdlib naming convention Remove near-duplicate methods of obscure operations. ref #350 --- documentation/BUILTIN.md | 24 +++++++++--------------- src/parser/__tests__/stdlib.spec.ts | 10 +++++----- src/stdlib/prelude.ts | 16 +++------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/documentation/BUILTIN.md b/documentation/BUILTIN.md index 9039c4b1..d8b85c67 100644 --- a/documentation/BUILTIN.md +++ b/documentation/BUILTIN.md @@ -425,9 +425,6 @@ Calculate the inverse hyperbolic cosine of x. ### add(*...terms*) Calculate the (linear) sum of the arguments. -### antiperiodiff(*constantOfIntegration*, *array*) -Calculate the cumulative geometric sums of a periodic difference pattern. Undoes what periodiff does. - ### asinh(*x*) Calculate the inverse hyperbolic sine of x. @@ -509,9 +506,6 @@ Calculate e raised to the power of x. ### fail(*message*) Throw the given message as an error. -### flatRepeat(*times = 2*, *scale = ££*) -Repeat the popped/given intervals as-is without accumulating equaves. - ### ftom(*freq*) Convert absolute frequency to MIDI note number / MTS value (fractional semitones with A440 = 69). @@ -587,12 +581,6 @@ Obtain a copy of the popped/given scale reduced by its last interval, sorted and ### parallelotope(*basis*, *ups = niente*, *downs = niente*, *equave = 2*, *basisSizeHints = niente*, *equaveSizeHint = niente*) Span a parallelotope by extending a basis combinatorically. `ups` defaults to all ones while `downs` defaults to all zeros. The size hints are used to get the correct period reduction when generating a preimage. -### periodiff(*array*) -Calculate the geometric differences of the periodic interval pattern. - -### periostack(*guideGenerator*, *array = ££*) -Stack the popped/given inflections along with the guide generator into a periodic sequence of steps. - ### pow(*x*, *y*) Calculate x to the power of y. @@ -626,6 +614,9 @@ Convert interval to relative logarithmic representation. ### repeat(*times = 2*, *scale = ££*) Stack the popped/given scale on top of itself. +### repeatFlat(*times = 2*, *scale = ££*) +Repeat the popped/given intervals as-is without accumulating equaves. + ### repeatLinear(*times = 2*, *scale = ££*) Repeat the popped/given scale shifted linearly each time. @@ -662,6 +653,9 @@ Cumulatively stack the popped/given intervals on top of each other. ### stackLinear(*array = ££*) Cumulatively sum the numbers of the popped/given array. +### stackPeriodic(*guideGenerator*, *array = ££*) +Stack the popped/given inflections along with the guide generator into a periodic sequence of steps. + ### stretch(*amount*, *scale = ££*) Obtain a copy of the popped/given scale streched by the given amount. A value of `1` corresponds to no change. @@ -698,12 +692,12 @@ Find a combination of three vals that is closer to just intonation. ### u(*scale = ££*) Obtain a undertonal reflection of the popped/given overtonal scale. -### unperiostack(*array = ££*) -Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator. - ### unstack(*array = ££*) Unstack the popped/given scale into steps. +### unstackPeriodic(*array = ££*) +Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator. + ### values(*record*) Obtain an array of values of the record. diff --git a/src/parser/__tests__/stdlib.spec.ts b/src/parser/__tests__/stdlib.spec.ts index 71ebb92a..6520ff89 100644 --- a/src/parser/__tests__/stdlib.spec.ts +++ b/src/parser/__tests__/stdlib.spec.ts @@ -514,7 +514,7 @@ describe('SonicWeave standard library', () => { it('can reduce Raga Bhairavi to a comma recipe (inline)', () => { const scale = expand( - 'periodiff(geodiff([16/15, 9/8, 6/5, 27/20, 3/2, 8/5, 9/5, 2/1]))' + 'unstackPeriodic(unstack([16/15, 9/8, 6/5, 27/20, 3/2, 8/5, 9/5, 2/1]))' ); expect(scale).toEqual([ '24/25', @@ -530,7 +530,7 @@ describe('SonicWeave standard library', () => { it('can reduce Raga Bhairavi to a comma recipe (verbs)', () => { const scale = expand( - '16/15;9/8;6/5;27/20;3/2;8/5;9/5;2/1;unstack();unperiostack()' + '16/15;9/8;6/5;27/20;3/2;8/5;9/5;2/1;unstack();unstackPeriodic()' ); expect(scale).toEqual([ '24/25', @@ -547,7 +547,7 @@ describe('SonicWeave standard library', () => { it('can recover Raga Bhairavi from its comma recipe (inline)', () => { const scale = expand(` cumprod( - antiperiodiff( + stackPeriodic( 10/9, [ 24/25, @@ -585,7 +585,7 @@ describe('SonicWeave standard library', () => { 24/25 135/128 80/81 - periostack(10/9) + stackPeriodic(10/9) stack() simplify `); @@ -948,7 +948,7 @@ describe('SonicWeave standard library', () => { }); it('can repeat unstacked steps', () => { - const zarlino7 = expand('5;3/5;flatRepeat(3);stack();2;reduce();sort()'); + const zarlino7 = expand('5;3/5;repeatFlat(3);stack();2;reduce();sort()'); expect(zarlino7).toEqual([ '9/8', '5/4', diff --git a/src/stdlib/prelude.ts b/src/stdlib/prelude.ts index a8c1ba2f..79949e37 100644 --- a/src/stdlib/prelude.ts +++ b/src/stdlib/prelude.ts @@ -306,7 +306,7 @@ riff geodiff(array) { return unstack(array); } -riff unperiostack(array = ££) { +riff unstackPeriodic(array = ££) { "Convert the popped/given periodic sequence of steps into inflections of the last interval as the guide generator."; array; const first = $[0] ~% $[-1]; @@ -316,12 +316,7 @@ riff unperiostack(array = ££) { $[0] = first; } -riff periodiff(array) { - "Calculate the geometric differences of the periodic interval pattern."; - return unperiostack(array); -} - -riff periostack(guideGenerator, array = ££) { +riff stackPeriodic(guideGenerator, array = ££) { "Stack the popped/given inflections along with the guide generator into a periodic sequence of steps."; if (not isInterval(guideGenerator)) throw "Guide generator must be an interval."; @@ -333,11 +328,6 @@ riff periostack(guideGenerator, array = ££) { $[i] ~*= $[i-1r]; } -riff antiperiodiff(constantOfIntegration, array) { - "Calculate the cumulative geometric sums of a periodic difference pattern. Undoes what periodiff does."; - return periostack(constantOfIntegration, array); -} - riff enumerate(array = $$) { "Produce an array of [index, element] pairs from the given current/given array."; return [[i, array[i]] for i in array]; @@ -775,7 +765,7 @@ riff repeatLinear(times = 2, scale = ££) { (scale ~- 1) ~+ level ~+ 1; } -riff flatRepeat(times = 2, scale = ££) { +riff repeatFlat(times = 2, scale = ££) { "Repeat the popped/given intervals as-is without accumulating equaves."; return arrayRepeat(times, scale); }