Skip to content

interp: guide the [x y z] vector trap and add a signature builtin#86

Merged
ecto merged 2 commits into
mainfrom
claude/loon-subject-last-ergonomics-9ae03d
Jul 18, 2026
Merged

interp: guide the [x y z] vector trap and add a signature builtin#86
ecto merged 2 commits into
mainfrom
claude/loon-subject-last-ergonomics-9ae03d

Conversation

@ecto

@ecto ecto commented Jul 18, 2026

Copy link
Copy Markdown
Owner

What

Two ergonomic fixes in loon-lang, surfaced by loon's first end-user-facing consumer (the vcad Typst plugin, where people write loon inline):

1. The [x y z] vector trap gets a guiding message

[30 20 -1] is application, not a vector literal, so it evaluated to the opaque not callable: 30. All four not-callable sites — the interp call path, the pipe path, machine.rs, and builtins::apply_value — now share a single not_callable_msg helper. For a numeric callee it names the cause and shows both correct spellings:

not callable: 30 — 30 is a number, not a function. loon has no [x y z] vector syntax; write #[30 ...] for a vector, or pass components as separate arguments, e.g. [translate 30 20 -1 solid]

Non-numeric callees keep the plain not callable: <v> message. The error already carries a span via err_at; a companion vcad-loon change (separate repo) threads that span to a user-source line number.

2. signature builtin for discoverability

No way previously to learn a symbol's arity/arg names without reading source. [signature translate]"[translate x y z s]". Multi-clause fns join with |, rest params render as & name, builtins report "[name ...] (builtin)". Registered in the type checker as ∀a. a → Str (keeps the interp/checker builtin-parity test green).

Why

These are the language-level halves of a three-problem ergonomics pass (full tradeoff writeup, including the vcad-side subject-last lint and span→line threading, is in docs/plans/2026-07-18-subject-last-ergonomics.md). The design bar for the vector trap: make the wrong-input mistake loud and self-correcting at the moment it happens, without a parse-time ban that would outlaw legal macro-generated forms.

Tests

cargo test --workspace is green. New in tests/interp_tests.rs:

  • numeric-callee message on both the tree-walker and the EIR VM
  • plain message preserved for a non-numeric callee
  • signature over named, anonymous, builtin, and non-fn values

Reviewer notes

  • Backward compatible: no syntax or API changes, only a richer error string and one new builtin.
  • The doc references vcad extensively for context, but this PR touches only loon-lang. The vcad-loon consumer changes (VcadError line numbers, lint_vcad for the subject-last B−A trap) land in the vcad repo separately.

🤖 Generated with Claude Code

Loon's first end-user surface (the vcad Typst plugin) exposed two
ergonomic failures that live in loon-lang:

- [30 20 -1] is application, so a vector-literal habit yields the opaque
  "not callable: 30". All four not-callable sites (interp call + pipe
  paths, machine.rs, builtins::apply_value) now share not_callable_msg,
  which special-cases a numeric callee: it names the cause and shows the
  two correct spellings (#[30 ...] or separate args).

- No way to discover a symbol's arity/arg names without reading source.
  New `signature` builtin: [signature translate] -> "[translate x y z s]"
  (multi-clause fns join with |, rest params show as `& name`, builtins
  report "[name ...] (builtin)"). Registered in the checker as a. a -> Str.

The span already rides on err_at; the downstream vcad-loon change that
threads it to a line number lives in the vcad repo.

Tests: numeric-callee message on both the tree-walker and the VM, plain
message preserved for non-numeric callees, and signature over
named/anonymous/builtin/non-fn values.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
loon Ready Ready Preview, Comment Jul 18, 2026 8:50pm

Request Review

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ecto
ecto merged commit 97c9684 into main Jul 18, 2026
6 checks passed
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