Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed enhancement FUNCTION or DEF FN #69

Open
marianodominguez opened this issue Mar 23, 2023 · 1 comment
Open

Proposed enhancement FUNCTION or DEF FN #69

marianodominguez opened this issue Mar 23, 2023 · 1 comment

Comments

@marianodominguez
Copy link

This is a thing lacking in all Atari Basic implementations, ability to define functions. (same as PROC defines rubroutines)

https://zxbasic.readthedocs.io/en/docs/function/

I propose using the stack for being able to do recursive functions, if local variables are too complex, this implementation uses only parameter copy.

That allows for shorter code. eg

160 XX=X+1:EXEC HS:HS1=V:XX=X-1:EXEC HS:HS2=V:XX=X+3:EXEC HS:HS3=V:XX=X-3:EXEC HS:HS4=V
170 YT=(H-L)*HS1+(R-H)*HS2+(L-W)*HS3+(W-R)*HS4+W
becomes
170 YT=(H-L)*HS(X+1)+(R-H)*HS(X-1)+(L-W)*HS(X+3)+(W-R)*HS(X-3)+W

@dmsc
Copy link
Owner

dmsc commented Mar 23, 2023

Note that your example is better written using a procedure with parameters:

  @HS X+1 : YT = V*(H-L) : @HS X-1 : YT = YT + V*(R-H) : @HS X+3 : YT = YT + V*(L-W) : @HS X-3 : YT = YT + V*(W-R)
  PROC HS COORD
    V = ........ ' your expression here
  ENDPROC  

The problem with functions is that, for the 6502 compiler to work, you can´t write to variables or call statements from a function - and also you could not nest USR() functions.

Having a limited DEF FN implementation could work - it has the benefit of having a standard naming convention for functions ( FN* ).

@dmsc dmsc mentioned this issue Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants