feat: add 7 builtins (cat, has, hd, tl, rev, srt, slc) + ternary guard-else#56
Merged
Merged
Conversation
- 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
This was referenced Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cat,has,hd,tl,rev,srt,slc(opcodes 49-55)cond{then}{else}— produces a value without early returnBuiltins
cat xs sepL t, t → thas xs vlist_or_text, any → bhd xslist_or_text → anytl xslist_or_text → list_or_textrev xslist_or_text → list_or_textsrt xslist_or_text → list_or_textslc xs a blist_or_text, n, n → list_or_textTernary
Test plan
Supersedes PRs #49-#55 (which had opcode collisions from parallel development).