Accept zero-argument parameter lists in DEF and GEN #63
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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: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, bothDEFandGENheaders, no runtime effect. This is pre-existing (DEFhad it before generators existed).Implementation steps
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 howfndef->arglist->right == NULLis handled inakbasic_runtime_call_function()'s andakbasic_runtime_generator_invoke()'s binding loops; both already guard witharglist != NULL ? arglist->right : NULL, so an arglist with an empty right should bind zero and be done).NOW()as an expression, andFOR EACH V# IN BEEPS(). Ifakbasic_parser_expression()refuses an empty argument list inside a call, fix that in the same change — a definition nobody can call is not done.NOW(5)should fail the same wayTWOARG(1)does.Tests
tests/user_functions.c: a zero-argument single-expressionDEFand a zero-argument multi-lineDEF, called from an expression.tests/generators.c: a zero-argumentGENconsumed by bothFOR EACHandDO EACH.tests/language/exercising a zero-argument DEF and GEN together.Docs
docs/11-verb-reference.mdDEF/GEN rows: no change needed unless they end up stating the restriction; check.