I'm releasing a FOCAL interpreter

I’ve released a 1.0 version of RetroFOCAL, an interpreter for the FOCAL language written in yacc/lex/c that should compile on practically anything. It comes with a makefile and an Xcode project for those on macOS.

It has some remaining bugaboos in the number formatting and a couple of missing features - see the TODO - but it does what I was aiming for: runs Lunar Lander and Hamurabi and mostly likely any other FOCAL code you’ll find online.

You can find it here: GitHub - maurymarkowitz/RetroFOCAL: FOCAL interpreter in lex/yacc/c

7 Likes

Neat! I’d used Dave Pitts’ interpreter before - David Pitts' Home Page - which almost but not quite made it into the Debian distribution.

Yeah, I was using his version to test my number formatting. Both his and mine are different from the canonical output of Lunar Lander on Jim’s page, and annoyingly, both are different in different ways.

I also found that his doesn’t seem to properly parse the YES or NO at the end of LL, but that might be because I’m on macOS and not Linux. I’ll debug it at some point.

FOCAL was only used for a short time from 1968 until the early 1970s

It was available on the Soviet BK-0010 machines.

Some models had it available rigt in the ROM, so you just turned on the machine, and got to Focal editor.

3 Likes

FOCAL was only used for a short time from 1968 until the early 1970s

No, I do not think so.

I really wonder why, but after more than 40 years I exactly remember the title of an article in a German computer magazine, called mc, in issues 3 and 4/1981, author Hans-Georg Joepgen, title “Focal auf dem Vormarsch”. The article talks about Focal-65, apparently it had just been ported to a 6502 processor.

I found a scan here: [mc-1981-04 : Franzis Verlag : Free Download, Borrow, and Streaming : Internet Archive]

Maybe Germany was again eleven years behind?

1 Like

I briefly played with FOCAL when I was tinkering with PDP-8 stuff a few years back… It was interesting but not interesting enough for me to prefer it over BASIC.

Reading the wikipedia article on it now, it seems to suggest that had DEC licensed it - or given it away then it may have supplanted BASIC in some areas. Hindsight is a great thing though…

That article suggests there was (is?) and 8080 version, and I think that Implementing it on a modern system ought to be relatively easy, even on an older micro like the 6502 - bearing in-mind that the originals were all written in assembly language… (Do I want to? Not really!)

-Gordon

1 Like

Like Drogon, I also played with FOCAL a little while back. I looked into the PDP-8 emulator on an Arduino Mega (https://github.com/KedalionDaimon/DEC-PDP-8-on-Arduino,) and that had the original DEC FOCAL interpreter preloaded. It was pretty cool, playing with it, but like Drogon it wasn’t enough to replace my BASIC work.

The emulator is pretty cool, and running it on an Arduino is cheap enough to try out, just for fun. There is a nice video of it on YouTube (DEC PDP-8 on Arduino Mega 2560 & Arduino DUE, 4K running FOCAL 69 - YouTube)

Not to detract from @MauryMarkowitz’s announcement of a new portable FOCAL, I followed up on the idea of a 6502 FOCAL, and found @HansOtten’s pages on FOCAL for the KIM-1 - the Aresto version, not the previously mentioned Programming Group version.

Hans has a number of resources on his site here, including reconstructed sources:

Including a link to the origin story of this implementation:

Wayne now turned his attention to a high level language. The Intel based microprocessors had a version of BASIC written by Microsoft. Wayne decided that we should have a similar language, and he chose to write a version of the DEC language called FOCAL. Even though it was a relatively obscure language, FOCAL had some subtle advantages over BASIC, the biggest was its ability to evaluate strings as expressions.

Wayne wanted FOCAL to be a group project, and one evening he showed up with a stack of photocopies of the DEC flowcharts for the language. His plan was to assign each section of the chart to one of the 6502 Group members. We were supposed to go home, write 6502 assembly code for the section, and in a few weeks, we’d have an operating version of FOCAL. Unfortunately, Wayne had overestimated our skills. Most of us had been assembling code by hand and had no idea how to work from a flow chart. In the end, Wayne and Bob Ulshafer did most of the coding.

When it was finally finished, FOCAL was a big breakthrough. Suddenly we had a true programming language. Complex new games began to appear on our computers including a version of the famous mainframe game Star Trek, written by Larry Fish. Over the next few weeks Wayne wrote a five-byte floating point package for FOCAL based on a Dr. Dobbs article. With the new floating point power, simulations and mathematical programs sprouted up everywhere.

I see an offer to scan some source printouts, from Nigel Williams on the classiccmp mail list, but I also see that his domain has expired recently, which isn’t a good sign, and makes it difficult to contact him.

1 Like

Some machine translation from the mc article linked above:

…let’s close the general consideration of this latest version of Focal and turn to the concrete interpreter that you get for your 30 dollars. There are versions for the KIM and an Apple Version that we tested on an ITT - 2020. In addition, a version is offered for the TIM monitor, which is available as a tape for older PETs and is already installed in newer CBM machines.

A new Focal version for floppy disk operation has been announced: we bought the initially only available cassette version, so that Wayne Wall and his friends can’t be blamed for the floppy disk inconveniences: Nice that Focal is now compatible with DOS 3.2 at all! Incidentally, Don Marshai from the “6502 Program Exchange” proved to be helpful in integrating the interpreter into the floppy disk operating system — in two transatlantic telephone calls at night, Don was willing and committed to providing information on such questions, in which the (separately ordered) documentation materials |6; 7| leave the reader alone. Unfortunately, there are several such gaps in the documentation: nowhere is reference made to the convenient input options that the author discovered by accident: variables and expressions as an answer to “INQUIRY”. , that it uses an asterisk as its notification character - exactly the same character that the Apple monitor uses to announce that it is there.

1 Like

The history of FOCAL is interesting.

The language started at SRI in California in the early 1960s, as JOSS. The ideas that led to JOSS were that computers would use time sharing and offer direct interactivity with the user. Their programmers all used FORTRAN, so having a cleaned-up, interactive version of FORTRAN would be ideal.

This was, of course, exactly the same logic that led K&K to produce BASIC on the other coast. It is not surprising that JOSS and BASIC ended up being very similar indeed.

DEC comes into the picture in 1965, before either language was known outside their own communities. GE was supplying Dartmouth and thus started building out systems using BASIC as their primary programming system. Meanwhile, DEC sold one of its very few PDP-6’s to SRI where they learned of JOSS, and so they thought JOSS was going to be the next big thing.

Curiously, when DEC did finally decide to make their own “real” BASIC in the 1970s, they patterned it on the one from Tymshare, not the Dartmouth pattern. How that came about is a bit of history I have not been able to track down. Tymshare were the ones that introduced the MID/LEFT/RIGHT string functions, which are abysmal in performance and memory terms, whereas HP had already introduced the string-slicing commands and these were being widely used. Sadly, MS was seemingly unaware of any non-DEC dialects when they made their version, and the rest is history.

1 Like

The “strings as expressions” was actually sort of a side-effect in the parser. It simply sent anything that started with a zero, or any user input in ASK, into the decimal-to-binary number parser. Since the character set on the PDP-8 was six-bit and A was value 1, any character input was automatically treated as a numeric value and parsed as it if were a digit. Actual digits were character codes starting at 60, so basically >60 code-=60 and anything else goes right through. The result is a hash with collisions, but it is numeric.

It did work, in that it let the user type in something like “YES” and then you could see if they did that by comparing the numeric value to “0YES”, but this still strikes me as a hack. There were no string values, variables or functions, and all of that sort of thing had to be done numerically and character by character.

Note that Altair BASIC did include string support that we are all familiar with, and did so before this version of FOCAL seems to have been released. There’s no reason that they couldn’t have used the same FOCAL-like parser in a BASIC for almost no extra cost.

And I say this only because mostly every other feature in FOCAL is worse than BASIC. FOR loops only work on a single line, there’s no equivalent of NEXT. IF statements can only perform branches, not arbitrary code, so it’s total spaghetti. And the IF and FOR syntax is just FORTRAN’s, so is that middle one the step or the limit, and how do I test >0?

The one interesting thing from JOSS that survived is the line numbering scheme. Line numbers consist of two two-digit parts with a decimal, so in FOCAL it’s 01.01 to 31.99. The first part is the “group” and the latter it seems DEC never agreed on a name - I’ve seen line, specific line, statement number etc.

The reason I think this is cool is that when you look at FOCAL programs, they are invariably easier to read than the exact same code in BASIC. As you scan down the code you can immediately see the sections because they have different group numbers, whereas in BASIC it’s often just number after number with no pattern unless the programmer wanted that. So for instance, compare Lunar Lander in FOCAL and BASIC - the individual lines in FOCAL are hard to read, but the program as a whole is much more obvious in its layout.

2 Likes

The 0YES-style string(ish) decoding is a hack, sure enough, but programmers at the time might have been familiar with Fortran’s Hollerith constants: a very hacky, very official but word-length specific way of packing characters into machine words. It looks weird to us now, but one has to remember that when Focal came out, the idea of a character as an individually addressable thing was very new. It may have only come in with the IBM System/360 in 1965.

Contemporary Basic systems (including Dartmouth’s) didn’t have anything more refined than IF … GOTO, with THEN as a synonym for GOTO. Focal’s FOR can call a whole group, so was effectively multi-line. The three-term IF relative to zero was compact and familiar from Fortran, and DEC’s own Towers of Hanoi uses a familiar old Fortran trick to test >0 by testing the negative value:

01.47 ASK"AUTO#0, MANUAL#1 ? ",A,!
01.50 IF (-A) 5.1; …

(p.11.66, “Programming Languages”, PDP-8 Handbook Series, 1970: programmingLanguages_May70.pdf)

PDP-8 Focal increased overall legibility by emitting a blank line after every group. But inside each group, yecchhh! Shortening each of the 26-ish keywords to just one character made the language look like line noise. But hey, a typical tiny PDP-8 had roughly 700 words free for all of a user’s program.

To your earlier comment about Basic:

Tymshare were the ones that introduced the MID/LEFT/RIGHT string functions, which are abysmal in performance and memory terms …

Are they necessarily abysmal? They could be written as syntactic sugar for array slice functions, without a major performance penalty. There were extremely small numbers of people implementing these features, so it was more luck than merit that the “right” small group of people saw MID/LEFT/RIGHT and carried it forward. The rest were left to grumble on with string slicing and Betamax.

1 Like

My foggy and possibly flawed recollection is that MID$/LEFT$/RIGHT$/STR$/A$+B$ and even simple reassignment like A$=B$:A$=C$ inevitably led to performance killing temporary strings and garbage collection, at least in the MS versions of BASIC. Slicing didn’t suffer from the same maladies but required more careful planning by the programmer.

Reagarding the spread and use of FOCAL outside DEC, the Wikipedia article mentions 8080 FOCAL for the Altair. Besides this it had been available for the SOL, as well. Compare the brochure at https://www.sol20.org/articles/Sol20_SmallComputerSystems.pdf, esp. the section on software.

I guess, it must have been available on most S-100 computers. There’s a certain possibility for an alternative history, where FOCAL would have been what had been BASIC in our reality. What in turn poses the question, why was it BASIC and not FOCAL that became the predominant language on minis and micros, given the availability on DEC machines and S-100 machines quite early on, which should have provided FOCAL some of a head start? (Was it IBM being supportive of BASIC?)

While it’s true that any string operations result in temporary storage on the heap, this is not true for simple assignments.
For example, running this small program on a PET,

10 A$="A STRING"
20 B$=A$
RUN

results in the following variable allocation (mind that the BSIC text starts at $0401 and that $0409 points to the location of the string as a constant in the program text, line 10, and there’s no heap allocation at all), where A$ and B$ are pointing to the same memory location:

041F  41 80               A$
0421  08 09 04 00 00      len: 8, @ $0409
0426  42 80               B$
0428  08 09 04 00 00      len: 8, @ $0409

JOSS was done at RAND, running on the one-of-a-kind JOHNNIAC computer.

Here’s a 56 page intro and user guide from 1966

Which I assume is the MS version they subsequently lost the tape for.

I wasn’t going to hijack the thread, but oh well, the cat’s out of the bag.

Here’s someone else’s project to transcribe the JOSS listings, with an eye towards making an emulator: GitHub - sebras/JOSS-I: Recreational project to transcribe the JOSS-I listings for JOHNNIAC.

And similarly, transcribed listings for JOSS II, which ran on a PDP-6. Unfortunately, there are parts missing so it’s not possible to do a 100% faithful recreation. GitHub - sebras/JOSS-I: Recreational project to transcribe the JOSS-I listings for JOHNNIAC.

DEC picked up JOSS II and made their own version called AID. https://hopl.info/showlanguage.prx?exp=310 Maybe AID directly affected FOCAL?

1 Like

They did by the time FOCAL came out. These were introduced in the fourth version of Dartmouth, in early 1968.

Shortening each of the 26-ish keywords to just one character made the language look like line noise.

Which is the reason whenever the topic of PILOT comes up, I always wonder “what was he thinking?”

Are they necessarily abysmal? They could be written as syntactic sugar for array slice functions

Sure, you can fix any code. But they didn’t. They had the same problems on the Tymshare mainframes as they did in MS code. Of course on the mainframe, one imagines it would take a little longer to hit the memory limit that would cause an MS version to hit GC.

BTW, I talked to the primary author of Atari BASIC some time ago, and he mentioned that there was no reason they couldn’t have done this. But, like MS, they simply didn’t bother. This is what happened before we had the 'net to let people discuss these things!