skx / gobasic

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

Support for WHILE/WEND #89

Open udhos opened 5 years ago

udhos commented 5 years ago

gobasic should support WHILE/WEND.

Documentation: http://www.antonis.de/qbebooks/gwbasman/whilewend.html

$ gobasic while.bas 
Error running program:
    Line 20 : Object{Type:error, Value:The variable 'while' doesn't exist}
$ 
$ more while.bas 
10 let a=1
20 while a<=10
30 print a
40 let a=a+1
50 wend
skx commented 5 years ago

Patches welcome, but I regard this as something I'd not be personally interested in implementing.

In my view simple BASIC uses FOR-loops, and line-numbers. Things like WHILE/WEND is the start of a slippery-slope that ends up supporting "ON ERR GOTO .." and other advanced constructs often those more advanced dialects of BASIC don't even need line-numbers, and allow functions with named-parameters, etc.

Some extensions, and expansions I can be persuaded are useful. (Such as your LET-less assignments, and READing into an array.) But I think there are limits, and whenever I'm unsure I just think back to my ZX Spectrum.

This is a deliberately minimal project, which is a little retro and niche. It won't make all scripts run, or all users happy, and I'm OK with that. It is, after all, just a weekend hack that got a bit bigger because it was fun to play with :)

udhos commented 5 years ago

Of course you should add features only if you find fun in doing so, I fully understand that.

I reported this request for WHILE/WEND because they were present in the old classical BASICA/GW-BASIC dialect for PCs. WHILE/WEND was not a "modern" extension added by things like QBASIC, QuickBasic, VisualBasic, etc.

Have a look at the GW-BASIC manual: http://www.antonis.de/qbebooks/gwbasman/whilewend.html