User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Tue Apr 16, 2019 8:59 pm

jahboater wrote:
Tue Apr 16, 2019 5:56 pm
Except that it no longer supports legacy x87 instructions.
Correct me if I'm wrong, but my understanding is that the x87 FPU instructions are supported by Valgrind, but their results will be accurate to only 64 bits of precision rather than 80. Hence numeric values may be different compared with normal execution, but Valgrind can nevertheless analyse a program which includes those instructions. I would have thought that was essential, considering that both GCC and clang (and their libraries) implement 'long double' calculations that way when targeting an x86.

jahboater
Posts: 4675
Joined: Wed Feb 04, 2015 6:38 pm

Re: Introduction to BBC BASIC

Tue Apr 16, 2019 9:07 pm

RichardRussell wrote:
Tue Apr 16, 2019 8:59 pm
Correct me if I'm wrong, but my understanding is that the x87 FPU instructions are supported by Valgrind, but their results will be accurate to only 64 bits of precision rather than 80.
I think you are right - all my tests that relied on 80-bits failed. I always had to comment out the FPU stuff from my test scripts when I passed them through valgrind :( Now I am using AVX it all just works.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Wed May 01, 2019 2:58 pm

BBC BASIC (using the supplied 'gpiolib' library) controlling the GPIO outputs of a RPi 3:

Image

User avatar
scruss
Posts: 2475
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Introduction to BBC BASIC

Sat May 11, 2019 2:02 pm

I know using GOTO/GOSUB is frowned upon in BBC BASIC, but I was surprised to learn that it didn't (seem to) support non-numeric labels.

Richard, is the sparse "remove unused line numbers" format you use in BBCSDL also used in BBC BASIC V and later on RISC OS? It looks very similar to good ol' FORTRAN-77:

Code: Select all

      REM TEDIOUS SIEVE OF ERATOSTHENES - SCRUSS - 2018-09
      INPUT "MAX VALUE "; N
      DIM P(N)
      FOR J = 2 TO N
      LET P(J) = 1
      NEXT J
      LET M = SQR(N)
      LET I = 2
   90 FOR J = I * I TO N STEP I
      LET P(J) = 0
      NEXT J
  120 LET I = I + 1
      IF I > M THEN GOTO 160
      IF P(I) = 0 THEN GOTO 120
      GOTO 90
  160 PRINT "PRIMES <= "; N
      PRINT "=============="
      LET K = 0
      FOR J = 2 TO N
      IF P(J) = 1 THEN PRINT J,: LET K = K + 1
      NEXT J
      PRINT
      PRINT "COUNT OF PRIMES <= "; N; ": "; K
      END
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sat May 11, 2019 7:03 pm

scruss wrote:
Sat May 11, 2019 2:02 pm
I know using GOTO/GOSUB is frowned upon in BBC BASIC, but I was surprised to learn that it didn't (seem to) support non-numeric labels.
BBC BASIC for WIndows and BBC BASIC for SDL 2.0 do support non-numeric labels, the syntax is that the label is enclosed in parentheses:

Code: Select all

      loop = 1000
      (again)
      loop -= 1
      IF loop <> 0 THEN GOTO again
      END
However the labels share the same namespace as regular variables (indeed they are variables) so that may require some care to be taken. Older versions of BBC BASIC don't support labels, but as you say the use of GOTO and GOSUB is deprecated.
Richard, is the sparse "remove unused line numbers" format you use in BBCSDL also used in BBC BASIC V and later on RISC OS?
I'm by no means an expert on RISC OS (ARM) BASIC, but I'm reasonably sure that at run-time it will be happy for only those lines that are referenced from GOTO, GOSUB or RESTORE to have numbers. But of course the console-style program entry and editing mechanism requires lines to be numbered irrespective of the run-time behaviour.

Heater
Posts: 13283
Joined: Tue Jul 17, 2012 3:02 pm

Re: Introduction to BBC BASIC

Sat May 11, 2019 7:26 pm

RichardRussell,
BBC BASIC for WIndows and BBC BASIC for SDL 2.0 do support non-numeric labels, the syntax is that the label is enclosed in parentheses:
That is possibly the most bizarre programming language specification I have ever seen.

Do you have any recollection of the reasoning behind that?

User avatar
John_Spikowski
Posts: 1384
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Introduction to BBC BASIC

Sat May 11, 2019 7:35 pm

The only time I use ScriptBasic's line number emulation is with ported old BASIC code that used them.

When I use labels they are in the form of:

Error_Trap:

ON ERROR GOTO Error_Trap

ScriptBasic allows reusing label names as long as they are not in the same scope. (same label name used in two different functions is fine)

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sat May 11, 2019 8:38 pm

Heater wrote:
Sat May 11, 2019 7:26 pm
That is possibly the most bizarre programming language specification I have ever seen.
Why? It was based on Liberty BASIC's label syntax:

Code: Select all

     ' Liberty BASIC
     repeats = 1000
     [again]
     repeats = repeats - 1
     if repeats <> 0 then goto [again]
     end
  
I couldn't copy Liberty BASIC's syntax exactly because square brackets are already used in BBC BASIC (they delimit assembler code) so I made it as similar as I could by replacing the square brackets with parentheses. It seemed to me then, and it still does now, that basing the syntax on one of the most popular 'modern' BASICs was sensible. Do you disagree?

Heater
Posts: 13283
Joined: Tue Jul 17, 2012 3:02 pm

Re: Introduction to BBC BASIC

Sat May 11, 2019 9:09 pm

RichardRussell,
Why? It was based on Liberty BASIC's label syntax:
You say that as if "Liberty BASIC" was something anyone had ever heard of.
It seemed to me then, and it still does now, that basing the syntax on one of the most popular 'modern' BASICs was sensible.
Is that really so?

I have been keeping an eye on all things personal computing since ever there were such things. Never heard of "Liberty BASIC" until someone mentioned it recently in the "avoiding BASIC" thread.

Liberty BASIC is not open source and not free. There is no liberty about it. It has totally the wrong name. But I digress.
Do you disagree?
Of course.

If a design feature of anything is silly it is no defense to say "That's the way that guy makes it"

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sat May 11, 2019 9:27 pm

Heater wrote:
Sat May 11, 2019 9:09 pm
You say that as if "Liberty BASIC" was something anyone had ever heard of.
Anybody here will have heard of it, anyway, because Carl (its author) announced the release of the Raspberry Pi version only recently in this very board! It's a popular BASIC in the US, I understand.
Liberty BASIC is not open source and not free.
Judging by its logo (a flaming torch) Liberty BASIC's name is based on the Statue of Liberty rather than any claim to be free or open source. BBC BASIC for Windows isn't free or open source either. Being paid-for but at the same time popular probably means both products are rather good! ;)
If a design feature of anything is silly it is no defense to say "That's the way that guy makes it"
Asserting that something is silly doesn't make it so. I have been writing software since 1970, and programming in BASIC since around 1980, and nothing about either Liberty BASIC's or BBC BASIC's label syntax strikes me as "silly". I did consider other syntaxes, such as following the label with a colon (like assembler labels) but that conflicted with the use of colon as a statement separator. I'm sure you won't have forgotten my obsessive desire to preserve compatibility!

Heater
Posts: 13283
Joined: Tue Jul 17, 2012 3:02 pm

Re: Introduction to BBC BASIC

Sat May 11, 2019 9:51 pm

RichardRussell,
Anybody here will have heard of it, anyway, because Carl (its author) announced the release of the Raspberry Pi version only recently in this very board!
Perhaps that is where I first heard of it. I think I questioned the name in that very thread.
It's a popular BASIC in the US, I understand.
Many unhealthy things are popular in the US.
Judging by its logo (a flaming torch) Liberty BASIC's name is based on the Statue of Liberty rather than any claim to be free or open source.
Interesting. I see no such logo on the Liberty BASIC landing page. http://www.libertybasic.com/
I do see a VISA logo though.
Asserting that something is silly doesn't make it so.
Of course it does. When I am making the assertion :)

I do appreciate the backwards compatibility idea.

On the other hand, backwards compatibility can lead to the madness that is C++.

I can't help thinking that at some point it's time to stop remodeling the house, adding windows, balconies, bathrooms, an extra floor, here and there.

Tear it down and start again with a new architecture that scales to what you want to do.

hippy
Posts: 5942
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Introduction to BBC BASIC

Sat May 11, 2019 10:55 pm

Heater wrote:
Sat May 11, 2019 9:09 pm
I have been keeping an eye on all things personal computing since ever there were such things. Never heard of "Liberty BASIC" until someone mentioned it recently in the "avoiding BASIC" thread.
You said you had not heard of PowerBasic either so I am not convinced you have actually been keeping an eye on things at all.

I was trying to remember where I first saw square brackets used to enclose labels but can't. I thought it might be Pilot or SNOBOL, but no. Probably something less well known or more esoteric, but likely from the 70's. Ada uses double chevrons <<label>>.

I have used square brackets, chevrons and other symbols to indicate labels in languages I have invented to get things done over the years. It's easier to parse and syntax check when the prefix identifies the token type it is rather than have to look ahead. It also avoids the whole issue of whether an alphanumeric is a label or the name of a procedure to be defined later which is to be called when that's allowed.

Plus it allows reserved words to be used as labels, and bracketing allows embedded spaces and non-alphanumeric symbols, all of which can be useful at times.

Single characters prefixes can be used for label definitions; eg : in Batch files, but where it's a bracket it makes sense to include the closing bracket for aesthetic reasons. Whether a GOTO or GOSUB needs to include the decoration, already knowing a label must follow, is equally a matter of aesthetics and preference, and whether a variable can be used as well as a literal label. Which can also influence how a label must be.

But I would guess, as it usually is, it's was more a case of "how do I crowbar that into the rest of what I have?" and that was an easy solution, and good enough.

User avatar
John_Spikowski
Posts: 1384
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: Introduction to BBC BASIC

Sun May 12, 2019 1:07 am

I commend Richard for going multi-platform and opening up the source. It's still based on a retro BASIC and that is going to be a problem going forward. Most kids these days don't even know what DOS is at least in the states.

There is a big difference between retro and traditional BASIC. Fortunately ScriptBasic is able to put on its retro clothes when needed.

User avatar
bensimmo
Posts: 4175
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Introduction to BBC BASIC

Sun May 12, 2019 7:53 am

...

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sun May 12, 2019 11:08 am

I mentioned in the other thread that I was thinking of writing a native code BigInt library for BBC BASIC; it would be an interesting exercise and hopefully provide a route to an efficient solution of the Fibonacci challenge. I've started to look at this, but I'm facing a dilemma: should I use a 10^n radix for the limbs (as the classic BASIC Fibo program does) or a more conventional 2^n radix? The advantage of the former is that the conversion back from the BigInt to decimal becomes trivial (and fast) which is of particular value when outputting a million-digit result! The disadvantage - and it's a big one - is that the BigInt computations themselves become significantly less efficient.

For a general-purpose BigInt library I'm in little doubt that the 2^n limb radix is better. In a typical application the formatting of the output as a decimal number is likely to be a small proportion of the total work (it might not even always be needed, if the output value isn't intended for 'human consumption') and efficiency of the BigInt arithmetic will be the most important factor (GMP uses a 2^n radix incidentally). But I suspect that in the specific case of the million-digit Fibonacci challenge it would give poor results because of the time taken to convert the result to decimal (which I assume is supposed to be part of the challenge).

What to do?! Does anybody have some BASIC code for multiple-precision binary-to-decimal conversion that I could benchmark?

hippy
Posts: 5942
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Introduction to BBC BASIC

Sun May 12, 2019 12:16 pm

RichardRussell wrote:
Sun May 12, 2019 11:08 am
I'm facing a dilemma: should I use a 10^n radix for the limbs (as the classic BASIC Fibo program does) or a more conventional 2^n radix?
I would argue that, as so few people need bigints in the real world, it doesn't matter which you use so you might as well go for the simplest to implement; 10^n.

I would even argue that so few need them that it's not even worth wasting time or resources on implementing them, other than for the personal fun which might be had in doing that.

Let's be honest, when hasn't 32-bit 4294967295, or 64-bit 18446744073709551615, been enough ? When have you ever needed to use an integer greater than that other than in artificial circumstances such as calculating a million digit Fibonacci sequence which no one has any actual use for once done.

I will however admit it could be very useful for counting how many angels are dancing on a pin head.

Heater
Posts: 13283
Joined: Tue Jul 17, 2012 3:02 pm

Re: Introduction to BBC BASIC

Sun May 12, 2019 12:33 pm

In the real world people use cryptography all the time. Modern cryptography makes use of huge integers.

Now, it's generally recommended that people don't implement there own cryptographic software and systems. There are so many ways to mess it up unwittingly and end up with an insecure system. But if one want's to learn about and experiment with such algorithms big integer support would be nice.

A million digits may be something of an overkill but, hey, if you are going ti do a thing might as well do it properly.

I'm wondering why Richard want's to write his own big maths. BBC BASIC uses SDL for graphics, why not use a known working big int library like GMP for the maths?

jahboater
Posts: 4675
Joined: Wed Feb 04, 2015 6:38 pm

Re: Introduction to BBC BASIC

Sun May 12, 2019 12:34 pm

Other languages just call the GMP routines (which include a fibo function). They have been very widely used, over a long time, and on many platforms. They have been heavily optimized by experts.
There is also a comprehensive floating-point library MPFR that does arbitrary precision floating-point with IEEE semantics.

Its a lot of work to re-invent the wheel and produce something that is bound to be inferior.

Unless the fun of implementing it is the main point!

With GCC (C and C++ anyway) you have direct access to the carry bit (that is it doesn't store the bit in a separate integer which you later have to test, instead it uses the bit directly with "add with carry" or "jump if carry" instructions) so 2^n limbs might be very fast.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sun May 12, 2019 12:48 pm

hippy wrote:
Sun May 12, 2019 12:16 pm
I would argue that, as so few people need bigints in the real world, it doesn't matter which you use so you might as well go for the simplest to implement; 10^n.
There's no satisfaction to be gained from writing a "simple" library! The whole purpose of the exercise is to leverage the features of BBC BASIC to gain a performance benefit - something that I am uniquely qualified to achieve - not to take generic bigint code and translate it to BBC BASIC; anybody could do that. Here for example is the work-in-progress addition code that I've been experimenting with:

Code: Select all

      DEF FNbigadd(a%%(), b%%(), c%%())
      LOCAL F%,N%,d%%() : N% = DIM(a%%(),1) : DIM d%%(N%)
      c%%() = a%%() : d%%() = b%%()
      REPEAT c%%() += d%%()
        F% OR= FNbigcarry(c%%(),d%%(),N%)
      UNTIL SUM(d%%()) = 0
      = F%
Let's be honest, when hasn't 32-bit 4294967295, or 64-bit 18446744073709551615, been enough ?
Simple answer to that: cryptography. Not that anybody is seriously likely to be using BBC BASIC for that application, but it's a major and growing field and somebody wanting to dabble is going to need bigints. Even something as straightforward as a 256-bit hash, which is a reasonable requirement in a BASIC program, would benefit.

Another factor: Liberty BASIC has bigints (as standard). It's the one major incompatibility between the original Liberty BASIC (coded in SmallTalk) and my LB clone 'LB Booster' (coded in BBC BASIC). A BBC BASIC bigint library would provide a solution for those who would like to use LBB but are currently unable to because of that limitation.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sun May 12, 2019 1:02 pm

Heater wrote:
Sun May 12, 2019 12:33 pm
I'm wondering why Richard want's to write his own big maths. BBC BASIC uses SDL for graphics, why not use a known working big int library like GMP for the maths?
Apart from the reasons I explained in the other thread (it's a challenge and can showcase the capabilities of one's favourite BASIC dialect) there's the issue of cross-platform compatibility. BBC BASIC will run on Windows, MacOS, Linux, Raspberry Pi, Android and iOS, and programs written with care will run on all those platforms with no modifications.

As soon as you introduce a dependency on an external library like GMP that compatibility is sacrificed, unless I ship (or link) a compiled GMP binary (for the appropriate architecture) with each of those editions of BBC BASIC. I expect I could do that but it would add bloat and the problem is solved more elegantly by writing a native library.

jahboater
Posts: 4675
Joined: Wed Feb 04, 2015 6:38 pm

Re: Introduction to BBC BASIC

Sun May 12, 2019 1:18 pm

RichardRussell wrote:
Sun May 12, 2019 1:02 pm
it's a challenge and can showcase the capabilities of one's favourite BASIC dialect
I applaud this.

Too often I see people claiming language A is so much better than an old language B, and yet the translator and run-time library for language A is mostly written in language B.
If language A needs to use another language for its heavy lifting, then it doesn't inspire confidence.

Well done!

Having said that, I think GMP has been fairly widely ported, at least as much as GCC has been, and likely more.
Compile time arithmetic for GCC is done with GMP/MPFR to very high precision.

GCC handles the library by a script called "download_prerequisites" which is run after the source tree has been unzipped.
GMP and MPFR then get built within the GCC build.

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sun May 12, 2019 1:39 pm

jahboater wrote:
Sun May 12, 2019 1:18 pm
If language A needs to use another language for its heavy lifting, it doesn't inspire confidence.
Indeed. I don't take it to extremes such as implementing graphics primitives in BBC BASIC (that would hardly be sensible with an interpreted language!) so of course I use off-the-shelf libraries for several things (SDL2_gfx, SDL2_ttf, SDL2_net, SDL2_stbimage notably). But if speed is not critical - and I appreciate that it could be in cryptography - and it's practical to code the functionality in native BBC BASIC code I prefer to.

If you know the language inside-out like I do there are often big wins to be made by using 'novel' techniques, and in a library I don't mind if the code is unreadable so long as it works. There was a famous occasion when I managed to achieve a multi-orders-of-magnitude speedup by leveraging BBC BASIC's dot-product operator, something that I suspect most people don't know exists or wouldn't know how to use.

I've mentioned before that the two IDEs supplied with BBC BASIC are themselves entirely BASIC programs - quite big ones - and hopefully they act as a good demonstration of what can be achieved. Compiled languages often compile themselves; BBC BASIC can't do that but implementing the IDE in native code is the next best thing.

User avatar
rpdom
Posts: 15180
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Introduction to BBC BASIC

Sun May 12, 2019 1:49 pm

RichardRussell wrote:
Sun May 12, 2019 1:02 pm
BBC BASIC will run on Windows, MacOS, Linux, Raspberry Pi, Android and iOS
The first three and last two are Operating Systems. The fourth is hardware. The Pi can run several Operating Systems, including many versions of the previously mentioned Linux OS, also Windows 10 IoT and RISC OS. I'd hazard a guess that since RISC OS already has a BBC BASIC you haven't ported to that platform. Does it run on Win IoT?

User avatar
RichardRussell
Posts: 578
Joined: Thu Jun 21, 2012 10:48 am

Re: Introduction to BBC BASIC

Sun May 12, 2019 2:07 pm

rpdom wrote:
Sun May 12, 2019 1:49 pm
The first three and last two are Operating Systems. The fourth is hardware.
The point is that these are the available, pre-compiled, editions of BBC BASIC for SDL 2.0. You're quite right that it would be more accurate to call it the Raspbian edition (to distinguish it from the x86 Linux editions) but the typical 'man in the street' probably wouldn't recognise that as meaning the Raspberry Pi.

Steve Drain
Posts: 105
Joined: Tue Oct 30, 2012 2:08 pm
Location: Exeter UK

Re: Introduction to BBC BASIC

Sun May 12, 2019 2:13 pm

RichardRussell wrote:
Sun May 12, 2019 11:08 am
I'm facing a dilemma: should I use a 10^n radix for the limbs (as the classic BASIC Fibo program does) or a more conventional 2^n radix?
A long time ago, it seems, in the original topic, I had go at this using RISC OS BBC BASIC. I used 10^n radix and BASIC VI float arrays that could exploit the ARM VFP. Optimising/delaying the carry resolution was quite important. Even so, the million digit fibo was achingly slow. As there is a bignum module and SWIs available I ran with that in my submission.

Return to “Other programming languages”