skx / gobasic

A BASIC interpreter written in golang.
https://blog.steve.fi/tags/basic/
GNU General Public License v2.0
323 stars 27 forks source link

Fantasy Basic: Return values from subroutines? #25

Closed skx closed 5 years ago

skx commented 5 years ago

Looking at the code of my toupper/tolower example it is clear that BASIC makes it too easy to use globals:

 10 LET a$ = "STEVE"
  20 GOSUB blah
  30 REM a$ is now updated

If we wanted to provide clarity we could have said:

  10 LET a = "STEVE"  
  20 LET a = GOSUB 300
 30 END
 300 RETURN 3

i.e. "RETURN" now returns an expression. It doesn't help a lot, because the "input parameter" is still a random global. To allow named-parameters we'd need to implement "DEF FN" + "FN". But it's a cheap hack that might be useful.

Filed as fantasy issue for now.

skx commented 5 years ago

I'll close this because DEF FN and FN are implemented, which allows the same result.