Skip to content

array-like access syntax for subdivisions and alternating#111

Draft
unlessgames wants to merge 1 commit intodevfrom
cycle-indexing
Draft

array-like access syntax for subdivisions and alternating#111
unlessgames wants to merge 1 commit intodevfrom
cycle-indexing

Conversation

@unlessgames
Copy link
Copy Markdown
Collaborator

@unlessgames unlessgames commented Mar 10, 2026

Implementing #108

Subdivisons work as described in the issue. Being able to use patterns on the right side for this proved to be super handy for experimentation in my opinion, see examples in the tests.

fn indexing() -> Result<(), String> {
assert_cycle_equality("[a b c d]%0", "a")?;
assert_cycle_equality("[a b c d]%1", "a")?;
assert_cycle_equality("[a b c d]%2", "b")?;
assert_cycle_equality("[a b c d]%3", "c")?;
assert_cycle_equality("[a b c d]%4", "d")?;
assert_cycle_equality("[a b c d]%5", "a")?;
assert_cycle_equality("[a b c d]%0.1", "a")?;
assert_cycle_equality("[a b c d]%0.25", "b")?;
assert_cycle_equality("[a b c d]%0.499", "b")?;
assert_cycle_equality("[a b c d]%0.5", "c")?;
assert_cycle_equality("[a b c d]%0.999", "d")?;
assert_cycle_equality("[a b c d]%[1 3 3]", "a c c")?;
assert_cycle_equality("[a b c d]%[5 4 3]", "a d c")?;
assert_cycle_equality("[a b c d]%[1, 3, 4]", "a, c, d")?;
assert_cycle_equality("[a b c d]%<1 2 3>", "a")?;
assert_cycle_equality("[a b c d]%<[1*8 2*4 3*2 4]>", "a*8 b*4 c*2 d")?;
assert_cycles_equality("<a b c d>%2", &["b", "c", "d", "a"])?;

For alternating patterns <..> I went with using the index as an offset instead of a static access, so it still plays the inner steps across cycles but with an offset for where to start which seems like reasonable behaviour but there might be something better to do here, and while indexing from 1 is natural, using the same value for offsetting (ie 1 being no offset) is a bit less so.

@github-actions
Copy link
Copy Markdown

Benchmark for 8e03014

Click to view benchmark
Test Base PR %
Cycle/Generate 53.0±0.48µs 52.1±0.62µs -1.70%
Cycle/Parse 310.0±5.58µs 313.2±6.34µs +1.03%
Rust Phrase/Clone 429.7±8.08ns 427.4±4.58ns -0.54%
Rust Phrase/Create 66.8±1.47µs 66.8±0.85µs 0.00%
Rust Phrase/Run 639.9±6.68µs 654.2±4.15µs +2.23%
Rust Phrase/Seek 133.5±245.59µs 146.7±256.42µs +9.89%
Scripted Phrase/Clone 632.6±9.44ns 619.1±7.84ns -2.13%
Scripted Phrase/Create 1006.2±12.93µs 1000.7±18.06µs -0.55%
Scripted Phrase/Run 1664.1±15.86µs 1654.5±11.00µs -0.58%
Scripted Phrase/Seek 224.4±451.88µs 216.2±436.93µs -3.65%

@emuell
Copy link
Copy Markdown
Member

emuell commented Mar 11, 2026

Works great. And is super fun in combination with the new variables to in order to dynamically select sub sequences, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants