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

Allow string-multiplication #113

Closed skx closed 2 years ago

skx commented 2 years ago

I saw a bug report in a related project, relating to "string multiplication":

Supporting this would be nice and simple, and I recall it was always useful in Perl.

Something like the following should work as expected:

10 LET a = "STEVE "
20 LET b = 4
40 LET c = a * b
50 PRINT c
prologic commented 2 years ago

Hahahaha 😂 Does anyone seriously actually still write in BASIC? 🤔 Still a good idea to add this, if I recall this was always supported by even GWBASIC IIRC 👌

skx commented 2 years ago

The most recent project I worked on recently was a trivial text-based adventure game, written in Z80 assembly language, and designed for CP/M! There's a lot of the retro stuff around these days, and while it'll never be hugely popular it's still fun to see.

I was recently shown a project using the BASIC from this repository to control bots, basically a port/reimagining of crobots:

So .. I guess the answer is "yes".

ThomasMertes commented 2 years ago

I brought up the issue in PyBasic, because I thought that they introduced something that was not present in historic / vintage BASIC interpreters. I was not able to find any reference in the manuals of GW-Basic, QuickBasic, QBasic or TI-99 extended Basic. At Rosetta Code the page about repeating a string showed also no reference to a BASIC that supported string multiplication with *. A reference to the manual of APC Megabasic (link, see page 123) convinced me that at least some historic / vintage BASIC had support for it. So for me it is not about "it would be nice" or "it is useful in any other language". I think that interpreters for historic / vintage programming languages should refuse to introduce new features that were not present in the past (at historic / vintage time). That said I am convinced and already added this feature to Bas7, which is my interpreter of old BASIC programs. Btw: Bas7 is also at GitHub as part of Seed7 project. See: here

skx commented 2 years ago

Yeah I saw the discussion there. My project is mostly just for fun and nostalgia. Whenever I'm asked about features I say yes if they were present in ZX Spectrum BASIC, but usually not if they weren't.

I can be persuaded though, when something cool is raised. Seeing the original report my immediate reaction was "That would have been cool when I was a child [using the Spectrum]". That's enough reason to add it here.

Will commit a PR later this evening/tomorrow.

prologic commented 2 years ago

Oh actually that's pretty cool! 👌 Maybe I can show this to my daughter and teach her to code 🤣