Skip to content

builtins: add take n xs and drop n xs#188

Merged
danieljohnmorris merged 1 commit into
mainfrom
fix/take-drop-builtins
May 12, 2026
Merged

builtins: add take n xs and drop n xs#188
danieljohnmorris merged 1 commit into
mainfrom
fix/take-drop-builtins

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Slicing prefixes and suffixes is a daily need that previously required sub with arithmetic. take and drop give it a one-token form.

Implementation:

  • take n xs returns first n elements, drop n xs returns rest
  • works on lists and text
  • both clamp on out-of-range n, error on negative
  • opcodes allocated: take, drop

Tests: cross-engine regression tests + examples/take-drop.ilo with -- run: directives.

@danieljohnmorris danieljohnmorris force-pushed the fix/take-drop-builtins branch 2 times, most recently from f124ae4 to 34d5b8f Compare May 12, 2026 09:57
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 72.69625% with 80 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/interpreter/mod.rs 61.76% 26 Missing ⚠️
src/verify.rs 28.57% 20 Missing ⚠️
src/vm/mod.rs 87.83% 18 Missing ⚠️
src/vm/compile_cranelift.rs 15.78% 16 Missing ⚠️

📢 Thoughts on this report? Let us know!

@danieljohnmorris danieljohnmorris force-pushed the fix/take-drop-builtins branch 2 times, most recently from c868ea0 to 26b19ef Compare May 12, 2026 22:31
Slicing prefixes and suffixes is a daily need that previously required
sub start end with arithmetic. take n xs returns the first n elements,
drop n xs returns everything after. Both clamp on out-of-range n.

Opcodes allocated: take, drop. Works on lists and text. Negative n
errors at runtime via the standard verify path.
@danieljohnmorris danieljohnmorris force-pushed the fix/take-drop-builtins branch from 26b19ef to f692d14 Compare May 12, 2026 22:37
@danieljohnmorris danieljohnmorris merged commit a3b2578 into main May 12, 2026
4 of 5 checks passed
@danieljohnmorris danieljohnmorris deleted the fix/take-drop-builtins branch May 12, 2026 22:40
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.

1 participant