Websela

Smalltalk-72 Interpreter

Posted on: September 10, 2013

st72screen2

http://osrcon.ca/Squeak3.2.zip

http://www.squeakland.org/

http://wiki.squeak.org/squeak/989

At the Toronto Smalltalk Users Group last night I presented on the article The Early History Of Smalltalk by Alan Kay. You can Google it or buy a beautiful copy from the Digital Library at the ACM.

My intent was to see what Smalltalk was like without a compiler,  image, browser, or byte codes. The problem I’ve been facing for years is to look at the vm or byte codes or a CompiledMethod and not be able to look past the immediate context of what I’m looking at to see how it relates to other parts of the system.

I was intrigued by the part of the story where Dan Ingalls implemented the first interpreter in a Data General Nova in BASIC to make 3+4 tally. I thought why not do this in BASH? I found the St-72 simulator Dan made for the 3.2 image and that idea was quickly put aside. You can download the image above. You’ll need to use a vm from Squeakland. Then just read the instructions in the Transcript window.

Smalltalk-72 is very different from Smalltalk as we know it. It has no utility and is some kind of semiotics engine. The objective was to build better children with this medium of computing. Alan Kay talks about how he was influenced by Piaget, Bruner, and Papert. He’s not fooling around here. The difference between Smalltalk-72 and Smalltalk-76 cannot be overstated. If Dan Ingalls had not refused to “burn the disk packs” at the three day retreat in Pajaro Dunes in late January 1976, then you would never have heard of Smalltalk.  They went separate ways. Alan started work on NoteTaker. Dan came up with a new version of Smalltalk with byte level implementation that ran x180 faster and did work you as a programmer could appreciate. Alan came around when he saw the new system seven months later.

Even still, Smalltalk-72 is a blast. You can see the REPL from Lisp directly when you type “show ev” and it produces (repeat(cr read eval print)). That looks a lot to me like Interpreter>>#interpret. And Smalltalk-72 fits my agenda of wanting to see the interpreter in a simple, whole form that I can explore. All the pieces of future implementations are there in embryo. It’s great to be able to comprehend the whole system in the palm of my hand and then map it onto future evolutions.

Basically, you have an array called a vector that acts as the message stream. Vector understands the message eval. I won’t put the hash mark in front – # – because that wasn’t in use yet. At that time they used the “eyeball” or Celsius degree sign. So eval wound not be #eval but ˚eval. Get it? Eyeball. You send a message to vector and it “looks” to see if it understands that message. If it does then ˚eval would return true. True is the receiver of the new  message which is sent >> which is an if/than conditional. If the answer is true, then you execute the content in the vector (i.e. the selector in the compiled method) of this object. If the answer is false then it falls through and looks a the next selector token. It looks like this:

stScreen3

The object read has a message “of”. If ˚of evaluates to true, then the if/than conditional ˚>> will execute the code in the vector (:str. CODE 2). If the eyeball did not see the selector token name, then it returns false and the vector is passed over to check the next selector token. It helps to have a copy of the Smalltalk-72 Instruction Manual pdf, which isn’t hard to find.

Interestingly, David C. Smith of Croquet fame did his doctoral thesis at Stanford on Smalltalk-72 and “iconic programming”. He wrote a twenty page program called Pygmalion in 1975.

The Early History Of Smalltalk is a great read and the Smalltalk-72 interpreter is fun. It sort of makes you feel like a kid, which I suspect is its point. I mean, if you spend your time working on a system for children, then isn’t that a way of reminding yourself what it was like to be a child, because that’s a place you want to be?

At any rate, if the virtual machine is completely incomprehensible to you as it is to me, then the place to start is the interpreter. And a simple interpreter in the the Smalltalk-72 interpreter described in Appendix II of Alan’s article is a great place to start. The 60s live.

“Computer power to the people! Down with the cybercrud!”

Advertisements

8 Responses to "Smalltalk-72 Interpreter"

The Smalltalk-72 equivalent of # would be the hand symbol with the pointing finger. The closest we have to the eye symbol in modern Smalltalks is the method peekFor: (in PositionableStream, for example).

The Smalltalk-72 is extremely clever and tricky, so it might not be the best example for someone who is starting out. The problem is that there are two or more pieces of code, each with its separate program counter and context, being evaluated at any instant. This is what gives the language its unique programmable syntax. Smalltalk-76 might be simpler to understand because it has a single level of interpretation. While a modern Smalltalk VM might not be very approachable, the various versions of Little Smalltalk are a good starting point.

Wow, great stuff, Jecel. Thanks you for adding brush strokes to the picture. I wasn’t quite sure what the hand symbol was for. I figured it was for creating a variable. And I hadn’t heard of Little Smalltalk. A little Googling has turned up some interesting things.

That that the Little Smalltalk described in the book (freely available in Stef’s site) has some very interesting differences from Smalltalk-80. But in version 3 it is very similar to Smalltalk-76 (no metaclasses) and in version 4 it is just a very simple Smalltalk-80.

The hand in Smalltalk-72 is like ‘name or (QUOTE name) in Lisp. While Alan loved the idea of Lisp, he hated that they could only get it to work by introducing the notion of FEXPRs which didn’t evaluate its arguments. Without that, you couldn’t write:

(define fact (n) (cond….))

but would instead have to do:

(define ‘fact ‘(n) ‘(cond….))

So in Smalltalk-72 he created two separate ways to get arguments: the normal colon would evaluate the next expression in the message stream and assign it to the name right after it while the open colon would fetch the next item from the message stream and assign it as is to the name.

If the message stream is pointing to something like

….. (3 + 4) ….

and the class code is pointing to something like

… :val ….

then 7 will be assigned to the name “val”. But if it were an open colon instead (can’t type that in ASCII, and I might have gotten the two mixed up since it has been a while since I last looked at this) then the actual vector object with the three tokens “3”, “+” and “4” will get assigned to “val”.

This evolved to selector names with closed and open colons in Smalltalk-76 and then to the current block definition in Smalltalk-80 (or was it in -78?).

“Note that”, I meant to write instead of “That that”.

One interesting detail is that all this colon stuff came from Logo. While in Lisp you either have ‘x or just x, Logo introduced 😡 as a shorthand for (THING ‘x) meaning fetch the value associated with the name “x”. When defining a new function, the declaration syntax showed the intended usage:

to spiral :angle :size :steps

This was also the syntax used to define classes in Smalltalk-72 with the addition of a vertical bar to separate the instance variables from the temporary variables in the class code. Even after all the changes on the way to Smalltalk-80 we still have a left over of that syntax in blocks:

[ :angle : size : steps | ….. ]

Stupid emoticons. Logo introduced :a as a shorthand for (THING “a)

Oh, OK. When you put it like that, I see the blocks influenced by LOGO more clearly.

I’m glad to get more about FEXPRs and the example is very valuable. I read around the problem and learned about Ken Pitman writing a paper (“Special Forms In Lisp”, 1980) that began their removal and replacement with macros.

The : and open-colon are interesting. The colon in the := comes from Algol, I suspect. The :n way of writing a variable shows up a lot in St-72. I think it lives in what I call the block assignment operator [: which executes the following and assigns it to the block. When you say the colon in :n comes from Logo, I see it now.

I think the >> came from IMP (see Irons, “Experience With An Extensible Language”, 1970 available from the ACM). It was a right arrow that was a true/false test (:n=0) >> (1) (n-1). This would say (pg. 536 of “The Early History Of Smallalk” available from the ACM) if n equals 0 then return 1 if not then return n-1.

The interesting thing is that it was also used for testing if a method was present in a class ˚isPair >> (SELF mprint). I thought >> was just a polite notation used by Smalltalkers to reference a method (i.e. MyClass>>#someMethod), but it’s still in the system at Behavior>>#>> and does one of it’s old jobs from the past by answering true/false whether a class has a given method. Behavior>>#foo throws an error. Behavior>>#allCallsOn does not. That part still works. Cool stuff.

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

%d bloggers like this: