Skip to content

feat: add hd and tl builtins#51

Closed
danieljohnmorris wants to merge 1 commit into
mainfrom
feature/builtin-hd-tl
Closed

feat: add hd and tl builtins#51
danieljohnmorris wants to merge 1 commit into
mainfrom
feature/builtin-hd-tl

Conversation

@danieljohnmorris
Copy link
Copy Markdown
Collaborator

Summary

  • Add hd builtin: returns the first element of a list or first character of text
  • Add tl builtin: returns a list without its first element, or text without its first character
  • Both error on empty input (ILO-R009)

Changes

  • Verifier: hd and tl in BUILTINS array with list_or_text param type; builtin_check_args returns correct types (e.g. hd on L n returns n, tl on L n returns L n)
  • Interpreter: runtime dispatch for both builtins on List and Text values
  • VM: OP_HD (48) and OP_TL (49) opcodes with compiler emission and NanVal dispatch

Test plan

  • Verifier: hd/tl valid with list, valid with text, wrong type errors
  • Interpreter: hd/tl on list and text
  • VM: hd/tl on list and text
  • All 865 tests pass (753 unit + 112 integration)
  • Clippy clean (no new warnings)

@danieljohnmorris
Copy link
Copy Markdown
Collaborator Author

Superseded by #56 which combines all builtins + ternary with correct opcode numbering.

@danieljohnmorris danieljohnmorris deleted the feature/builtin-hd-tl branch March 1, 2026 19:01
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