michaeljabbour / michaeljabbour/altairbasic
Fix User-Defined Functions (DEF FN)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
# Fix User-Defined Functions (DEF FN)
## Issue Description
The implementation of user-defined functions using the DEF FN syntax has issues. When trying to create and use a function, the interpreter either fails to recognize the syntax or throws an error during execution.
## Steps to Reproduce
Create a file with the following BASIC code:
Running this program results in either parse errors or runtime errors with messages like 'FNA is not an array'.
## Expected Behavior
- The DEF FN statement should define a user function
- The function should be callable using the syntax FN A(X)
- The function should execute correctly and return the expected result
## Technical Details
Issues may exist in multiple components:
1. Lexer/parser might not correctly handle the FN syntax
2. The interpreter may not be storing or retrieving the function definition correctly
3. Function evaluation might not be implemented properly
## Proposed Solution
1. Ensure the parser correctly handles both DEF FN and function call syntax
2. Update function storage mechanism in the environment
3. Fix function evaluation in the interpreter
4. Consider examining original ALTAIR BASIC documentation for the exact syntax
## Related Components
- src/core/lexer.cpp - Tokenization of FN syntax
- src/core/parser.cpp - Parsing function definitions and calls
- src/core/ast.cpp - Function representation
- src/core/interpreter.cpp - Function execution
## Priority
Medium - Functions are an important feature but not as critical as core execution flow
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/core/lexer.cpp and src/core/parser.cpp to trace DEF FN and FN A(X) handling, then inspect src/core/ast.cpp and src/core/interpreter.cpp for function storage and evaluation. Reproduce the reported parse or “FNA is not an array” error with a minimal BASIC program. Done means DEF FN defines a function and FN A(X) calls it and returns the expected result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100