richpl / PyBasic

Simple interactive BASIC interpreter written in Python
GNU General Public License v3.0
170 stars 46 forks source link

string multiplication with * #49

Closed ThomasMertes closed 3 years ago

ThomasMertes commented 3 years ago

In the example program PyBStartrek.bas is the line:

1413 Q$=" "*192

I did not find a definition for this kind of string multiplication. Neither in the manual of GW-Basic nor in the manuals of QuickBasic, QBasic or TI-99 extended Basic. But maybe I overlooked it.

There is a page about repeating a string at Rosetta Code. None of the BASIC examples uses * for string multiplication. In almost all BASIC examples a loop is used. In some BASIC examples there is a function for string multiplication:

BBC BASIC has STRING$(5, "ha")
PowerBasic has REPEAT$(5, "ha")
TI-99 Extended BASIC has RPT$("ha", 5)

So my question is: Which historic BASIC defines this kind of string multiplication?

If there is no historic BASIC with * as string multiplications I suggest to rewrite line 1413 of the PyBStartrek.bas example and additionally I suggest also to remove this functionality from PyBasic and writing a syntax error such as:

**** [1413] UNEXPECTED SYMBOL "".

instead. If there is some historic BASIC with * as string multiplication please tell me such that I can add it to my Bas7 BASIC interpreter (which is also for historic BASIC programs).

RetiredWizard commented 3 years ago

Interesting point @ThomasMertes, I don't know if @richpl views PyBasic as a historic reproduction or simply capable of running vintage programs. Either way, perhaps there's some value in considering a more common repeat function, although by your examples it doesn't look like the historic BASICs had standardized on any particular method. As far as a historic example goes, there is APC Megabasic by Christopher Cochran, I found a manual of the GE version of Megabasic here

I'm not sure I'd use APC Megabasic as a template for historic BASICs though. While I was using it in the early 80s to deliver commercial applications it was a very advanced BASIC for it's time. In addition to string repetition (*), concatenation (+) and subtraction (-), it included an encrypted binary run format, vector math and pointer operations to name a few of it's more advanced features.

RetiredWizard commented 3 years ago

FYI my earliest copy of startrek.bas set the Q$ variable with the following lines of code:

820 Z$=" " Should be 25 spaces, I'm not good at GIT formatting :/
1410 FOR I=1 TO 3:K(I,3)=0: NEXT I:Q$=Z$+Z$+Z$+Z$+Z$+Z$+Z$+LEFT$(Z$,17)

I believe GWBasic supports this method.

ThomasMertes commented 3 years ago

I never heard about APC Megabasic. Page 123 of the APC Megabasic manual confirms that it really supports as operator for string multiplication. If you used it it in the early 80s this is IMHO a historic / vintage BASIC and all BASIC interpreters for historic / vintage BASIC programs should support it. I will definitely add as string multiplication operator also to Bas7.

RetiredWizard commented 3 years ago

I don't know if it makes a difference to you, but APC Megabasic didn't have a huge user base. I pulled this quote from Chris Cochran's current LinkedIn profile:

I have been involved in software development continuously since 1976. From 1985 to 2000 I personally developed and supported the x86 assembler-based MegaBasic programming language, having several thousand users, including its use by GE/Fanuc in a line of industrial process controllers.

ThomasMertes commented 3 years ago

The size of the APC Megabasic user base is not a problem. And the feature will hardly collide with string expressions allowed by other BASIC dialects. I just didn't want to add a feature that was introduced in 2021 by PyBasic or some other modern BASIC interpreter. My focus is on historic / vintage BASIC programs, therefore modern features are not so interesting.

richpl commented 3 years ago

So I guess Python duck typing has sort of come to the rescue again! It gave me string concatenation using + for free.

If @RetiredWizard hadn't found an example of a BASIC dialect that uses for string repetition, then the purist in me would probably think about implementing a block on its use. But if we have an example then I see no reason to stop it. I will add to the ReadMe at some point. Not sure where this version of Star Trek came from, but clearly from a dialect that also supported , whether it was APC Megabasic or not.

Bigger issue for me is that while trying to port The Oregon Trail I'm finding instances of a timer function (certainly in Chipmunk BASIC). I'm trying to decide if the port is worth the hassle of trying to introduce something similar or whether I can find a workaround.

ThomasMertes commented 3 years ago

Regarding your port of Oregon Trail. Ok, I know this is not the correct place to discuss, but

RetiredWizard commented 3 years ago

Of course it's up to @richpl to move PyBasic towards whatever vision he has for it, but I'll throw my thoughts out there as well.

If the purpose of all the versions of BASIC was the same then there would be no reason to develop more than one. I think it's great that Bas7 is setting out to provide a way to run historical vintage code, but I'm also happy that @richpl developed such an accessible, easy to modify version. I have learned so much about Python and interpreter operations from PyBasic.

I would also point out that the process of porting to the various dialects of BASIC didn't begin when these old programs became "vintage". I was porting startrek from GWBasic to MegaBasic to Fortan back in the 80's.

When David Ahl's awesome books on Basic Computer first came out, I grabbed them up but even brand new I had to perform some porting on almost every program I typed in.

RetiredWizard commented 3 years ago

Also, :-D

The fact that PyBasic can be run on a microcontroller is the thing that initially got my attention. Adding the additional functionality (and memory overhead) to support all dialects of vintage basic would likely make running on microcontrollers less practical.

richpl commented 3 years ago

I have to agree with @RetiredWizard, there is a long and proud history of BASIC porting. Having grown up in the UK, there were literally hundreds of companies trying to develop home computers in the early 1980s, and they all ran different dialects.

Having said that @ThomasMertes, there are more changes that could usefully be made to PyBasic to bring it more in line with vintage versions. Having ported a few BASIC programs over the last few weeks, I have found some of the deficiencies a bit infuriating!

By the way, thanks for the pointer to the Oregon Trail code. I could implement TIMER, but I was struggling to find details of what it returned. Having implemented it on Bas7 do you know whether it returns epoch second, epoch milliseconds or whatever?