Add SPC and POS print functions - #123
Merged
Merged
Conversation
SPC( and POS( are standard Microsoft 8K BASIC functions that were not reserved words, so they lexed as ordinary identifiers and became implicit array references. PRINT "A";SPC(5);"B" auto-dimensioned an array and printed A0B instead of emitting five spaces. Reserve both names, parse them as call expressions, and evaluate them in the PRINT item path alongside TAB. SPC yields a print-list directive that renders as a run of spaces; POS returns the current output column as a number, so it also works outside PRINT. A negative SPC count is a runtime error, mirroring TAB. No program in the pinned corpus uses either name as a function or a bare identifier, so reserving them changes no existing transcript. Closes #121 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Closes #121.
Behavior
SPC(andPOS(are standard Microsoft 8K BASIC functions that were not reserved words. They lexed as ordinary identifiers, which made them implicit array references that auto-dimensioned and returned0.Before
After
Composed with
TAB, showingPOSreads the same column thatTABand the comma zones write:Design notes
SPCreturns a print-list directive rendered as a run of spaces, mirroring howTABalready works.A=SPC(5)is therefore a type error, exactly asA=TAB(5)already was.POSreturns a plain number, so it works anywhere an expression is allowed, not only insidePRINT. This asymmetry is correct Microsoft behavior and is now stated in the language reference.SPCcount is a runtime error, mirroringTAB position cannot be negative.POSrequires a numeric argument and ignores its value. Microsoft ignores it too; requiring it to be numeric keeps the no-silent-coercion rule.Risk
No program in the pinned corpus uses
SPCorPOS— as a function or as a bare identifier:So reserving the names changes no existing transcript. Corpus smoke still passes all 112 byte-distinct variants.
Follow-up filed, not fixed here
#122 —
TAB(200000000)allocates 206 MB of padding, measured. That is pre-existing inTAB, andSPCdeliberately mirrors it rather than introducing a one-sided guard, so both should be bounded together.Commands run
Full CI gate, all green on the committed state:
Tests added:
TestLexerRecognizesSpcAndPos,TestEvaluatorEmitsSpcSpacingAndReportsPosColumn(coversSPC(n),SPC(0),POSat column 0, after a semicolon-suppressedPRINT, after a comma zone, and composed withTAB), plusnegative spc,spc argument count, andpos argument countrows inTestEvaluatorReportsRuntimeErrors.🤖 Generated with Claude Code