Skip to content

feat: add 7 builtins (cat, has, hd, tl, rev, srt, slc) + ternary guard-else#56

Merged
danieljohnmorris merged 2 commits into
mainfrom
feature/all-builtins-and-ternary
Mar 1, 2026
Merged

feat: add 7 builtins (cat, has, hd, tl, rev, srt, slc) + ternary guard-else#56
danieljohnmorris merged 2 commits into
mainfrom
feature/all-builtins-and-ternary

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • 7 new builtins: cat, has, hd, tl, rev, srt, slc (opcodes 49-55)
  • Ternary guard-else: cond{then}{else} — produces a value without early return
  • Each builtin has verifier type checks, interpreter implementation, VM opcode, and tests
  • SPEC.md updated with all new builtins and ternary syntax

Builtins

Builtin Signature Description
cat xs sep L t, t → t Join list of text with separator
has xs v list_or_text, any → b Membership test
hd xs list_or_text → any Head (first element/char)
tl xs list_or_text → list_or_text Tail (all but first)
rev xs list_or_text → list_or_text Reverse
srt xs list_or_text → list_or_text Sort (numbers/text)
slc xs a b list_or_text, n, n → list_or_text Slice from a to b

Ternary

f x:n>t;=x 1{"yes"}{"no"}    -- returns "yes" or "no"
f x:n>n;=x 0{10}{20};+x 1    -- ternary value discarded, returns x+1

Test plan

  • 917 tests pass (805 unit + 112 integration)
  • Verifier, interpreter, and VM tests for each builtin
  • Ternary tests: true/false branches, no-early-return, negated, guard unchanged
  • Parser test for ternary AST structure
  • No new clippy warnings

Supersedes PRs #49-#55 (which had opcode collisions from parallel development).

- cat xs sep: join list of text with separator → t
- has xs v: membership test (list element / text substring) → b
- hd xs: head of list or text (error if empty)
- tl xs: tail of list or text (error if empty)
- rev xs: reverse list or text
- srt xs: sort list (all-number or all-text) or text chars
- slc xs a b: slice list or text from index a to b (clamped)

Each builtin has verifier type checks, interpreter implementation,
VM opcode (OP_CAT=49 through OP_SLC=55), and tests across all three.
Add ternary syntax: a guard followed by a second brace block produces
a value without early return. Guards (`cond{body}`) still early-return.

- Parser: detect second `{` after guard body at all 3 construction sites
- AST: `else_body: Option<Vec<Spanned<Stmt>>>` on Stmt::Guard
- Interpreter: ternary returns BodyResult::Value (no early return)
- VM: JMPF/JMP conditional structure for if/else branches
- Verifier: type-check both branches
- Codegen: fmt emits `{else}`, python emits `if/else`
- SPEC.md updated with ternary syntax and all new builtins
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