## Coming soon: RISCYFORTH

When I was much younger FORTH fascinated me as an alternative interpreted language for the Z80 eight-bit processor machines I was typically using.

Compared to BASIC – the language that the Sinclair ZX80, ZX81 and Spectrum came with – FORTH was reputedly lightening fast and very powerful.

My brother and I even obtained a tape copy of somebody’s FORTH for the ZX80 and we ran it – and it certainly was fast. But it also lacked the simplicity of BASIC and the tape was soon handed back.

But I’m back on the case again, inspired by this (long out of print but widely available on the web) book – Threaded Interpretive Languages – and by the prospect of a single board RISC-V computer – the BeagleV – coming out this year.

Currently I am targeting the PK proxy kernel on the Spike Risc-V emulator for RISCYFORTH but if and when I get a real BeagleV I’ll immediately switch to that (I applied to be an early user but have heard nothing so while the signs are that the project itself is making good progress it looks like I’ll have to wait to get my hands on one.)

I struggled with getting the mechanics of RISCYFORTH right for a long time but in the last week I’ve finally started to make serious progress and it actually does things (only in immediate mode for now). The picture shows my very first success with a multi-token command line from a couple of evenings ago and it’s come on a fair bit since then.

It’s nowhere near a releasable state but it’s rapidly improving.

Why bother? Well I think it’s important that RISC-V succeeds as a disruptor of what is starting to look like an ARM monopoly and so contributing to the ecosystem of the first single board seriously affordable RISC-V device matters. And, of course, because it’s there.

Always yield to the hands-on imperative (from this classic).

Update: My brother actually thinks we borrowed somebody’s Jupiter Ace which was a Z80-based FORTH computer of a very similar size to a ZX81 – and I think he might be right.

## Still pondering over BASIC

Last month I put a bit of effort into fixing BINSIC – the collection of Groovy scripts that allows the execution of Sinclair ZX80/81 BASIC programs – and I have been thinking about the thing that they offer that modern computers don’t: the ability to switch on and just write a simple program to solve a problem.

The obvious thing to do would be a browser plug-in that replicates the straight-to-coding environment: particularly for Chromebooks and the like.

BASIC lacks expressive power but it is simple to use and would be a good choice, though I guess the line numbers abstraction would have to go.

## BINSIC – Sinclair BASIC emulator – is back

BINSIC was my 2012 project to emulate Sinclair ZX80/81 BASIC on a modern computer.

It is a series of Groovy classes that provide a mixture of interpretation and ‘domain specific language’ (i.e. executing BASIC as native Groovy).

Over the years bitrot seems to have set in and the code in the GitHub repo wouldn’t work and the BINSIC jar that would allow Java users to execute some BASIC without a Groovy install disappeared.

I have fixed all that now. You can see the Groovy at the GitHub BINSIC repo – and use that to explore or edit the code.

If you just want to cut to the chase then have a look here: http://n4decameron.org.uk/~adrian/

There you’ll find a jar and test.bas – an implementation of Conway’s Game of Life.

To run the code download both and execute:

java -jar binsic.jar test.bas

When the code starts specify filled cells with a character like ‘*’ and empty cells with a space. (You don’t have to fill in a whole line, but a blank line needs at least a single space.

When you have filled in the initial grid type ‘DONE’ and hit enter and the code should start – to advance through the generations hit enter.

Feel free to experiment with your own BASIC programs – I have copied a few from the classic BASIC Computer Games and they generally work – but I’ve not tried anything very long. All contributed programs would be gratefully accepted – happy to consider pull requests at the repo.

BASIC is out of fashion these days – but you can read about the motivation behind the project here.

## If only I had the time…

I would reimplement BINSIC using a JIT compiler as outlined in this rather good blog from Josh Haberman.

(And, at least now I have bumped Chomsky from the top of my blog.)

## Learnt this week… 24 January

My friend and former colleague Adam Higgitt every Friday posts a list of “five things I have learned this week”. It’s popular and good fun – especially as Adam is not afraid of an argument if you challenge some of his claims.

For a while I tried to do the same thing myself, but failed miserably.

I am not going to try again, but I am proposing to try something different, if inspired by Adam.

So here is the first list of things “learnt this week” scientific or mathematical facts and amusements. I will aim for five, but this week just did not make it.

1. A random walk can be used to build a binomial distribution – but not a very good one!

Imagine a left-right ruled line centred on zero and a marker than can, in every time step move either left or right be one step where the probability of moving left $p_l$ and of moving right, $p_r$ are both the same: i.e., $p_l = p_r = 0.5$. At the “beginning of time” the marker stands at 0.

Then if we count the times the marker is at any given position they will be distributed bionomially (well, as we approach an infinite time). The BASIC code below (which I wrote using BINSIC) should give you an idea (this code runs the risk of an overflow though, of course and the most interesting thing about it is how unlike a binomial distribution the results can be).

10 DIM A(1001)
12 FOR I = 1 TO 1001
14 LET A(I) = 0
16 NEXT I
20 LET POS = 500
30 FOR I = 1 TO 50000
40 LET X = RND * 2
50 IF X > 1 THEN LET POS = POS + 1 ELSE LET POS = POS - 1
60 LET A(POS) = A(POS) + 1
70 NEXT I
80 PRINT "*****BINOMIAL DISTRIBUTION*****"
90 FOR I = 1 TO 1001
95 LET X = I - 500
110 PRINT X," ",A(I)
120 NEXT I

Here’s a chart of the values generated by similar code (actually run for about 70,000 times):
2. Things that are isomorphic have a one-to-one relationship

Up to this point I just had an informal “things that look different but are related through a reversible transformation” idea in my head. But that’s not fully correct.

A simple example might be the logarithms. Every real number has a unique logarithm.

## A little plug for BINSIC

Thirty-three years ago my brother and I got a new cassette player for Christmas.

That allowed us to write and save games for our ZX80 computer (like many ZX80 owners we found that an older cassette player just didn’t work) and in 1981 I wrote a Z80 machine code version of Conway’s Game of Life – still my proudest programming achievement.

Last year I sought to complete the circle by writing an interpreter/DSL that mimiced ZX80 BASIC and called it BINSIC as “BINSIC Is Not Sinclair Instruction Code” and then wrote a BASIC version of the Game of Life (see the screenshot below).

So, if you are from that generation computer users, or even if you are not, why not give it a try – more details here: BINSIC

## Tiny BASIC for the Raspberry Pi

Only slightly miffed that no one seems to have noticed that I was running BASIC on this platform more than three months ago 🙂

## Getting booted from Wikipedia

A short article on “Binsic Is Not Sinclair Instruction Code” (BINSIC), my BASIC-like interpreter/DSL for Groovy faces getting deleted from Wikipedia on the grounds of lack-of-notability.

It would not be right or proper for me to intervene to stop this, but if you have been a BINSIC user then a proper third-party reference to it (followed by a clearance of the deletion message in the prescribed manner) would be very much appreciated.

The BINSIC article does not generate much traffic here (perhaps a visit a day), so I admit it is not a particularly important project in the world of computer science, but I hope it has been fun for at least a few people and it is worth keeping as a link to a quick and easy way to get BASIC on your computer.

## More than a game: the Game of Life

Conway’s Game of Life has long fascinated me. Thirty years ago I wrote some Z80 machine code to run it on a Sinclair ZX80 and when I wrote BINSIC, my reimplentation of Sinclair ZX81 BASIC, Life was the obvious choice for a demonstration piece of BASIC (and I had to rewrite it from scratch when I discovered that the version in Basic Computer Games was banjaxed).

But Life is much more than a game – it continues to be the foundation of ongoing research into computability and geometry – as the linked article in the New Scientist reports.

For me, it’s just fun though. When I wrote my first version of it back in 1981 I merely used the rubric in Basic Computer Games – there was no description of gliders or any of the other fascinating patterns that the game throws up – so in a sense I “discovered” them independently, with all the excitement that implies: it is certainly possible to spend hours typing in patterns to see what results they produce and to keep coming back for more.

• “Life.bas” should run on any system that will support the Java SDK – for instance it will run on a Raspberry Pi – follow the instructions on the BINSIC page. A more up to date version may be available in the Github repository at any given time (for instance, at the time of writing, the version in Git supports graphics plotting, the version in the JAR file on the server only supports text plotting). On the other hand, at any given time the version in Git may not work at all: thems the breaks. If you need assistance then just comment here or email me adrianmcmenamin at gmail.