Accept zero-argument parameter lists in DEF and GEN #63

Open
opened 2026-08-06 11:34:17 -04:00 by andrew · 0 comments
Owner

Found during the PR #61 (generators) review; the PR itself notes it as deviation 2 and TODO.md §1.10 records it. Filed by Ishikawa via Andrew's account.

The problem

parse_def_parameters() (src/parser_commands.c) does not accept an empty parameter list, so neither of these can be written:

DEF NOW() = TI
GEN BEEPS()

Every function and generator must take at least one parameter whether it wants one or not — #61's own tests all carry a dummy N# for exactly this reason. Consequence: pointless parameters in programs. Blast radius: cosmetic, both DEF and GEN headers, no runtime effect. This is pre-existing (DEF had it before generators existed).

Implementation steps

  1. In parse_def_parameters(), after consuming (: if the next token is ), consume it and return an arglist with zero parameter leaves (whatever shape the callers treat as "no parameters" — check how fndef->arglist->right == NULL is handled in akbasic_runtime_call_function()'s and akbasic_runtime_generator_invoke()'s binding loops; both already guard with arglist != NULL ? arglist->right : NULL, so an arglist with an empty right should bind zero and be done).
  2. Verify the call side parses zero-argument call sites: NOW() as an expression, and FOR EACH V# IN BEEPS(). If akbasic_parser_expression() refuses an empty argument list inside a call, fix that in the same change — a definition nobody can call is not done.
  3. Verify arity checking (whatever the parser does for call/definition mismatch today) still behaves for the zero case: NOW(5) should fail the same way TWOARG(1) does.

Tests

  • tests/user_functions.c: a zero-argument single-expression DEF and a zero-argument multi-line DEF, called from an expression.
  • tests/generators.c: a zero-argument GEN consumed by both FOR EACH and DO EACH.
  • One golden pair under tests/language/ exercising a zero-argument DEF and GEN together.
  • A call with arguments to a zero-argument definition → error, not silence.

Docs

  • Remove the at-least-one-parameter caveat from TODO.md §1.10 (last paragraph) when closing.
  • docs/11-verb-reference.md DEF/GEN rows: no change needed unless they end up stating the restriction; check.
Found during the PR #61 (generators) review; the PR itself notes it as deviation 2 and TODO.md §1.10 records it. Filed by Ishikawa via Andrew's account. ## The problem `parse_def_parameters()` (`src/parser_commands.c`) does not accept an empty parameter list, so neither of these can be written: ``` DEF NOW() = TI GEN BEEPS() ``` Every function and generator must take at least one parameter whether it wants one or not — #61's own tests all carry a dummy `N#` for exactly this reason. Consequence: pointless parameters in programs. Blast radius: cosmetic, both `DEF` and `GEN` headers, no runtime effect. This is pre-existing (`DEF` had it before generators existed). ## Implementation steps 1. In `parse_def_parameters()`, after consuming `(`: if the next token is `)`, consume it and return an arglist with zero parameter leaves (whatever shape the callers treat as "no parameters" — check how `fndef->arglist->right == NULL` is handled in `akbasic_runtime_call_function()`'s and `akbasic_runtime_generator_invoke()`'s binding loops; both already guard with `arglist != NULL ? arglist->right : NULL`, so an arglist with an empty right should bind zero and be done). 2. Verify the *call* side parses zero-argument call sites: `NOW()` as an expression, and `FOR EACH V# IN BEEPS()`. If `akbasic_parser_expression()` refuses an empty argument list inside a call, fix that in the same change — a definition nobody can call is not done. 3. Verify arity checking (whatever the parser does for call/definition mismatch today) still behaves for the zero case: `NOW(5)` should fail the same way `TWOARG(1)` does. ## Tests - `tests/user_functions.c`: a zero-argument single-expression `DEF` and a zero-argument multi-line `DEF`, called from an expression. - `tests/generators.c`: a zero-argument `GEN` consumed by both `FOR EACH` and `DO EACH`. - One golden pair under `tests/language/` exercising a zero-argument DEF and GEN together. - A call with arguments to a zero-argument definition → error, not silence. ## Docs - Remove the at-least-one-parameter caveat from TODO.md §1.10 (last paragraph) when closing. - `docs/11-verb-reference.md` DEF/GEN rows: no change needed unless they end up stating the restriction; check.
Sign in to join this conversation.