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

gosub does not work as expected not ending nicely the program #15

Closed
carloshm opened this issue Jul 27, 2021 · 1 comment
Closed

gosub does not work as expected not ending nicely the program #15

carloshm opened this issue Jul 27, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@carloshm
Copy link
Contributor

the sample code:
10 diameter=5
20 gosub 100
30 print area
40 diameter=12
50 gosub 100
60 print area
70 end
100 print "The area of a circle of diameter "; diameter; " is: ";
110 area = pi*(diameter/2)^2
120 return
run
The area of a circle of diameter 5 is
19.6349540849
The area of a circle of diameter 12 is
113.0973355292
Mismatched statement closing mark at line 70

Adds an error when no error should be the expected

In this other example (forget about the logic )
Nothing to return to at line 160
Ready
shows up

10 cls
20 number_marks = 0
30 while number_marks < 100
40 if number_marks mod 2 = 1
50 ratius=10
60 gosub 140
70 else
80 ratius=5
90 gosub 140
100 break
110 number_marks = number_marks + 1
120 loop
130 end
140 move 250, 200
150 draw ratius, ratius + number_marks
160 return

@James-Livesey
Copy link
Member

Aha! I see the problem. To stop an atto program from executing further, the command's stop. Here's your code, with line 70 changed to stop.

The reason being is because end is used as an 'ending marker' for if statements. This feature is somewhat unique to atto since most other BASICs only support one-liner ifs, which seemed counter-intuitive if being able to make multiline for loops was possible.

The reason why atto throws the Mismatched statement closing mark error is because it expects there to be a preceeding if to match the end, akin to accidentally having an extra } at the end of a JavaScript/C-like program.

It may be seen as quite confusing for old BASIC users who would usually use end to stop a program, however I couldn't really see an alternative keyword that's used for ending if statements (Lua uses end like atto; fi is used in bash but is a bit obscure). As a consequence, stop is used instead of end.

It does appear that gosub seems to be in working order, though, which is good.

carloshm added a commit to carloshm-experiments/atto that referenced this issue Jul 28, 2021
Based on the comments on Issue devicefuture#15 devicefuture#15 I proposed the changes for the gosub example. On the other hand, a typo on the repeat example foes not allow to run it
@James-Livesey James-Livesey added the bug Something isn't working label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants