No Pascal, not a SNOBOL’s chance. Go Forth!

My article on Fortran, This is Not Your Father’s FORTRAN, brought back a lot of memories about the language. It also reminded me of other languages from my time at college and shortly thereafter, say pre-1978.

At that time there were the three original languages – FORTRAN, LISP, and COBOL. These originals are still used although none make the lists of popular languages. I never did any COBOL but did some work with Pascal, Forth, and SNOBOL which are from that era. Of those, SNOBOL quickly faded but the others are still around. SNOBOL was a text processing language that basically lost out to AWK, PERL, and regular expressions. Given how cryptic regular expressions are it’s amazing another language from that time, APL – A Programming Language, didn’t survive. APL was referred to as a ‘write only language’ because it was often easier to simply rewrite a piece of code than to debug it.

Another language deserving mention is Algol, if only because Pascal is a descendant, along with many modern languages. Algol was always more popular outside the US, probably because everyone there stuck with FORTRAN.

Back then certain books held iconic status, much like [McCracken’s] black FORTRAN IV. In the early 70s, mentioning [Nicolas Wirth] or the yellow book brought to mind Pascal. Similarly, [Griswold, (R. E.)] was SNOBOL and a green book. For some reason, [Griswold’s] two co-authors never were mentioned, unlike the later duo of [Kernighan] & [Ritchie] with their white “The C Programming Language”. Seeing that book years later on an Italian coworker’s bookshelf translated to Italian gave my mind a minor boggling. Join me for a walk down the memory lane that got our programming world to where it is today.

Pascal

pascal bookThe creator of Pascal, [Nicholas Wirth], was something of an iconoclast of his times. Pascal was a rebellion against Algol 60, which he felt was overly complicated and not useful for real work. I’d love to hear his opinion of Java and C++. Working without the constraints of a standards committee he pared Algol down to the bones to create Pascal.

[Wirth] was a hacker at heart:

Every single project was primarily a learning experiment. One learns best when inventing. Only by actually doing a development project can I gain enough familiarity with the intrinsic difficulties and enough confidence that the inherent details can be mastered. – From Programming Language Design To Computer Construction, Niklaus Wirth 1984 ACM A.M. Turing Award Recipient Lecture.

The language was so compact it was completely described and defined in a 58 page book, almost a pamphlet. This included showing it in Backus-Naur Form, and a novel graphic representation that became known as railroad diagrams. Being visually oriented I really liked that representation.

pascal rr diagram

An interesting feature is Pascal was bootstrapped into existence. A bootstrapped language’s compiler is written in itself, using the smallest subset possible. That compiler is then hand written in another language, probably Fortran for that time frame. Once the hand written compiler works you can feed its executable the compiler code written in the new language. Out comes an executable that will now compile itself. From there you can write the additional features in the language itself. Bootstrapping was a boon for computer science students as it provided them with a working compiler they could extend and hack but was still small enough to comprehend.

Pascal was a one pass compiler while almost all other languages make multiple passes through the code or intermediate outputs. This made compilation fast. A drawback was it didn’t provide much optimization.

Some Pascal code:

program ArithFunc;
  const
    Sentinel =0.0;
  var
    X:Real;
begin    
   writeln('After each line enter a real number or 0.0 to stop');
   writeln;
   writeln('X', 'Trunc(x)' :16, 'Round(X)' :10, 'Abs(X)' :10,
           'Sqr(X)' :10, 'Sqrt(Abs(X))' :15); 
   readln (X);
   while X <> Sentinel do
     begin
       writeln (Trunc(X) :17, Round(X) :10, Abs(X) :10:2, 
                 Sqr(x) :10:2, Sqrt(Abs(X)) :10:2);
       readln(X);
     end
end.

You can see the relationship of Pascal to current languages like C, C++, and Java, all derived from versions of Algol. One of the big complaints about Pascal is it didn’t use semi-colons enough. You can see in the example there is no semicolon prior to the final end. Another characteristic is the keywords begin and end marked blocks of code, where in today’s languages we use braces.

Pascal is still in use, having gained widespread popularity with the advent of the PC. The first PC compiler used UCSD Pascal P-code, an interpreter engine much like today’s Java. P-code was developed to allow easy porting of the language to new machines, the virtual machine being easier to write than a compiler.

The big boom for Pascal on the PC was the release of Borland’s Turbo Pascal (TP) in 1983. It was cheap so hackers could afford it and it had an integrated programming toolkit, what we’d today call an IDE.

I lay claim to using TP for an early, if not first, industrial usage. A team I led developed the software for an Intel 8088 based flow computer, i.e. an embedded system used to measure the flow in pipelines of gas or liquids. I developed an IDE using TP that generated bytecodes that were downloaded to the flow computer. The remainder of the team developed the flow computer software which included an interpreter for the bytecodes. The system was basically Lotus 1-2-3 – Excel for you youngsters – for pipelines since end users could develop their own code.

Turbo Pascal added object oriented features in the ’90s and finally morphed into Delphi.

SNOBOL

snobol coverSNOBOL was used for processing text and symbols. The name really isn’t meaningful, although some tried to shoehorn acronyms and portmanteaus. Griswold and others were sitting around talking about the name, shooting rubber bands, when they decided they “…didn’t have a snowball’s chance in hell in finding a name.” They shortened ‘snow’ and substituted ‘BOL’, which was the ending for many languages of that time.

(Rubber bands were used on card decks so shooting them was a favorite nerd pastime back then. I shot a cigarette out of a young ladies’ lips with a rubber band once. I was good!)

Here is some code to give you a sense of the language:

           OUTPUT = "What is your name?"
           Username = INPUT
           Username "J"                                             :S(LOVE)
           Username "K"                                             :S(HATE)
 MEH       OUTPUT = "Hi, " Username                                 :(END)
 LOVE      OUTPUT = "How nice to meet you, " Username               :(END)
 HATE      OUTPUT = "Oh. It's you, " Username
 END

Like many langauges of the time SNOBOL used a single line card format with a special flag character allowing continuation onto other cards. The first field was a destination label. The middle field contained the programming statements. The right most field, following a ‘:’, was test and jump.

The OUTPUT and INPUT lines are fairly obvious as is the assignment. After the assignment are two lines that perform a pattern match to see if the letters ‘J’ or ‘K’ are in Username. If the letters appear the line succeeds. On success, flagged by the ‘S‘ in the test field, a jump is made to the destination label. You could also ‘F‘ail, do both, or just jump, as shown by the jump to END in the code.

SNOBOL did all the text manipulation you would expect: concatenation, replacement, extraction, etc. It also did the usual math operations.

It was an interesting language to play with; very easy to understand and work with.

Forth

Forth is an intriguing language in multiple ways. It came neither from the computer industry nor academia. [Chuck Moore] developed it working a number of jobs but it came to fruition at the National Radio Astronomy Observatory developing embedded systems for the Kitt Peak observatory. From the start, Forth was meant to be portable. When [Chuck] changed jobs he wanted to take his toolkit along.

Forth is a threaded language. In our more traditional languages code is translated into a sequence of real or virtual machine opcodes. The machine then steps through the op-codes. In a threaded language only primitive operations are coded as opcodes. In Forth these primitives are the basic words of the language. All other defined words are built on the primitives.

Instead of opcodes a threaded language stores the address of the word. An inner interpreter in Forth steps through this list of addresses. If the address is that of a primitive word the opcodes are executed. When it is a defined word the inner interpreter jumps to that sequence and begins walking its list of addresses. A word at the end of a sequence causes a return to the previous word definition. The process is straightforward and surprisingly fast. It also makes threaded languages very portable. Once the primitives and the inner interpreter are created Forth is pretty much up and running. All the rest of the language is based on defined words.

An outer interpreter provides the user interface. You simply type in words and they are executed. There are words that allow you to define new words which are added to the dictionary. Revising code when working at the user interface is easy: you just enter the word definition again. The new definition overrides the older definition.

A compilation process walks through the dictionary selecting only the words actually used by other words, strips out all the parts needed for interactive processing, and creates a ‘binary’ containing the primitive and defined words that are needed. This, like the execution speed, is a surprisingly compact representation often smaller than standard compiled code.

Forth is like a giant hand-held calculator from Hewlett Packard: it uses a stack and reverse Polish notation (RPN). To add two numbers you’d enter: 2 3 +. This would push the 2 and 3 onto a stack. The + would pop them and add them leaving the resultant, 5, on the stack. While you can define variables most operations are done using the stack.

Here’s a Forth word definition and example usage for squaring a number:

> : sqr dup * ;
> 2 sqr .
4
> 3 sqr .
9

A word definition starts with the colon. The first token after that is the name. It can be anything! Forth often defines some numbers as words because it is actually faster to load the value from a word than convert it. If you want to drive someone nuts you can define 2 as 1 by entering “: 2 1 ;”.

Continuing with the example, the word dup creates a copy of the top of the stack and the ‘*’ multiplies the top two values leaving the resultant on the stack. In the lines where sqr is used the ‘.’ prints the top of the stack and removes the value.

You can try Forth using an online interpreter.

Back in the days of computers using CPM as the OS I wrote a text editor using Forth. The editor allowed the use of cursor keys, delete, insert, etc. It took only an hour. My introduction to Forth was at the University of Rochester Laboratory for Laser Energetics. Forth was used to develop the control system for the large laser fusion experiment they were undertaking. I even went to Manhattan Beach, CA for training at the Forth, Inc. offices. The second Forth programmer in the world, Elizabeth Rather, was my instructor.

Forth is still being used in aerospace and commercial applications.

I suggested in the Fortran article that someone create a FortDuino. I can’t make the same suggestion for Forth since it already exists in multiple incarnations. Besides, that would be fairly easy. It’s what Forth is meant to do. A larger challenge is a PiForth, or ForthPi, running as the operating systems loaded from the SD card. We’ve seen a Lisp version so how about Forth? Now that would be interesting.

Wrap Up

I hope you’ve enjoyed these two articles that walked through some history of programming languages from my personal experience. It was fun to bring back the memories and refresh the details by searching the web. The relationships among languages are fascinating, which reminds me of one last story.

The University of Rochester’s computer center, by some quirk, was in the basement of a Holiday Inn on the campus. Jean Sammet, another of the famous ladies in computing history, stayed at the Inn for an ACM conference. She commented that her sleep was disturbed because she kept dreaming of line printers for some strange reason. Nobody had the heart to tell her they may have been right under her room. I recalled this story because one of Jean’s books included a chart of programming language ancestry similar to the chart in the above link.

45 thoughts on “No Pascal, not a SNOBOL’s chance. Go Forth!

    1. Also: if you are interested in Pascal, check out Lazarus, which is an IDE for FreePascal. Available for multiple platforms, but compiles native code to run on a target. It actually functions quite a bit like Visual Basic and seems like it could make a neat replacement. Playing with the language a bit, I can definitely understand how it became the “teaching language” of its day.

      1. Yes, I quite like Free Pascal / Lazarus.
        Of course Object Pascal is still alive and well, as implemented by Free Pascal / Lazarus project, and Delphi (http://www.embarcadero.com/products/delphi). I understand that Skype was originally written in Delphi (i.e. a dialect of Object Pascal), before it was bought out by M$, and that part of the Skype core still is.
        Turbo Pascal (from which Delphi descended) is now in the public domain, and can be download from a link on this page http://edn.embarcadero.com/article/20803

        1. What I mean is, it’s useful for rapid prototyping of GUI applications, in that you can draw buttons on the screen wherever you want, add a few lines to a subroutine, and it Just Works. The unfortunate thing about VB is that too many of those “prototypes” became production software!

      1. Well, on paper god wrote in LISP but most of it was hacked together with perl http://xkcd.com/224/ :-) This is a freaky column, very personal to me; Griswold was the first CS prof here at the UA (He developed ICON, the successor to SNOBOL here), and Kitt Peak is where my dad worked for about 25 years.

        Also I still have my UCSD-Pascal didsks and book for the Apple II around here somehwere..

  1. Fortran was the first language I used back in the 70th… Because I was curious, I grabbed the Algol and Cobol manuals to learn a bit of them, but unfortunately, our IBM 360 didn’t have the compiler installed… (and of course it was very busy to compute important things, like geodetic networks…). I found Cobol far too verbose, but Algol very interesting and clever.
    After that we all learned PL/1, which was at the same time wonderful and awful (pointer bugs are always interesting in their effects, like a program crashing only with some data and very far from the faulty line) . You should write about this one !
    I use a bit of Pascal but didn’t like his lack of consistence (where shall you put the semicolon : a source of errors for all the students we have).
    I fell in love with Forth, because it worked like my HP calculator, and was free to put on my first personal computer (in fact a 6502 dev board, where it can easily fit in the few KB of memory available !)

  2. Pascal was my first “real” language, after BASIC, and I’m still using it today for hobby projects (with FPC/Lazarus). It is a fine language that unfortunately fell from grace, although it’s still being developed and stands up to modern standards.

    COBOL I learned a little at highschool (I think it was dropped from the curriculum a year or two afterwards). That was not a pleasant experience :-)

  3. I learned APL, COBOL and Pascal (and other languages) in business school in the late ’70s and early ’80s. Always hated APL and never put it on my resume. I made a good career of COBOL, CICS, Easytrieve, IBM Assembler and a couple of minor things from ’85 – 2001. After Y2K I was burnt out and will probably never write another line of code.
    I liked COBOL because it was so explicit. Most business programming isn’t writing programs, it’s reading them. And no matter how hurried or dunderheaded the author of a COBOL program was, you could always figure out what the thing was doing and fix it. You can’t say that about a lot of languages. Wordy, yes, but all those words had a valid purpose

  4. In the early days I owned a ZX-81 (with only 1k of memory). Some English company devised an EPROM to be installed and it ran fully multithreaded and real-time forth. I still have it, with hacks and all.

      1. I realise this topic is a year old –

        It was ZX ROM Forth by David Husband – I have a slight reworked version on my Github – but the Z80 source code h4th is still out there

        I bought the ROM with a friend in my 1st year at university, and immediately copied it in the engineering departments eprom programmer – not something I’d do these days ;)

        https://github.com/monsonite/Z80_Forth

        Original

        http://sinclairzxworld.com/viewtopic.php?t=459 Available as a zip

        There’s a pdf manual too if you look for it.

  5. I’d done a fair amount of Pascal work in college, always preferring it to C, and my first post-collegiate job used VAXen with their BASIC and Pascal languages which seemed to be on a crash course to become Bascal or PASIC (lots of string handling operators added to Pascal which never made its way into C at the time, and program structure elements added to BASIC).

    I’d also bought an original Mac which arrived after I graduated (they told me never to come back for support at the student center). Aside from $50/10 floppies and no hard drive in 1984, the other challenge was programming, as Apple wanted you to use a Lisa. I went through a lot of crappy compilers, most of which went belly-up within six months and never survived long enough to provide an update for new OS calls. One of these is the (ahem) beloved Turbo Pascal. I had found bugs in the compiler, and needed updates… but the support guy said, “We sold 30,000, and found 60,000 in use, so we stopped selling it.”

    One of the relief valves for that was a MacForth environment, which essentially worked as an interpretive assembler. This worked mainly because of the 68000’s stack orientation — it would have been much harder on an x86. After creating a Forth “word”, it could be displayed as machine code… which worked wonderfully as INLINE items added to Turbo Pascal.

  6. Great – Hackaday has mentioned Forth, which gives me an opportunity to plug my DIY Forth based retro 8-bit computer: FIGnition (which has been featured on Hackaday a couple of times)!

    FIGnition runs a version of Token Forth, from 8Kb or 32Kb of external Serial RAM, which means you can write more significant programs than if it used the AVR’s internal SRAM :-) It outputs to a TV has its own keypad for programming and its Flash firmware includes the entire language – it’s completely self-contained :-D It supports a full 160×160 bitmapped frame buffer with a simple 166KPixels/s blitter and can get up to 400Kips of Forth performance :-)

    I still have one left in my current stock, but people in Europe can order them via RS Components.

  7. I remember our first class on PC’s in college was DOS and Assembler. We spent hours coding Assembly to display “Hello World” only to crash the 8088 and have to boot from single sided 5 and 1/4s, which took forever. Did FORTIV for a traffic engineering internship (yep traffic control – lol). Started using FORTVII and Pascal when I started working. Stuck with Deplhi for quite a while, much to my colleages dismay. Thanks for the write up! Brought back fond memories.

  8. Actually had to write a lot of PL/1 code for a year or two. Glad to have nearly forgotten that time period :)…. Wrote a hard drive head actuator control program using turbo pascal, but far prefer C/C++ these days!!!

  9. Great article and a lovely walk down memory lane. Started programming on BASIC and Pascal. Swore I’d never use COBOL and spent 15 years programming in it. Now it’s JavaScript and PHP but I still have fond remembrances of Pascal.

    1. John Warnoch used be quite adamant about having never seen Forth. It was also always hard to believe given he was in Mountain View/Palo Alto, the Forth Interest Group (FIG) met publicly in the area, the early Atari arcade machines were Forth, etc, etc.

      A Son of Forth is Open Firmware/Open Boot from SUN and used in the pre-Intel Apples – you can enter the Forth interpreter on those Macs. Created by Mitch Bradley IIRC. The latest descendant is Device Tree in new Linux kernels.

  10. COBOL, Fortran, Pascal … I think we have covered the 1870’s – 80’s

    I really miss those “rail road” diagrams for syntax explanation. So so easy to follow. I wish there was one for VHDL!

    The last time I saw one of these was here – http://json.org/ and that says it all – one page to describe a whole protocol!

    The other thing I miss is the old style circuit diagrams where every connection was a line (or bus) and not just a label. The really old analog diagrams had the lines drawn at approximations by height on the page as to there DC voltage.

  11. The description of SNOBOL doesn’t really do it the injustice it deserved. The pattern matching operators were very elaborate, similar to modern Perl in complexity but different. The lack of structured programming constructs such as looping constructs was probably more what killed it than any specific competitors. If conditional branch and pattern matching operators are your only control constructs, then all code is spaghetti. SNOBOL was an interesting disaster. To be fair, in its day, not everyone understood just how important structured programming would become.

    The Icon programming language was a successor designed by Prof. Griswold’s son if i recall correctly, but I don’t believe it every gained enough traction to displace anything. Icon was pretty interesting in its support for coroutines and generators. I’m reminded more of Icon when I program in Python than SNOBOL.

  12. Back in the 80s and early 90s just about everyone learnt pascal at college but it went downhill as it was rubbish for internet development and only focussed on DOS/Windows32, the slide got worse after the disaster that was Delphi 8 and when the lead programmer jumped ship to write C# for Microsoft

    Luckily those days are long gone, though nowhere near as popular, Delphi is now quite solid and multi-platform (but $$$) and the latest Lazarus IDE is just plain awesome and has surpassed Delphi in my humble opinion, it’s a really nice example of open source in action.

    I for one cannot see a reason to change, however I do run my own business so don’t have the pressure of the job market and up to date CV to worry about :-)

  13. Better keep an eye on OBERON! Oberon is quite amazing. Think “highly refined/compact Pascal”, among much more.
    Did you realize the Professor Wirth is still “at it”? Yes… You need to take a close look at what he has “been up to”…

    ProjectOberon.com

    and also check out Astrobe.com , the Oberon IDE for microcontroller targets (plus the “soft core” FPGA RISC5 implementation of ProjectOberon)

    Or how about just go directly to Professor Wirth’s personal website?

    https://www.inf.ethz.ch/personal/wirth/

    Prepare to be mind boggled.

  14. I was taught FORTH by Marc DeGroot and Michael Perry (who wrote a definitive version of F83). The FORTH ran on a small embedded board. This was at a startup called Ono-Sendai. I had one of the oddest experiences of my life because of FORTH. This was in 1993

    I had to write some C code one night. I had been writing C since 1978, so roughly 15 years. I had been doing FORTH almost exclusively for a year.

    I *could not* think in C – I could only think in FORTH. I had to specifically and deliberately swap out the FORTH in my brain, and swap in the C part, before I could think in C. I wrote the C I needed to, then deliberately reverse the process so I could think in FORTH again.

    It took about 30 minutes each time of intense concentration to swap between languages. No drugs, just Dr Pepper and candy.

  15. I liked this article, and the earlier one about Fortran. I have only one critique, to your remark “Pascal was a rebellion against Algol 60, which he felt was overly complicated and not useful for real work.” I think you really meant it was a rebellion against Algol 68, the official successor to Algol 60. In Wirth’s Turing lecture, he mentions this split of the group that was trying to design the successor to Algol 60, and says he was in the subgroup that was trying to extend Algol 60. You are correct that he did want to simplify it in certain ways, such as substituting call by reference for call by name.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s