tenochtitlanuk
Posts: 156
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

BBC BASIC & Rosetta Code

Fri Nov 09, 2012 1:57 pm

I'm thoroughly enjoying the ROOL RISCOS release on my Pi.
It's great as a result to have access to the included BASIC. I've enjoyed getting into Python; played happily with seven year olds in Scratch; but still find BASIC more natural. Perhaps 'cos I've used it for so long...
If anyone is looking for interesting projects to try coding in BASIC, Rosetta Code ( http://rosettacode.org/wiki/Category:BBC_BASIC ) is worth visiting. Several hundred coding tasks, implemented in a huge range of languages, and therefore helpful for people who may know one but be trying another.
Just be aware that Rosetta Code 'BBC BASIC' solutions MAY not run in Pi RISCOS without small changes, since some have been developed in the extended BBC Basic for Windows or Brandy BASIC, etc. ( rather in the way that Python 3 does things sometimes in different ways to 2.7)

If anyone notices such an incompatibility, either join Rosetta Code as an editing member ( when you will be able to add a second Pi-specific version, or add a comment saying something like 'this line needs changing to ..... on Pi BASIC) OR e-mail me & I'll do it.

NigelJK
Posts: 65
Joined: Wed Sep 05, 2012 1:44 pm

Re: BBC BASIC & Rosetta Code

Fri Nov 09, 2012 4:09 pm

My researches and test of my own code suggest that over 95% of all code written for BBCBasic VI (The version that first came with the Archimedes) will run without alteration. Earlier code should also work as that implementation of BBCBasic was an augmented one from the one that came with the BBC Master.

I've visit the site as it sounds intriguing.

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

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 11:54 am

Actually it's BBC BASIC 5 rather than 6 that first came with the Archimedes. If there is such a thing as 'BBC BASIC VI' it will be BASIC64, the version adapted to use 64-bit 'doubles' for its floating-point operations rather than the 40-bit floats supported in earlier versions of BBC BASIC. What version comes with RISC OS on the Pi, 40-bit or 64-bit?

sawdust
Posts: 40
Joined: Fri Jul 27, 2012 7:09 am

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 2:39 pm

Basic V in the ROM image with soft loadable Basic VI (Basic64) on the disc image as has the case for years.

Sawdust

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

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 3:09 pm

Why isn't BASIC64 the default ('ROM') version on a machine with FP hardware? Presumably memory usage is a little greater, with floats needing 8 bytes each rather than 5, but are there any other reasons? Is the 64-bit version fully up-to-date with the later features such as DIM LOCAL?

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

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 3:45 pm

RichardRussell wrote:Why isn't BASIC64 the default ('ROM') version on a machine with FP hardware? Presumably memory usage is a little greater, with floats needing 8 bytes each rather than 5, but are there any other reasons? Is the 64-bit version fully up-to-date with the later features such as DIM LOCAL?
Presumably because no-one has had the time to do the necessary work. It would happen automatically if the FPE coding were converted seemlessly to use the new FP hardware, but I think that is a major task.

BASIC VI uses identical syntax to BASIC V, so apart from a handful of minor bugs, if the BASIC V version has a feature such as DIM LOCAL so does BASIC VI. The ROOL versions have this one.

tenochtitlanuk
Posts: 156
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 5:59 pm

Two observations.
1 Rosetta Code uses the section title BBC BASIC, but many examples use bb4w-specific code. This could potentially confuse & put people off Pi's BBC BASIC, 'tho I appreciate it often shows really neat aspects of bb4w.
2 More of a problem is that code copy/pasted from Rosetta Code viewed with NetSurf HAS to be first search/replaced, since many of the spaces are changed to hard-spaces. A typical example had 420 hard-spaces & they cause BASIC to barf badly.

I don't know a good answer to prevent confusion. I suppose I could go through all the examples & note those which need modifying for PI. I don't have the time.
It doesn't seem sensible to add 'Pi BASIC' as a new language & start from scratch, & that isn't the implementation's official name anyway.

sawdust
Posts: 40
Joined: Fri Jul 27, 2012 7:09 am

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 6:20 pm

tenochtitlanuk wrote:Two observations.
1 Rosetta Code uses the section title BBC BASIC, but many examples use bb4w-specific code. This could potentially confuse & put people off Pi's BBC BASIC, 'tho I appreciate it often shows really neat aspects of bb4w.
2 More of a problem is that code copy/pasted from Rosetta Code viewed with NetSurf HAS to be first search/replaced, since many of the spaces are changed to hard-spaces. A typical example had 420 hard-spaces & they cause BASIC to barf badly.

I don't know a good answer to prevent confusion. I suppose I could go through all the examples & note those which need modifying for PI. I don't have the time.
It doesn't seem sensible to add 'Pi BASIC' as a new language & start from scratch, & that isn't the implementation's official name anyway.
BBC Basic V and VI are the last official versions supplied with BBC branded Acorn computers. Any BB4W extensions used in Rosetta code make them non-BBC Basic and it is those examples that should be labelled as something other than BBC Basic!

Sawdust.

swirlythingy
Posts: 11
Joined: Sun Nov 04, 2012 12:27 pm

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 9:50 pm

tenochtitlanuk wrote:2 More of a problem is that code copy/pasted from Rosetta Code viewed with NetSurf HAS to be first search/replaced, since many of the spaces are changed to hard-spaces. A typical example had 420 hard-spaces & they cause BASIC to barf badly.
This 'feature' has been fixed in the current development versions of NetSurf. (The version on the ROOL disc image is the so-called 'stable' version, but IME 'stable' software has a tendency to have more bugs, as well as fewer features, than cutting-edge software. NetSurf is far from the only program with this problem.)

You can download NetSurf built from the latest git sources here:

http://ci.netsurf-browser.org/

Another advantage is that the newer versions will display the raspberrypi.org homepage properly!

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

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 11:31 pm

sawdust wrote: BBC Basic V and VI are the last official versions supplied with BBC branded Acorn computers. Any BB4W extensions used in Rosetta code make them non-BBC Basic and it is those examples that should be labelled as something other than BBC Basic!
Sawdust.
I am sure Richard will have something to say about that! AFAIK he wrote the original specification and has the rights on all machines except RISC OS.

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

Re: BBC BASIC & Rosetta Code

Sat Nov 10, 2012 11:49 pm

Any BB4W extensions used in Rosetta code make them non-BBC Basic and it is those examples that should be labelled as something other than BBC Basic!
Completely untrue. The 'Wilson' and 'Russell' branches of BBC BASIC are equally deserving of being called BBC BASIC! The specification was after all developed jointly by Acorn and the BBC, and neither party has an exclusive claim to be the custodian of the language. I even have formal written permission from the BBC to call my products 'BBC BASIC'.

It is a great shame that, despite the ongoing efforts by the likes of Jonathan Harston, ARM BBC BASIC still lags so far behind the specification of BB4W. As far as Rosetta Code tasks are concerned a large number simply could not be solved in ARM BASIC or Brandy.

The BBC BASIC solutions (over 440 at the last count) basically divide into three main categories:
  • 1. Those that use 'generic' BBC BASIC code and should run OK on BB4W, ARM BASIC and Brandy. Inevitably not all have been tested on all three platforms so there may be a few examples where they don't run, but in such cases it should be easy to correct them.

    2. Those that are marked 'Works in BBC BASIC for Windows' but could be modified to work in the other dialects without too much difficulty. Typically they use the line-continuation character to improve layout (RC doesn't like very long lines) or the EXIT statement (can usually be fudged in ARM BASIC with a GOTO or a conditional block) or 'byte' variables (could be changed to integers) etc.

    3. Those marked 'Works in BBC BASIC for Windows' but which cannot realistically be adapted to work in the other versions. Typically they use structures, or function pointers, or event interrupts etc.
.
Richard.

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

Re: BBC BASIC & Rosetta Code

Sun Nov 11, 2012 10:49 am

RichardRussell wrote: It is a great shame that, despite the ongoing efforts by the likes of Jonathan Harston, ARM BBC BASIC still lags so far behind the specification of BB4W. As far as Rosetta Code tasks are concerned a large number simply could not be solved in ARM BASIC or Brandy.

The BBC BASIC solutions (over 440 at the last count) basically divide into three main categories:
  • 1. Those that use 'generic' BBC BASIC code and should run OK on BB4W, ARM BASIC and Brandy. Inevitably not all have been tested on all three platforms so there may be a few examples where they don't run, but in such cases it should be easy to correct them.

    2. Those that are marked 'Works in BBC BASIC for Windows' but could be modified to work in the other dialects without too much difficulty. Typically they use the line-continuation character to improve layout (RC doesn't like very long lines) or the EXIT statement (can usually be fudged in ARM BASIC with a GOTO or a conditional block) or 'byte' variables (could be changed to integers) etc.

    3. Those marked 'Works in BBC BASIC for Windows' but which cannot realistically be adapted to work in the other versions. Typically they use structures, or function pointers, or event interrupts etc.
.
Richard.
You have missed a category:

4. Those that can be adapted to work with ARM BASIC with Basalt extensions.

I have had a look at a handful of them, and those involving pointers can work much the same way. EXIT is a Basalt keyword. Structures are more tricky, but most can be simulated with indirected variables, but it does get very ugly. There is more than one structures library which could be used. Wait until I get bored with the Pi and there will be structures in Basalt. :) I have not seen a Rosetta task using interrupts yet - could you suggest one?

Basalt is 'BASic ALTernative keywords', a module that works alongside the ARM BASIC module to provide many extra features.

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

Re: BBC BASIC & Rosetta Code

Sun Nov 11, 2012 5:38 pm

You have missed a category:
4. Those that can be adapted to work with ARM BASIC with Basalt extensions.
I simplified the list in other ways too. For example those solutions that can be adapted to run under Brandy but not ARM BASIC (e.g. because of the use of long strings) or ARM BASIC but not Brandy (e,g, because of the use of assembler code).

As you know I am well aware of Basalt, and as a way of extending ARM BASIC without actually modifying the existing interpreter it is very clever. But I do rather feel that, with the availability of the source of ARM BASIC,editing the interpreter itself is a more flexible approach (especially considering that Jonathan Harston has made some progress with this). I think you would concede that the way Basalt 'hooks into' the interpreter does impose some restrictions, such as being able to add new statements but not new functions.

Some respects in which Rosetta Code tasks cannot be solved in ARM BASIC or Brandy are as follows:
  • 1. Tasks which require First Class Function behaviour, e.g. being able to pass a function as a parameter, or create a new function at run-time. BB4W can do that by using function pointers and indirect function calls.

    2. Tasks which require Object Oriented behaviour. They are usually soluble in BB4W using the OO extensions in the CLASSLIB library (which also relies on function pointers and indirect calls).

    3. Tasks which require concurrency, which can often be solved in BB4W using timer interrupts.
I wonder if you feel it would be appropriate to add 'ARM BASIC + Basalt' as another BBC BASIC 'implementation' on Rosetta Code. If you were to do that it would allow you to add Basalt-specific solutions with an appropriate 'Works with' tag.

Richard.

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

Re: BBC BASIC & Rosetta Code

Sun Nov 11, 2012 5:54 pm

I have not seen a Rosetta task using interrupts yet - could you suggest one?
These BB4W solutions use timer interrupts:
http://rosettacode.org/wiki/Atomic_updates#BBC_BASIC
http://rosettacode.org/wiki/Events#BBC_BASIC
http://rosettacode.org/wiki/Metered_con ... #BBC_BASIC

Richard.

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

Re: BBC BASIC & Rosetta Code

Sun Nov 11, 2012 8:56 pm

RichardRussell wrote: As you know I am well aware of Basalt, and as a way of extending ARM BASIC without actually modifying the existing interpreter it is very clever.
But ...
To be brief, Basalt has dozens of function keywords. It has pointers to user-defined functions, although not as well integrated as BB4W. It has OOP for desktop tasks using the Toolbox. RISC OS has events and inter-task messages in the desktop which does much of the job of concurrency; Basalt can set up callbacks with the CALL function. The current version can deal with strings of any length.

It would be fun to go through the Rosetta tasks to see what could be done, but time is short.

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

Re: BBC BASIC & Rosetta Code

Sun Nov 11, 2012 11:06 pm

To be brief, Basalt has dozens of function keywords
I guess that's one of the main reasons why I'm not enthusiastic about it. One of the great strengths of BBC BASIC is that it isn't bloated like so many BASIC dialects are; only the essential and most commonly used functions are built into the core language. Everything else is done via libraries, which you can choose to install or not - I sometimes describe BBC BASIC as the 'C' of the BASIC world! That way 'compiled' executables (and of course that is my main interest) are as small and fast as possible - considering that the language is interpreted.

I presume that with Basalt it's 'all or nothing' - you can't be selective as to which extensions to have and which not to have. That's probably fine in a RISC OS environment, but if one were to consider how to port the concept to Windows every program which used just a single Basalt feature would need the entirety of Basalt to be included in the 'compiled' EXE. That goes against everything I've strived for in developing BB4W (for example the run-time-engine hasn't increased in size at all for more than 25 releases over 7 years - I've always managed to squeeze in the enhancements for no overall extra bytes).

I have every respect for your technical achievements in Basalt, but it's taking BBC BASIC in a very different direction to that which I have been following, and goes against the philosophy of BBC BASIC as a 'lean and mean' language which I feel so strongly about and which I think was shared by Sophie all those years ago.

Richard.

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

Re: BBC BASIC & Rosetta Code

Tue Nov 13, 2012 1:35 pm

RichardRussell wrote: I have every respect for your technical achievements in Basalt, but it's taking BBC BASIC in a very different direction to that which I have been following, and goes against the philosophy of BBC BASIC as a 'lean and mean' language which I feel so strongly about and which I think was shared by Sophie all those years ago.
AFAIUI BB4W produces a runtime containing only those bits of the interpreter and libraries required to run the program, making it 'lean and mean'. However, if your machine had many BASIC programs running, as with RISC OS, that could result in duplication, making it less 'lean'.

Basalt is a shared resource and there is only ever one copy of the module present. As a result programs can be quite small; a typical desktop patience game is 6k of code. A keyword written in machine code can be an order of magnitude or more faster and smaller than the equivalent BASIC code, so Basalt, too, is 'lean and mean'.

We have the same aims, but different paths.

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

Re: BBC BASIC & Rosetta Code

Wed Nov 14, 2012 10:54 pm

A keyword written in machine code can be an order of magnitude or more faster and smaller than the equivalent BASIC code
Faster I would of course believe, but smaller? In my experience tokenised and crunched BASIC code is usually more compact than the equivalent machine code. But either way I don't think it has much relevance to the current discussion because BB4W libraries are commonly partly or mostly assembler code as well.

To bring this back on topic the number of Rosetta Code tasks solved in BBC BASIC is now in excess of 450, and should shortly overtake the current leading BASIC dialect - PureBASIC. I particularly enjoyed coding the 'QR Decomposition' task because the built-in array/matrix arithmetic allowed an elegant translation of the mathematics into BBC BASIC:

http://rosettacode.org/wiki/QR_decomposition#BBC_BASIC

Richard.

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

Re: BBC BASIC & Rosetta Code

Wed Nov 14, 2012 11:24 pm

RichardRussell wrote:
A keyword written in machine code can be an order of magnitude or more faster and smaller than the equivalent BASIC code
Faster I would of course believe, but smaller? In my experience tokenised and crunched BASIC code is usually more compact than the equivalent machine code.
You might replace a routine written in BASIC to do a particular job, say make a string uppercase, with a single keyword written in machine code and achieve such an increase in speed and saving of code. You cannot count the keyword code, because that is a shared resource. However, if you write a specific machine code routine within your program, then the size will quite possibly not be reduced.
To bring this back on topic the number of Rosetta Code tasks solved in BBC BASIC is now in excess of 450, and should shortly overtake the current leading BASIC dialect - PureBASIC. I particularly enjoyed coding the 'QR Decomposition' task because the built-in array/matrix arithmetic allowed an elegant translation of the mathematics into BBC BASIC
I wish I had the time to get involved with this, too.

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

Re: BBC BASIC & Rosetta Code

Thu Nov 15, 2012 11:41 am

You cannot count the keyword code, because that is a shared resource
To create a 'shared resource' in Windows one would have to make it a DLL. From time to time I've been asked whether it would be possible to compile BBC BASIC code to a DLL, but it would be difficult to meet the requirement of being thread-safe.

Richard.

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

Re: BBC BASIC & Rosetta Code

Thu Nov 15, 2012 12:57 pm

RichardRussell wrote:To create a 'shared resource' in Windows one would have to make it a DLL.
It is quite possible to make BASIC libraries a shared resource for any BASIC program in RISC OS. I wrote a module[1] to support that way back in the mists of time, but it was taken up by only a handful of programmers, who have left the scene now. Mainly, developers include libraries within their applications, which means much duplication, or they do something similar to BB4W and extract and crunch a runtime. This still leads to more bulky programs than I prefer. But memory is cheap ... :(
[1] Basil - BASIC Shared Installed Libraries

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

Re: BBC BASIC & Rosetta Code

Thu Nov 15, 2012 11:29 pm

Mainly, developers include libraries within their applications
That's not necessarily such a bad idea, because it guarantees that the version of the library used by the application is the one with which it was developed and tested. On the other hand it means that if a bug in a library has subsequently been fixed the application won't benefit from it. There is no 'correct' answer.

Of course in a Windows environment it's unlikely that there would be two (or more) 'compiled' BBC BASIC applications running at the same time. Even if there were, and they happened to be using the same library, there would be no way of guaranteeing which copy was the most recent nor that it hadn't been 'customised' for some special purpose. So the only safe thing is for each application to use its own library.

Richard.

Return to “RISCOS”