Now Reading
Forth: The programming language that writes itself: The Internet Web page

Forth: The programming language that writes itself: The Internet Web page

2023-07-16 10:24:30


Forth: The programming language that writes itself: The Internet Web page









Charles H. Moore and the pursuit of simplicity.

drawing of chuck moore with his real head - with a scroll that says The Web Page Edition

Creator: Dave Gauer
Created: 2023-02-02
Up to date: 2023-07-16

Notice: This web page is my private journey to find Forth
and put it within the context of computing historical past.
It’s tailored from my
slides for a brief discuss.
I’ve completed every part in my energy to make this web page scale up and down
for numerous display sizes. I welcome options and corrections for
each the content material and show of this web page.
This is my
contact page.

After I was a wee programmer, I’d sit across the digital Usenet campfires listening
to the tall tales and legends of the elders.
usenet campfires on a desert scene: comp.lang.forth comp.lang.lisp and alt.religion.kibology

Within the Nineteen Nineties, Usenet
newsgroups
(wikipedia.org)
have been the place it was at.
For instance, Linus Torvalds’s preliminary announcement of Linux was to
comp.os.minix in 1991.

The comp.*
(wikipedia.org)
teams and notably comp.lang.* have been nice
locations to study and talk about programming.
By the point I obtained there within the late 90s, Perl was a reasonably sizzling matter,
particularly because it took a dominant position within the early Internet as the
dynamic web page and type processing programming language by way of
CGI
(wikipedia.org).

There have been programming sources on the Internet, however nothing like what’s
accessible now!
To really study to program, I purchased books,
and nonetheless do.

Usenet was the place the neighborhood and folklore lived.

(The “Easter egg” on this drawing is alt.faith.kibology, which ought to
get a chuckle from previous timers. The remainder of you’ll be able to look it up.)

I realized about magical languages with a number of (((((parenthesis))))).
third eye open to the y combinator

Sharp-eyed Lisp-lovers and different mutants will maybe acknowledge this factor
because the Y combinator expressed with lambdas.

The one time I understood this was once I accomplished
the e-book The Little Schemer by Friedman and Felliesen, which
walks you thru creating it for your self. It’s a magical e-book and
I implore you to strive it.

I listened, wide-eyed, to true tech tales like The Story of Mel (foldoc.org).
Royal McBee RPC-4000 computer drawing

Mel was actual and the Royal McBee RPC-4000 was actual. Have a look at that teletype
(aka “teleprinter”). If typewriters and “Royal” collectively make a little bit bell
in your head go “bing” as your psychological carriage hits the tip of the web page,
then you definitely’re proper: Royal McBee was a merger between the
Royal
Typewriter Company
(wikipedia.org) and McBee, a producer of accounting machines.

For some time, Royal was owned by the Italian typewriter firm, Olivetti,
who additionally made some really interesting computers (wikipedia.org).

After which…

I heard inform of a programming language so versatile that you possibly can
change the values of integers.


chuck moore as an adorable wizard

They mentioned that language was referred to as Forth and it was created
by a mad wizard referred to as Chuck Moore who may write any program in
a pair screens of code.

Years glided by and I wrote a whole lot of PHP and JavaScript.
I watched the Internet evolve (and generally de-evolve).

However I by no means forgot concerning the legend of Forth.

The weblog collection
“programming in the twenty-first century”
(prog21.dadgum.com)
by sport developer James Hague gave me the ultimate push.

He made Forth a recurring theme and it simply sounded so darned fascinating.

So I went on an journey and now that I’ve returned, I feel I’ve some
solutions.
a tired warrior returns from forth mountain

(Oh, and I confirmed the legend. I could make any integer
equal something I need. Stick round ’til the tip to see that Forth magic
trick.)


chuck moore as an adorable wizard


“Violà!”

hp-35 calculator with rpn syntax

At first, I believed this was what Forth was all about:

3 4 +
7
    

Now begins my quest to grasp Forth.

Maybe you have seen postfix or
Reverse Polish Notation (RPN)
(wikipedia.org)
earlier than? The precept is straightforward: As a substitute of the standard “infix” notation
which places operators between operands (3 + 4), RPN places
operators after the operands ( 3 4 +).

RPN notation is without doubt one of the most visually apparent
features of the Forth programming language. Nevertheless it seems, RPN is
not what Forth is about or the motive Forth exists.
As we’ll see, the state of affairs is reversed.

Actually, as you may see, my quest is generally a collection of incorrect
assumptions I made by wanting on the language with out the context
of historical past
.

By the best way, the HP-35 calculator (wikipedia.org) pictured right here is actually fascinating.
Within the early Seventies, HP had highly effective desktop calculators.
Truly,
what that they had have been actually programmable computer systems, however they nonetheless
called them calculators (wikipedia.org) for gross sales causes.
However these have been huge desktop machines that ran off of wall present.

Placing all of that energy right into a “shirt pocket” calculator was
an astounding accomplishment on the time.
Legend has it that the
measurement of the HP-35 was based mostly on the scale of Invoice Hewlett’s
precise shirt pocket.
HP-35 calculators have been in house. They killed off the slide rule.

HP calculators are well-known for utilizing RPN syntax. If it weren’t for
these calculators, I think it is probably that RPN syntax could be
digital unknown outdoors of pc science.

RPN is taken into account to be extremely environment friendly and,
being considerably inscrutable to outsiders, extremely geeky.

Let’s examine a greater instance…

Noob:

$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006,
2008, 2012-2017 Free Software program Basis, Inc.
That is free software program with ABSOLUTELY NO WARRANTY.
For particulars sort `guarantee'.
(3 * 4) + (5 * 6)
42
    

Professional:

$ dc
3 4 * 5 6 * + p
42
    

I am being cheeky right here. Customers of bc, are hardly
noobs. However it’s arguably even geekier to make use of the a lot
older dc program. bc was as soon as simply an
infix expression translator for dc to make it extra
palatable for individuals who did not need to use RPN. Thus the light
teasing.

Moreover utilizing RPN syntax,
the dc calculator
(wikipedia.org) is totally programmable. Oh and it additionally occurs to
be one of many very first Unix applications and pre-dates the C programming
language!

Anyway, the level right here is that RPN syntax allows you to specific
nested expressions with out requiring parenthesis to get the order of
operations the best way you need them. This is without doubt one of the causes RPN followers
(together with these HP calculator followers I alluded to) are so enamoured with it.

On this instance, we enter 3, then 4. * multiplies them.
Now we’ve the end result (12) accessible. However first, we enter 5 and 6 and
multiply them with one other * to additionally retailer that end result (30).
The ultimate + provides each saved outcomes (12 + 30) and
shops that end result (42).
In contrast to an HP calculator, dc would not present us any of the
saved outcomes, together with the final one till we “print” it with the
p command.

As it is known about
“ed, the standard text editor”
(gnu.org), dc would not
waste your VALUABLE time (or teletype paper) with output you do not want!

So this pertains to Forth how?

Forth professional:

3 4 * 5 6 * + .
42
    

As you’ll be able to see, somebody sitting at a Forth interpreter
can carry out this calculation precisely the identical as with the dc
calculator (or an HP calculator).

Sharp-eyed readers will observe that we print the end result with a “.”
command moderately than “p”. However that is the one distinction.

So Forth is like an RPN calculator? We enter values after which
function on them?
Effectively, that assertion just isn’t improper

However does that imply we all know what Forth is all about now?
If we all know enter issues in postfix notation, we “get” Forth?
No! Not even shut…

Forth completely makes use of postfix notation.

However then I realized some extra:

drawing of three stacks illustrating push swap and dup operations

The usage of an information stack might be the second most seen factor
concerning the Forth programming language.

A stack is an information construction typically defined with a “stack of
plates” analogy. You PUSH a plate on the stack and also you POP
a plate off the stack. The primary merchandise you placed on the stack is
the final merchandise out of the stack.

Above, we’ve an illustration of PUSH and two different frequent
stack operations:

  • SWAP slides a plate out (very rigorously) from the second
    place and places it on prime.
  • DUP takes the highest plate and duplicates it utilizing
    kitchen magic and places the duplicate on the highest of the stack (in
    this metaphor, I assume an equal quantity of matter is eliminated
    elsewhere within the Universe, however we strive to not fear too
    a lot about that).

As you will have guessed, these 4 stack phrases (PUSH, POP,
SWAP, DUP) additionally occur to be Forth phrases.

Historic observe 1: Within the previous days, folks and computer systems simply
WENT ABOUT SHOUTING AT EACH OTHER ALL THE TIME IN ALL CAPS BECAUSE
LOWERCASE LETTERS WERE TOO EXPENSIVE.

Historic observe 2: When a pc asks, “SHALL WE PLAY A
GAME?” in all caps, you have to reply NO, as we realized in 1983’s
WarGames (wikipedia.org)

Let’s examine a stack in motion:

Op   The Stack
--   ---------
3     3
4     3  4
*     12
5     12 5
6     12 5  6
*     12 30
+     42
.
    

Let’s revisit our math downside from earlier. That is the
Forth code on the left and the outcomes on “the stack” on the precise.

Relatively than worrying with the syntax or notation, we’re
now serious about what these operations are doing with our information
stack.

As you’ll be able to see, coming into a quantity places it on the stack.
The maths operators take two values from the stack, do one thing
with them, and put a brand new worth again on the stack.

The ‘.’ (DOT) operator is completely different because it solely takes one
worth (to print it) and doesn’t put something again on the stack.
So far as the stack is worried, it’s equal to DROP.
So far as people are involved, it has the helpful side-effect
of letting us see the quantity.

Now let’s have a look at one thing you most likely would not discover
on an HP calculator. One thing non-numerical…

That is legitimate Forth, assuming CAKE, HAVE, and EAT have been outlined:

CAKE DUP HAVE EAT 
    

Getting the joke right here would require figuring out
this English idiom (wikipedia.org).

Truly, this is not simply a foolish instance.
Forth’s use of the stack can result in a pure, if considerably
backward use of nouns and verbs. (Type of like Yoda’s speech habits.
“Cake you’ll dup, sure? Have it and eat it you’ll, hmmm?”)

There can, certainly, be some object named CAKE that we’ve
positioned on the stack (most likely a reminiscence reference) which
may be DUPed, after which HAVEd and EATen.

It is as much as the Forth developer to make harmonious
phrase decisions. It could actually get way more intelligent or poetic than my instance.

Naming issues is nice.

However generally not naming issues is even higher.

The stack frees us from being pressured to create express names for
intermediate values.

If I ask you so as to add these numbers:

2 6 1 3 7
    

Do you are feeling a necessity to offer a identify to every sum pair…and even the working complete?

(Hopefully your reply is “no” or the rhetorical query would not work.)

Nevertheless it’s humorous how our programming languages typically require us
to explicitly identify intermediate outcomes in order that we will check with them.
On paper, we might by no means give these values names – we might simply fortunately
begin engaged on the record.

Think about, if you’ll, a manufacturing facility meeting line through which
every individual working the road is a hateful fussbudget who refuses to
work on the half in entrance of them till you identify it. And every time the
half has been labored on it have to be given a brand new identify. Moreover, they
refuse to allow you to re-use a reputation you have already used.

A whole lot of crucial languages are like that manufacturing facility. As your
values go down the road, you have to give you nonsense names
like result2, or matched_part3.

Does your programming language make you do that?

(It is nearly as unhealthy as file names used as a versioning
system: my_doc_new_v5.4(copy)-final2…)

Working with out names (also referred to as implicit or
tacit or point-free programming) is typically a extra
pure and fewer irritating technique to compute. Eliminating names can
additionally result in far more concise code. And fewer code is nice code.

Nice, so stacks could be a very elegant technique to deal with expressions.

Have we “cracked” Forth but? Now we all know two issues:
it makes use of RPN syntax and it’s stack-based.

Effectively, Forth actually does use a stack. It’s undoubtedly a stack-based
language.

However then I realized some extra…

a confused cat working on an old pc

Ah, this have to be it as a result of it sounds fancy.

On this journey of Forth discovery, you may inevitably run into
the time period “concatenative programming”.

What’s that?

An superior useful resource for all issues concatenative is
The Concatenative Language Wiki
(concatenative.org).
It lists many concatenative languages and has a web page about Forth,
after all.

For the time period “concatenative programming” itself, the Issue
programming language web site has a wonderful web page defining the
time period:
Factor documentation: Concatenative Languages
(factorcode.org).
And, after all, there’s the Wikipedia entry,
Concatenative programming language
(wikipedia.org).

I perceive the reasons on these web sites now, however
it took me some time to get there. Your journey could also be shorter or longer.
Most likely shorter.

Let’s examine if I can stumble by means of it…

Distinction with applicative language:

eat(bake(show(combine(substances))))
    

Concatenative language:

substances combine show bake eat
    

An applicative language has you apply a operate to a worth, which
returns one other worth. Utilizing acquainted Algol-like (or “C-like”, or
“Java-like”, or “JavaScript-like”) syntax, arguments are handed to
capabilities inside a pair of parenthesis. Within the above instance, the
parenthesis find yourself deeply nested as we cross the output of 1 operate
to a different.

In contrast to the maths examples, the place the infix notation seems to be extra
pure to most of us than the postfix notation, the concatenative
instance of this baking program seems to be extra pure (a minimum of in a
human language sense) than the inside-out operate software
instance, proper?

(After all, for those who’re a programmer used to years of one thing like C
or Java or JavaScript, the inside-out parenthetical type will most likely
appear fairly pure too. Effectively, guess what? Your thoughts has been
warped. It is okay, mine has too.)

The purpose right here is that concatenative fashion has us “composing”
capabilities (which you’ll consider as verbs) just by placing them
in sequence. Every operate will likely be referred to as in that sequence.
The values which can be produced at every step are handed alongside
to be consumed as wanted.

No names (except we wish them), simply nouns and verbs.

However that is simply the floor. It seems this “concatenative language”
idea goes well past that…

The canonical instance of a concatenative language is Pleasure.

Manfred von Thun impressed by Backus’s 1977 ACM Turing Award lecture:
top of the john backus paper Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs

Can Programming Be Liberated from the von Neumann Style? (PDF) (worrydream.com)
This paper is dense with notation and I have not personally
tried to wade by means of it, but. I am certain it comprises
many profound concepts.

I do know simply sufficient to consider I perceive this paragraph from
the paper’s summary:

“An alternate purposeful fashion of programming is
based on using combining types for creating
applications. Purposeful applications cope with structured
information, are sometimes nonrepetitive and nonrecursive, are
hierarchically constructed, don’t identify their
arguments, and don’t require the complicated equipment of
process declarations to turn into typically relevant.
Combining types can use excessive stage applications to construct
nonetheless increased stage ones in a mode not doable in
standard languages.”

Maybe you have heard of “purposeful programming?” As you’ll be able to
see, that time period was being utilized in 1977.

“Concatenative programming” got here after. Actually,
Pleasure is the place the “concatenative” description comes from!
(von Thun particularly credit Billy Tanksley for creating the time period
“concatenative notation”.)

Pleasure is type of like beginning with a Lisp

…with out variables

…and with out conventional management buildings

…and all capabilities are unary (or an “arity of 1”).

Particularly, all capabilities take one stack as enter and return
one stack as output. The stack just isn’t named, it’s implied.

A program is solely an inventory of capabilities that’s learn
from left to proper.

I am unable to describe Pleasure’s genesis higher than the person himself.
Right here is von Thun in an interview about Pleasure:

“Pleasure then developed from this in a wholly haphazard manner:
First I restricted the binary relations to unary capabilities, and
this after all was a dramatic change. Second, to permit the standard
arithmetic operations with their two arguments, I wanted a spot
from which the arguments have been to return and the place the end result was to
be put – and the apparent place was a stack with just a few shuffling
combinators, initially the 4 impressed by Quine. Third, it
turned apparent that each one these combinators could possibly be changed by
unary capabilities, with solely operate composition remaining. Lastly
the very completely different distinctively Pleasure combinators emerged, which
take a number of quoted applications from the stack and execute them in
a particular manner. Alongside the best way after all, lists had already been
seen as simply particular circumstances of quoted applications. This meant that
applications could possibly be constructed utilizing record operations after which handed
on to a Pleasure combinator.”

From A Conversation with Manfred von Thun (nsl.com), which is a extremely nice learn in its entirety.

As you’ll be able to see, combinators are essential in Pleasure.
Let’s take a second to dive into these, as a result of it is a fairly
fascinating avenue of pc science…

Combinators are any “higher-order” capabilities like map.

“Greater-order” simply means capabilities that take different
capabilities as enter and do issues with them.

You may even have capabilities that take capabilities that take capabilities
and so forth to do highly effective issues. However you may must meditate on
them each time you need to re-read that a part of your code.

map is without doubt one of the extra frequent examples, so I am going to use it
for instance.

JavaScript:

inc = operate(n){ return n + 1; };

greater = [1, 2, 3, 4].map(inc);

Consequence: [2,3,4,5]
    

JavaScript utilizing an “arrow operate”:

greater = [1, 2, 3, 4].map(n => n + 1);

Consequence: [2,3,4,5]
    

(The second instance with the arrow operate syntax works precisely
the identical manner, however extra compactly. I included it to make the comparability
with Pleasure a little bit extra even-handed. Be at liberty to select a favourite
and ignore the opposite one.)

Within the first instance, we’ve acquainted Algol-like
syntax with capabilities that take arguments in parenthesis.

Maybe
map() is acquainted to you. But when not, simply know that
it takes two parameters like so: map(array, operate).
The primary parameter is implicit in these JavaScript examples, but it surely’s
there. The array object, [1, 2, 3, 4] calls its personal
map() methodology. The second parameter is a operate
(named inc within the first instance and left nameless in
the second), which will likely be utilized to each member of the record.

The output of map() is a new record containing the
results of every software.

Discover how each JavaScript examples
have variables such because the parameter n and the end result
greater. That is an instance of what I discussed a second
in the past when discussing the benefits of stacks: “Conventional”
programming languages typically make us identify values earlier than we will work with
them.

The identical factor, however concatenatively in Pleasure:

[1 2 3 4] [1 +] map

Consequence: [2 3 4 5]
    

The syntax right here could require a little bit clarification.
The sq. brackets ([]) are Pleasure’s
quote mechanism. Quotations are so much like lists, however they will comprise
applications in addition to information.

On this case, the primary citation is the quantity record,
[1 2 3 4].

The second citation is a program, [1 +].

As within the JavaScript examples, map takes two parameters.
The primary is the operate (or “program” in Pleasure) to use, and the second
is the record to use it to.

(It is type of complicated to speak about “first” and “second,” although
as a result of that is the other order through which we provide these
arguments on the stack…)

Notice the dearth of variables greater or n.
Intermediate values simply exist.

It seems to be fairly good and neat, proper?

This “point-free” fashion could be a blessing…
or curse. In contrast to computer systems, human brains have a tough time juggling too
many issues on the stack.

There appears to be a cheerful medium between named and unnamed. Additionally,
the point-free fashion appears to learn significantly from quick (even
very quick) definitions to keep away from psychological juggling and higher
composibility.

When you’ve got the slightest curiosity in Pleasure, I extremely suggest
studying or skimming this pleasant tutorial by Manfred von Thun
himself:
An informal tutorial on Joy
(hypercubed.github.io).

Notice: I had a little bit of a time truly working Pleasure to check out these
examples. Fortunately, I ultimately bumped into
Joypy (github.com),
a Pleasure written in Python. My Linux distro comes with Python put in,
so the entire course of for me was:

git clone https://github.com/calroc/joypy.git
cd joypy
python -m pleasure
...
pleasure? [1 2 3] [1 +] map
        

Okay, that is a glimpse.

However we have barely touched the conceptual energy of combinators with our
map examples. Let’s go a little deeper on
this fascinating topic:

cover of the book

This is one thing from my bookshelf. It is To Mock a Mockingbird
by mathematician and
puzzle-maker Raymond Smullyan. It makes use of puzzles involving birds to unravel
logic issues and classify some well-known combinators.

It might be inconceivable to put in writing an entire catalog of
combinators simply as it could be inconceivable to put in writing an entire
catalog of integers. They’re each infinite lists.
Nonetheless, some well-known combinators have been recognized as
having particular properties. Within the e-book above, many of those have
been given the names of birds.

Keep in mind, combinators are simply “higher-order”
capabilities that take capabilities as enter.
Effectively, it seems these are
all it’s essential to carry out any computation. They’ll change logical
operators and even variables.

What?!

Yeah, you’ll be able to re-work any expression right into a combinatorial expression
and utterly change every part, together with the variables, with
combinators.

It is type of laborious to think about at first. However you’ll be able to see it occur
proper earlier than your very eyes.
The mind-blowing device on this web page by Ben Lynn:
Combinatory Logic
(stanford.edu)
takes a time period expressed in lambda calculus and replaces every part
with simply two combinators, Ok and S.
(We’ll discuss extra about these two in only a second as a result of they
are tremendous particular.)
screenshot from the aforementioned calculator with buttons 'Look ma, no names, no variables, and no variables K-optimized!

(Ben Lynn’s entire web site is filled with neat stuff like this.
In case you’re trying to entertain your self for any period of time from
a day to the remainder your life, Lynn has you lined.)

So combinators share one thing in frequent with lambda calculus and
Turing machines. These methods present the entire constructing blocks
it’s essential to carry out any
doable computation within the sense of the
Church-Turing thesis (wikipedia.org)
or “computability thesis”. (We have additionally found some issues
which can be not computable and no system can compute
them like “the halting downside,” however these are fairly uncommon.)

It seems that computation is a elementary function of
the Universe
.
So far as we will inform, any common system of computation is equally
able to fixing any computational downside. And when you understand how
little is required, you’ll be able to invent a common pc your self!

Electronically talking, this is similar precept
that enables a NAND gate to simulate all different gates. NAND gates are
a elementary computational constructing block. You can also make an
complete pc with nothing however NAND gates and that pc can
(slowly) remedy any computable downside you’ll be able to think about.

Anyway, once we use combinators, this specific taste of common
computation is known as
combinatory logic (wikipedia.org).

What do the constructing blocks of combinatory logic appear like?

Let’s begin small:

Identification

(I x) = x
    

The only of all combinators is I, the “identification combinator”.
There are a ton of various methods to put in writing this. In lambda calculus,
it seems to be like this: I = λx.

The best way to learn "(I x) = x" is: “I utilized
to some object x ends in…x.”

We are saying “object x” moderately than “worth x” as a result of, being a
combinator, I may take a operate as enter in addition to a
worth. Actually, “object” is deliberately very summary, so
x may comprise a scalar worth, or
record, or operate, or one other combinator, or something.
No matter that object is, I returns it.

Ok and S

(Ok x y) = x

(S x y z) = (x z (y z))
    

Each of those take a couple of parameter of enter.
However for those who’re used to Algol-like operate syntax, the best way this
works could also be shocking.

Since it is the less complicated of the 2, let’s use the Ok
combinator for instance:

The best way to learn “(Ok x y) = x” is:
Ok utilized to x yields
a combinator
, which, when utilized to y at all times
evaluates to x.”

(Programmers accustomed to the idea of currying will see
that that is just like the partial software of a operate, the place
a brand new operate is “pre-baked” with the argument x. The
time period “currying” is called in honor of mathematician
Haskell Curry
(wikipedia.org),
after whom the Haskell programming language can be named.)

The result’s that Ok makes a combinator that
throws away any enter and simply returns
x. Bizarre, proper? Nevertheless it seems to be helpful.

Ok is tremendous simple to put in writing in a language like
JavaScript, which can be a pleasant selection as a result of you’ll be able to play with
it proper within the browser console like I simply did:

Ok = operate(x){
  return operate(y){
    return x;
  }
}

Ok("hi there")("bye")

> "hi there" 
        

See how the results of Ok("hi there") is a operate that
returns “hi there” it doesn’t matter what you give it as enter?

How about S? I am going to go away implementing that
in JavaScript as an train for the reader.
It is clearly far more sophisticated because it has three ranges of
“operate that yields a combinator” on the left and the end result
is an equally sophisticated combinator that first applies
parameter z to combinator y.

(By the best way, the y combinator above shouldn’t be
confused with the Y combinator.
Do you do not forget that arcane lambda calculus artifact projected
over that head with the third eye manner up close to the start of this
web page? That factor was the Y combinator! It seems, it is
all, like, linked, you realize?)

However the true level is that this: S and Ok are
particular for one very fascinating motive.
Along with I, they type the “SKI calculus” and simply
these three combinators are all you want to carry out
any computation within the recognized universe.

Truly, it is even crazier than that. You do not even want
I as a result of that, too, may be created with S
and Ok.

That is proper, the S and Ok definitions
above are an entire system for common computation.

cover of the book

The e-book proven right here is one other from my bookshelf. It is
Combinators: A Centennial View by Stephen Wolfram.

It begins with a (a lot too) terse introduction to the SKI combinator
calculus after which launches into web page after web page of visualizations of S
and Ok combinators being fed into one another. Like fractals or automata,
easy inputs can produce patterns of peculiar sophistication.

Wolfram demonstrates combinators that maintain producing completely different
output for a gazillion iterations after which get caught in a loop. A few of
them produce common patterns for some time after which begin producing
completely different patterns. Some simply loop perpetually on the outset.
As in different common methods, there isn’t a finish to the complexity
produced by these two easy constructs. It’s infinite. And all of
that is simply S and Ok combinators taking combinators as enter and
returning combinators as output.

I feel it’s wild and enjoyable to see somebody play
with a topic like Wolfram does on this e-book. Every web page is saying,
“Have a look at what is feasible!”

Combinators can be Wolfram’s ode to the discoverer of
combinatory logic,
Moses Schönfinkel (wikipedia.org)
who, like so lots of the giants within the area of pc science,
did his work on paper many years earlier than the primary digital digital
computer systems beeped their first boops.

Determining the output of the S combinator as soon as
was sufficient to maintain me occupied for some time. It boggles my thoughts to
think about feeding it one other S as enter on paper,
not to mention discovering these specific combinators within the first place.

Okay, we get it, combinators are a loopy technique to compute.

However are they price utilizing in “actual” applications? In restricted
doses, completely!

Combinators allow us to issue out express loops. This:

foo.map(bar)
    

is similar as this for much longer assertion:

temp = [];
for(i=0; i<foo.size; i++){
    temp[i] = bar(foo[i]);
}
    

Each of these items of JavaScript give us the results of making use of
the operate bar() to an array foo.

I feel map() is a superb instance of the facility of
combinators to scrub up a program with abstraction. When you begin
utilizing easy combinators like this to summary away the boilerplate
logic of one more loop over an inventory of things, it is laborious
to return.

My private historical past with exploring increased order capabilities in
a manufacturing setting is thru the
Ramda (ramdajs.com) JavaScript
library, which I found from the discuss
Hey Underscore, You’re Doing It Wrong!
(youtube.com)
by Brian Lonsdorf, which is improbable.

As soon as I began discovering how combinators and curried capabilities
may eradicate huge previous chunks of code, I used to be hooked!
The previous, dreary procedural code turned a brand new enjoyable puzzle!

Thoughts you, it is very simple to go overboard with these items and
write one thing far much less readable
than some easy procedural code. (Gee, ask me how I do know this.)

However in restricted doses, it is tremendous highly effective and compact.

Pleasure makes use of combinators to “issue out” all kinds of logic.

Even completely different types of recursion may be utterly dealt with
for you by combinators in Pleasure due to the uniformly unary capabilities.

This is a factorial definition:

factorial == [null] [succ] [dup pred] [*] linrec
    

Let’s strive it:

5 factorial
120
    

Computing the factorial of a quantity is usually used for instance of
recursion. The ultimate reply is the enter quantity multiplied by the
earlier quantity multiplied by the earlier quantity multiplied by…
the remainder of the numbers all the best way right down to 1.

Computing a factorial requires a cumulative end result. With out
recursion, you want an express variable to carry the intermediate
end result as you loop by means of the numbers.

As proven within the Pleasure factorial definiton above,
linrec is a “linear recursion” combinator. It takes takes
4 parameters, every of which is a quoted program. null is a
predicate which exams for zero. dup is similar as in
Forth. pred is an operator which yields a quantity’s
predecessor (given 4, yields 3). “*” multiplies two
numbers, similar to you’d count on. Given these items, maybe you’ll be able to
take a guess at how linrec works?

For comparability, here’s a recursive JavaScript resolution:

operate factorial(n) {
    if (n <= 1) {
        return 1;
    }

    return n * factorial(n - 1);
 }
        

Notice that the Pleasure instance is not only shorter and has no
variable names but it surely has abstracted away the mechanics
of recursion
. All we’re left with is the
logic particular to the factorial downside itself.

It is debatable which of those two are extra readable
as a result of the measure of readability is within the eye of the beholder.
However I feel you’ll be able to think about getting good at studying the Pleasure
instance.

Okay, so we have gone fairly deep into this concatenative
programming and combinator factor. How does this truly
relate to Forth?

To begin with, Forth does have services for
coping with combinators:

Forth helps increased order capabilities with “execution tokens”
(operate pointers) and the EXECUTE phrase.

It will run the phrase returned by the phrase FOO:

FOO EXECUTE
    

With this, you’ll be able to very compactly outline combinatorial phrases equivalent to
MAP, FOLD, and
REDUCE.

First, let’s have a look at how EXECUTE works. The syntax will likely be
alien to non-Forth programmers, however the idea will likely be no downside for
anybody used to utilizing firstclass capabilities.

First, let’s make a brand new phrase:

: hi there ." Whats up" ;
        

That is Forth for, “Compile a phrase referred to as hi there
that prints the string Whats up.”

(We’ll find out how compiling phrases truly works later.
For now, please simply gracefully settle for what you are seeing.)

Subsequent:

 
VARIABLE hello-token
        

This creates a brand new variable referred to as hello-token which
will retailer the “execution token” for the hi there phrase.

This half will look tremendous cryptic for those who’re new to Forth:

 
' hi there hello-token !
        

Let’s study this one piece at a time:

  • '” will get the tackle of the phrase
    hi there” and places it on the stack.
  • hello-token” is a variable, which
    simply leaves its tackle on the stack when referred to as.
  • !” shops a worth from the stack
    (the tackle of hi there) at
    an tackle from the stack (the tackle of
    variable hello-token).

So the code above merely reads, “Retailer the tackle of
hi there within the variable hello-token.”

Now let’s use EXECUTE to name this “execution token”:

 
hello-token @ EXECUTE
Whats up
        

Behold, it printed the “Whats up” string!

Keep in mind, the variable hello-token leaves its
tackle on the stack when it’s referred to as.

@” is a typical Forth phrase that masses the worth
from the given tackle and places that worth on the stack.

EXECUTE will get an tackle from the stack and runs
no matter phrase is discovered at that tackle.

Maybe it could be useful to see that this foolish assertion:

' hi there EXECUTE
        

is equal to simply calling hi there instantly:

hi there
        

Anyway, now we’re armed with Forth’s combinatorial skill:
Treating capabilities (“phrases”) as values so different capabilities can
take them as enter. This permits us to outline combinators in Forth.

For some compact higher-order operate definitions
in Forth, take a look at this Gist by Adolfo Perez Alvarez (github.com).

So sure, Forth is concatenative. It implicitly passes values
from one operate invocation to the following. And it helps higher-order
capabilities.

Nonetheless, I do not consider finding out “concatenative
programming” normally or Pleasure particularly is an efficient technique to perceive
Forth!

For instance, this easy assertion:

2 3 +
    

may be learn two other ways:

Forth: “Push 2 after which 3 on the stack; add them; push end result
5
on the stack.”

Pleasure: “The composition of the capabilities 2, 3, and +
is equivalent to the operate 5.”

Whereas each languages share a cosmetically comparable syntax,
and each produce the identical end result for this
expression, there’s a elementary distinction between how the 2
languages “assume” concerning the expression as a result of they arrived at
this place in utterly other ways.

Forth’s solely concern (as a language) is to course of these three
tokens and act upon them in accordance with some easy guidelines.
(If the token is within the dictionary, execute it. If it is a quantity, put
it on the stack.)

To Pleasure, it might be the identical mechanical course of beneath the hood, however
the language itself sees these tokens extra like a mathematical
expression. It is a way more summary outlook.

The purpose I am making is that Forth could accomodate the
summary standpoint, if the developer chooses to take it. However
Forth just isn’t based mostly on summary concatenative computing
ideas or combinatory logic.

Let’s take a look at this from a historic perspective.
First, the notions of postfix syntax (RPN) and an information stack for
the premise of the language:

drawing of konrad zuse's z3 computer

Postfix notation was undoubtedly within the air when Chuck Moore
created Forth.

Stacks have been recognized and used within the time of Forth’s origins,
although they have been typically restricted to 2-4 objects in registers.

So I feel it is affordable to imagine that RPN syntax and use of
stacks are a traditionally correct technique to study Forth’s “origin story.”

Maintain that thought, this is a enjoyable apart:

The drawing of the pc labeled “Z3” on the precise is of
the
Z3 computer
(wikipedia.org)
designed by engineer and pc scientist Konrad Zuse. That is broadly
thought of to be the first programmable digital pc!
It used electro-mechanical relays just like the telegraph networks of the day.

(By the best way, a specific amount of electro-mechanical logic is
nonetheless utilized in trendy nuclear reactor security methods as a result of
the massive mechanical parts should not as weak to nuclear
radiation as semiconductors!)

The Z3 may do addition in lower than a second and multiplication
in three seconds. It had 64 phrases of twenty-two bits every and labored with
the equal of recent floating-point numbers.

As talked about above, it may be mentioned to make use of RPN, although there are solely
two registers and 9 directions. Opcodes have been encoded in eight
bits. The pc is programmable by way of punched paper tape (you’ll be able to see
the tape machine to the precise of the management console, although it’s kind of
of a scribble in my drawing).

It’s additionally a stack machine. Once more, that is with a mere
two registers, which get juggled in a selected sequence as you
load and retailer values.

Enjoyable truth: The management unit used particular management
wheels to encode microsequences. If the microsequence wasn’t
programmed appropriately, it may short-circuit the machine and destroy
the {hardware}!

I obtained most of this info from this wonderful paper by
Raul Rojas:
Konrad Zuse’s Legacy: The Architecture of the Z1 and Z3 (PDF) (ed-thelen.org).

Anyway, so the straightforward mechanics of RPN and stack-based
operation are very pure for digital computing machines
and their use goes again to the very starting.

However Pleasure and the time period “concatenative programming” come from the
Nineteen Eighties.

Uh oh.

Whereas the concepts of combinators and different sorts of
common computation have been well-known in sure mathematical
and computational circles, I’d argue they weren’t very amenable
to present pc {hardware} till a lot later when computer systems turned
quick sufficient to assist “purposeful programming” types and
abstractions.

Till then, programming was “near the steel.”
Even the thought of “structured programming” with programming language
ideas like if/else or whereas/for loops was
as soon as thought of novel! Till then, every part was completed with tackle
jumps or GOTO.

It is essential to do not forget that “coding”, the
precise act of turning an summary program into machine code,
was way back thought of to be a mere secretarial talent, not far
faraway from typing and different types of information entry.
For this reason some folks (together with myself) refer themselves as
“programmers” moderately than “coders”.

Concatenative programming, with its emphasis on combinators
(and immutable information buildings, which we’ve not talked about),
would not have the identical historic grounding for Forth the best way that RPN
syntax and stack-based programming do.

So I need to conclude that understanding concatenative programming
is tremendous cool, but it surely would not truly assist us perceive the
true nature of Forth as a result of it would not describe how Forth got here to be.
It’s not a part of Forth’s “origin story.”

As we’ll quickly see, Forth actually is concerning the “nuts and
bolts”. You carry your personal theories with you.

So whereas all these descriptions of the Forth language are true
(RPN, stack-based, concatenative), all of them describe
the language Forth from the vantage of hindsight.

There’s nothing improper with occupied with Forth in these phrases,
but it surely would not reply the “why” questions:

Why does Forth have this syntax?”

Why does Forth work this fashion?”

I feel the solutions to the “why” questions are finest answered by
taking a look at when.

What’s Forth’s historical past, anyway?


chuck moore as marty in a drawing of the back to the future poster

If this picture would not make any sense to you, citizen of
the longer term, it is from the long-lasting film poster by Drew Struzan for
Back to the Future (1985) (wikipedia.org).

chuck moore operating an IBM 704

Chuck Moore is programming an IBM 704 with Fortran on punchards.

“Compiling took half-hour…you bought one shot per day”

— Chuck Moore, Forth, the Early years

In Forth – The Early Years (PDF) (worrydream.com), Chuck
Moore recites a reasonably terse historical past of Forth, from the earliest
pre-Forths to the creation of the language commonplace.

(Notice: Chuck mentions the Smithsonian Astrophysical Observatory
(SAO) and the Massachusetts Institute of Expertise (MIT) in
roughly the identical time interval, and it’s kind of tough to be
fully certain which half is speaking about which group. However
for those who have a look at a map, SAO is at Harvard College. Harvard and MIT
are a few mile aside in Cambridge, Massachusetts. It is principally a
singular level for those who zoom out a bit. In order that helps clarify the
overlap.)

The pc in query is the
IBM 704
(wikipedia.org)
It was a type of room-filling vacuum-tube computer systems with
tape drives the dimensions of refridgerators.

The 704 was a completely programmable “trendy” pc with
magnetic-core reminiscence, a number of registers, a 36-bit instruction set, and
36-bit phrases (“phrase” as in native reminiscence measurement for the processor, not
“phrase” as in Forth capabilities).

There have been switches for every register on the management console, however
applications could possibly be written to and browse from paper punch playing cards.

It was very trendy for the time, however…

“In its day, the 704 was an exceptionally dependable machine.
Being a vacuum-tube machine, nonetheless, the IBM 704 had very poor
reliability by right now’s requirements. On common, the machine failed round
each 8 hours, which restricted this system measurement that the primary Fortran
compilers may efficiently translate as a result of the machine would fail
earlier than a profitable compilation of a giant program.”

It is tough to think about now, however altering parameters for a program,
re-compiling it, and working it once more may take a day (assuming you
did not make any errors).

So Chuck solved that irritation with a particularly intelligent resolution:

Moore made an interactive interpreter
on a pc with nothing we might acknowledge right now as an interactive
terminal.

He completed this by making his program programmable.
fortran on a punchcard

This is a quote from The Evolution of Forth (forth.com):

“Moore’s programming profession started within the late Nineteen Fifties on the
Smithsonian Astrophysical Observatory with applications to compute
ephemerides, orbital components, satellite tv for pc station positions, and so forth.
His supply code crammed two card trays. To reduce recompiling this
giant program, he developed a easy interpreter to learn playing cards
controlling this system. This enabled him to compose completely different
equations for a number of satellites with out recompiling…”

His free-form enter format turned out, sarcastically, to be extra
dependable for human use than Fortran, which required formatted
columns. (On the time, any mis-aligned columns in Fortran punchcard
enter would require a re-run of this system!)

It was additionally quicker and extra compact.

These “programming this system” statements in Moore’s easy
interpreter didn’t use key phrases.
They have been assertion numbers encoded on a punchcard.

That is the origin of the system that might ultimately be named
Forth.

Based on Moore, the interpreter’s assertion numbers would have been
roughly equal to those Forth phrases:

WORD NUMBER INTERPRET ABORT
    

Free-form enter was uncommon on the time. It is clearly a brilliant good
various to recompiling your calculation program each time you need
to vary some numbers!

So, finally, we’ve found the true origin of the Forth
language
: Moore wrote a easy interpreter to cut back waste
and tedium.

Already, Moore has exhibited the defining mixture of traits
shared by nice programmers all over the world: Ingenious and allergic to
tedium.

If it had stopped there, it could have been a intelligent trick and
maybe worthy of a footnote in historical past.

However Chuck Moore didn’t cease there.

drawing of chuck at the stanford burroughs b5500 system

Now we head from Massachusetts to California the place Moore discovered
himself at Stanford College the place he obtained his BA in Physics
and began graduate faculty. He labored with Stanford’s
Burroughs B5500.

Let’s discuss concerning the pc first:

The B5500 (or “B 5500” – the official handbook places an area between
the B and the quantity) was a solid-state pc. It was a part of the
“second-generation” of computers
(wikipedia.org).
These computer systems had discrete transistors on circuit boards. By
distinction, the first technology earlier than them used vacuum tubes
(just like the aforementioned IBM 704) and the third technology
after them used built-in circuits.

Actually, the
Burroughs Large Systems
engineers have been transistor pc pioneers.
And the B5000 collection was a pioneering system.

This is some extra sources:

And what precisely did Chuck Moore do with that B5500 machine?

Moore’s CURVE was one other mathematical software, written in
Stanford’s personal Algol implementation.

It contained a way more refined interpreter this time
with an information stack and management stream operators.

Equal Forth phrases:

IF ELSE DUP DROP SWAP + - * 
    

(As we’ll see, symbols like “+” and “-” are phrases in Forth.)

Moore labored on the Stanford Linear Accelerator
as a programmer. His focus was on steering the beam of
the electron accelerator.

The CURVE program was much more “programmable” than
his Fortran program at SAO. He took these concepts and
expanded them to incorporate the thought of a parameter stack
and the power to outline new procedures.

This made the interpreter far more versatile and succesful.

Apart: At this level, I additionally assume it is fascinating to
evaluate Moore’s budding interpreter language with one other interpreter
created particularly to be embedded in bigger applications for controlling
them:
The Tcl programming language
(wikipedia.org).
27 years after Moore began his work, John Ousterhout created Tcl out
of frustration with ad-hoc, half-baked options 1988 at Berkeley. The
identify comes from “Device Command Language”. However the comparability
goes deeper than simply the shared motivation.
Tcl and Forth
have comparable ranges of syntactical purity and suppleness. All the things
in Tcl is a string! Each languages give the person the facility to outline
elementary elements of the system, equivalent to new management buildings, within the
language itself. If this sounds fascinating, you owe it to your self to
play with Tcl for some time. This can be very intelligent and very
succesful. The primary implementation has been nicely cared-for and may be
discovered on most Unix-like methods, typically put in by default.

As Moore demonstrated with CURVE, a strong, extensible interpreter
is a big time-saver (actually when in comparison with re-compiling the
program!) and permits the person of this system so as to add to this system’s
performance on the fly. It is tough to overstate how highly effective this
may be.

Actually, now we’ve the beginnings of a fully-fledged
programming language. It is not named Forth but, however
we’re getting nearer.

a teletype 33 with paper tape reader and writer

“With the TTY got here paper-tape and among the
most un-friendly software program possible – hours of modifying and punching
and loading and assembling and printing and loading and testing
and repeating.”

— Chuck Moore, Forth, the Early years

First, let’s speak about what “TTY” means in 1965.
Teleprinters
(wikipedia.org) or “teletypewriters” or simply “teletype”
have been all printer gadgets. They printed to steady sheets of paper
fan-folded to suit into bins.

The Latin “tele-” prefix means “far” or “at a distance”. These
machines hint a direct lineage from telegraphs and Morse code.

Within the late 1800s, the idea of a typewriter which operated over
telegraph traces had been explored and existed in a wide range of types.
However the transmission code, paper tape, and typewriter system devised by
Donald Murray (oztypewriter.blogspot.com)
is the one which received out. And it was arguably Murray’s
selection of QWERTY keyboard that cemented it as the usual round
the world.

The present Baudot code (from which we additionally get the time period “baud”)
was modified by Murray into one thing that very a lot resembles what we
nonetheless use right now. Murray additionally launched the idea of management
characters, which nonetheless clearly retain their typewriter origins within the
names:
CR (carriage return) and LF (line feed).

Teletype machines began as point-to-point textual content communication
instruments (just like the telegraph), however they have been later used over switched
networks just like the world-wide Telex system which used pulse dialing
to robotically route a connection by means of the community.

The Teletype Model 33
(wikipedia.org)
I drew above was one of the vital well-liked teletypes used with computer systems.
It was created by The Teletype Company in 1963, which suggests it
shares a beginning yr with the ASCII commonplace! It remained well-liked till
the mid-Seventies when video terminals lastly got here down in value sufficient to
push printer teletypes apart. Actually, Teletype Co. made the Mannequin 33
till 1981, which is way later than I’d have guessed!

As for
paper-tape
(wikipedia.org), I am going to simply quote Wikipedia instantly:

“Punched tape was used as a manner of storing messages for
teletypewriters. Operators typed within the message to the paper tape,
after which despatched the message on the most line pace from the tape.
This permitted the operator to organize the message “off-line” at
the operator’s finest typing pace, and permitted the operator to
appropriate any error previous to transmission. An skilled operator
may put together a message at 135 phrases per minute (WPM) or extra for
quick durations.”

Donald Murray did not invent the idea of perforated paper
tape for information storage, however his system used it for the encoding of
transmitted messages from the keyboard. It would not appear to be a stretch
to hint the origins of this storage methodology to Murray’s system.

The computer systems of this period and earlier have been paper manipulators.
They have been type of like actually sophisticated typewriters. They displayed
their output on paper, they have been programmed with paper, and so they stored
long-term storage on paper!

However as time went on, pc interactivity elevated. They turned
much less like typewriters and extra just like the machines we use right now.

As every new skill emerged, Forth turned more and more interactive.

Forth features direct terminal enter and output!

KEY EMIT CR SPACE DIGIT
    

These new phrases turned Moore’s system right into a program editor.

Now you’ll be able to edit this system inside the program.

Moore’s full system is now type of like an built-in growth
atmosphere and type of like an working system.

Within the mid-Nineteen Sixties, “mini-computers” got here out. They have been
nonetheless enormous by right now’s requirements, however not required a
giant room of their very own.

Along with the discount in measurement, the opposite rising change was
direct interactive use of a pc by way of teletype.

Particularly, the invention of
timesharing (stanford.edu)
was an enormous shift away from the “batch processing” fashion of
computing that had come earlier than (like with enter by way of punchcard).

(Enjoyable truth: A “second technology” time-sharing working system
referred to as Multics
(multicians.org)
was the non secular ancestor of and
identify from which Brian Kernighan made the joke identify
Unix: “Certainly one of no matter Multics was lots of”.)

Moore’s evolving pre-Forth language additionally gained
utterly interactive modifying and executing of applications.

This may have been proper across the time
that the unique
LISP REPL (Read-eval-print loop)
(wikipedia.org)
was created in 1964 on a PDP-1.

If not pre-saging, Moore was actually on the bleeding edge
of interactive pc utilization!

Apart: If you wish to see an superior demonstration of
interactive pc utilization on paper, take a look at this demonstration
by Bob Spence:
APL demonstration 1975
(youtube.com).
Bob Spence
(wikipedia.org)
is finest recognized for his personal contributions, together with a variety of early
intelligent pc interplay concepts which can be price re-examining right now.
Bob’s demo is extraordinarily nice to observe and brilliantly offered
in break up display. Discover how paper output allows you to mark up stuff with
a pen – fairly good function!
And
APL
(wikipedia.org)
is a complete different rabbit gap which has fascinating intersections with
the point-free and higher-order operate programming we have encountered
earlier.

Then this occurs…

IBM 1130 minicomputer at Mohasco, a textiles producer in New York.
drawing of chuck at an IBM 1130 minicomputer

16 bit, 8 KB RAM.

Backup was by way of punch/reader.

With disks, now we will have file names!

File names restricted to five characters…

Moore names his “fourth technology” system “FORTH”.

Yup, this actually is the origin of the identify, “Forth”. Humorous how
momentary issues have a tendency to stay and final perpetually, is not it?

The
IBM 1130
(wikipedia.org)
is a type of new-fangled “minicomputers” we have talked about.
Gosh, it was so small, the CPU weighed lower than a automobile!

And it was inexpensive! The bottom mannequin was as little as $32,000.
Examine that to $20,000, the median value for a home within the U.S.
in 1965.
Simply consider that: In case you may afford a home, you have been nicely
in your technique to with the ability to afford a pc!

As famous, the unit Chuck Moore labored on had a disk drive,
which might have bumped up the value an extra $9,000.
That might be the equal of shopping for an above-average home
and including a pair brand-new 1965 automobiles within the driveway.

However, wow, think about having disk drive cartridges with 512 KB of
storage at your disposal. What would you do with all that house?

As talked about, presently, we’re nonetheless interacting with the
pc (largely) by way of paper, however these minis introduced the thought of
interactive computing to “the lots” as a result of they have been a lot
smaller, cheaper, and extra dependable than the kinds of computer systems that
had come earlier than.

Quoting
The Evolution of Forth (forth.com):

“Newly married and in search of a small city atmosphere, Moore joined
Mohasco Industries in Amsterdam, NY, in 1968. Right here he developed
pc graphics applications for an IBM 1130 minicomputer with a 2250
graphic show. This pc had a 16-bit CPU, 8k RAM, his first
disk, keyboard, printer, card reader/punch (used as disk backup!),
and Fortran compiler. He added a cross-assembler to his program to
generate code for the 2250, in addition to a primitive editor and
source-management instruments. This method may draw animated 3-D
pictures, at a time when IBM’s software program for that configuration
drew solely static 2-D pictures. For enjoyable, he additionally wrote a model of
Spacewar, an early online game, and transformed his Algol Chess
program into the brand new language, now (for the primary time) referred to as
FORTH. He was impressed by how a lot less complicated it turned.”

As you will have gathered by now, Chuck Moore is a reasonably
extraordinary pc programmer.

It seems the IBM 1130 was massively influential to a bunch of early
big-name programmers along with Moore. One thing was in
the air.

Along with it is humorous new identify, Forth had additionally gained new
talents:

Moore provides return name stack, permitting nested phrase definitions:

: DOUBLE DUP + ;
: QUAD DOUBLE DOUBLE ;
    

And a dictionary of phrases.

It is not simply the identify that makes this the primary actual Forth:
A dictionary of named phrases which may be referred to as interactively or
recursively within the definitions of different phrases is without doubt one of the
defining options of Forth. The power to make use of phrases as constructing
blocks is the Forth language’s main abstraction.

Within the instance above, we have outlined a phrase referred to as DOUBLE
which duplicates the quantity on the highest of the stack and provides the
two numbers collectively.

A second phrase referred to as QUAD makes use of the earlier definition
by calling DOUBLE twice, quadrupling the quantity in a
moderately amusing manner.

A return stack makes this doable. With no return stack, we’ve
no manner of telling the pc “get again” to the place in
QUAD the place we left off after DOUBLE is finished.

(We’ll get to the specifics of the syntax quickly. That is one other
important a part of understanding Forth.)

drawing of chuck at a univac 1108 console

Nonetheless at Mohasco. Programming a Univac 1108.

A brand new port of Forth written in assembler and will name COBOL modules
as a result of that is what the company fits wished in 1970.

Moore hates complexity.

To begin with, the UNIVAC 1108
(wikipedia.org)
is a superb instance of the superior “retro-futuristic” design of
these previous machines. Simply have a look at the sweeping angles in my drawing
of the console. That is a cool pc console!

When these computer systems value greater than a home, it makes excellent
sense that they have been constructed into stunning {custom} furnishings
that made them appear like house ships.

It’s important to surprise: Did the sci-fi artwork of the time drive
the design of those computer systems or did the computer systems and industrial
design of the time inform the artwork? Or, extra probably, did they each
feed off of one another within the traditional cycle of, “life imitates artwork
imitates life?”

That is a teletypewriter constructed into the desk of the console.
I presume the tractor-feed paper would have spooled to and from
containers behind the smooth facade.

Anyway, the UNIVAC 1108 is an much more trendy pc than the IBM
1130. Now we’re shifting into utilizing built-in circuits for every part,
together with the register storage. (Talking of registers, the 1108 had
128 of them and should have been fascinating to program!)

As was additionally the development on the time, the CPU
was constructed of discrete playing cards linked collectively by a wire-wrapped
backplane.

In case you’re not accustomed to the method, you must know that
wire-wrapped
(wikipedia.org)
connections are extraordinarily top quality. Wire is wrapped with
nice pressure round a submit, making a gas-tight connection that won’t
corrode (corrosion can happen outdoors the connection, after all). A
little little bit of the insulation will get wrapped within the final turns, which
gives flexibility and pressure reduction. There are NASA pointers for
making an ideal wire-wrap connection.

Anyway, the Univac was much more highly effective and trendy
than Moore’s earlier pc and he took benefit of it.

You do not have to learn between the traces to see Moore’s apparent
distaste of
COBOL
(wikipedia.org),
the COmmon Enterprise-Oriented Language.
What’s spectacular is that he managed to nonetheless use Forth whereas
additionally utilizing the required COBOL modules.

When this challenge was deserted by the employer, Moore was
upset by the entire state of affairs, notably the best way enterprise software program
was rising in complexity. This would possibly not be the final time we
see this theme crop up.

He additionally wrote a e-book (unpublished) presently referred to as
Programming a Drawback-Oriented Language.
It is written in typical Moore vogue, with out superfluous phrases or
exposition. Be at liberty to distinction this with the article you are studying
now.

(This e-book will likely be talked about once more later.)

Nationwide Radio Astronomy Observatory
– Pc management software program for radio telescopes.
drawing of radio telescope dishes from NRAO

Radio telescopes are like visible telescopes, however they accumulate decrease
frequency waves. Because of the magic of computer systems, we will course of these
indicators to see what the radio telescopes see.

Radio telescopes can work with every part from 1 kHz, which is simply
beneath the makes use of of “radio” as we consider it for navigation,
communication, and leisure, to 30 GHz, which continues to be nicely beneath
the seen portion of the electromagnetic spectrum. Shopper microwave
ovens function at about 2.45 GHz.

(Talking of Gigahertz, apparently Intel Core i9 processors can run
at clock speeds as much as 6 Ghz, however most CPU designs prime out at round 4
Ghz. This can be essential for Forth for causes I clarify later.)

The seen a part of the spectrum could be very small by comparability. It
begins at 420 THz (terahertz) and ends at 720 THz. The acquainted
rainbow of colours captured within the mnemonics “Roy G. Biv” or “Richard of
York Gave Battle in Useless” (ROYGBIV) lists colours so as of lowest
frequency (Pink) to highest (Violet).

Right here is the official web site of the
National Radio Astronomy Observatory
(nrao.edu).
However for a greater abstract,
the Wikipedia entry (wikipedia.org)
is the best way to go. Remember to scroll right down to the unimaginable picture and
description from 1988 of the collapsed 300ft radio telescope:

“The telescope stood at 240ft in peak, wieghed 600-tons, had a
2-min arc accuracy, and had a floor accuracy of ~1 inch. The
collapse in 1988 was discovered to be as a consequence of unanticipated stresses
which cracked a hidden, but weight and stress-supporting metal
connector plate, within the assist construction of the large telescope.
A cascade failure of the construction occurred at 9:43pm inflicting the
complete telescope to implode.”

The 300ft dish had been the world’s largest radio telescope when it
went lively in 1962 on the NRAO website in West Virginia.

My drawing above is of the
Very Large Array
(wikipedia.org)
in New Mexico.
NRAO can be a accomplice in an enormous worldwide array in Chile.

By utilizing radio interferometry, arrays of telescopes may be handled
as primarily one enormous telescope with the diameter of the array
(lacking the sensitivity a dish of that measurement would have).

However the scope for which Moore wrote software program was a single 36ft (11
meter) dish at Kitt Peak in Arizona referred to as The 36-Foot Telescope.
It was constructed in 1967 and continued
working till it was changed with a barely bigger and extra
correct dish in 2013.

The 36ft scope was used for millimeter-wavelength molecular astronomy.
That is the vary above “microwaves” and these telescopes fairly
a lot must be constructed at dry, excessive altitude websites as a result of
water vapor within the air can intervene with the radio waves.

(Notice that Moore stayed on the NRAO headquarters in Virginia and
was not on-site at Kitt Peak.)

NRAO had a coverage of utilizing Fortran on its minicomputers, however based mostly
on the success of his earlier work, Moore was begrudgingly given
permission to make use of Forth as an alternative.
I could not probably do justice to summarizing it, so this is Chuck’s
personal phrases describing the software program he wrote for the NRAO (additionally from
Forth – The Early Years):

“There have been two modes of observing, continuum and spectral-line.
Spectral-line was essentially the most enjoyable, for I may show spectra as they
have been collected and match line-shapes with least-squares.”

It did advance the state-of-the-art in on-line information discount.
Astronomers used it to find and map inter-stellar molecules
simply as that turned sizzling analysis.”

Here is a photo (nrao.edu) of the 36-foot telescope.
And
here is a photo of the control room in 1974
(nrao.edu)
with what seems to be a PDP-11 within the background.

As you’ll be able to see, the work itself was extraordinarily fascinating and
cutting-edge. However how Moore went about it was additionally very fascinating,
which a collection of pc drawings will exhibit in a second.

However on the Forth language entrance, there was one other growth…

Right now, there are talks of patenting Forth.

Moore believes concepts should not be patented.

We take it without any consideration now that “free” or “open” software program
unencumbered by patents and restrictive company licenses is an efficient
factor. However this was completely not a mainstream place in
the early Seventies.

To place issues in context, in the summertime of 1970,
Richard Stallman
(wikipedia.org) was simply out of highschool and was writing
his first applications in Fortran (which he hated) after which APL.

It wasn’t till 1980 that Stallman lastly obtained fed up sufficient with
the state of proprietary and legally encumbered software program to start out the
“free-as-in-freedom” software program revolution. Firms have been more and more
utilizing copyright to stop modification, enchancment, or duplication by
the tip person. Stallman, being a reasonably unimaginable programmer, wrote free
clones of such applications. He introduced the
GNU project
(wikipedia.org)
in 1983.

Apart: I consider Stallman was proper. There’s completely
nothing improper with writing applications for cash or promoting software program. However
utilizing the legislation to stop folks from really proudly owning that software program
by limiting how or the place to run it, and even stopping folks from
writing their very own comparable software program, if they’re succesful
, is an
abominable follow and needs to be countered at each step.

Moore additionally rejects the standardization of Forth.

“All of my fears of the usual and none of the benefits of the usual have come to cross. Any spirit of innovation has been totally quelched.

Underground Forths are nonetheless wanted.

I mentioned I believed the usual needs to be a publication commonplace however they wished an execution commonplace.”

— Chuck Moore, 1997

Quote from the ANSI Forth part in
this cool collection of Forth quotes
(ultratechnology.com) by Jeff Fox.

I feel that while you get to the guts of what Forth is all
about, Moore’s displeasure with the ANSI standardization out of the blue makes
tons of sense. In brief, the entire level of Forth is to create
your personal toolkit. Having an all-inclusive language commonplace is nice
for ensuring Forths are interchangeable. Sadly, it is
additionally antithetical to adapting the language to your particular {hardware}
and software program wants.

Alright, sufficient philosophizing. Let’s get again to the pc
stuff!

Whereas Moore was at NRAO, he additionally wrote software program to level the telescope.
Elizabeth Relatively (Moore credit her as Bess Relatively in his paper) was
employed for assist and so they labored collectively on a minimum of one port.
The Forth system migrated throughout a number of machines at NRAO which,
as we’ll see, highlights one of many technological strengths of the
commonplace Forth implementation.

By the best way, after her preliminary response of shock and horror,
Elizabeth Relatively embraced Forth. From
The Evolution of Forth
(forth.com):

“After about two months, Relatively started to appreciate that one thing
extraordinary was occurring: regardless of the extremely primitive
nature of the on-line computer systems, regardless of the weirdness of the
language, regardless of the dearth of any native consultants or sources, she
may accomplish extra within the few hours she spent on the Forth
computer systems as soon as per week than your entire remainder of the week when she had
just about limitless entry to a number of giant mainframes.”

Relatively went on to put in writing the primary Forth handbook in 1972 and
write papers about it for the NRAO and different astronomical organizations.

Later, Elizabeth “Bess” Rather
(wikipedia.org)
turned the co-founder of FORTH, Inc with Chuck and
remained one of many main consultants and promoters of the Forth language
till her retirement in 2006.
screenshot of the top half of the first page of the article

There’s an amazing overview paper of the entire NRAO system by
Moore and Relatively in a 1973 Proceedings of the IEEE:
The FORTH Program for Spectral Line Observing (PDF)
(iae.nl).

It features a high-level description of the system with examples of
interactive Forth utilization and a neat diagram on the primary web page, which you
can see within the screenshot.

As talked about, Forth was ported to a bunch of various computer systems
at NRAO.

Let’s have a look:

Forth on the IBM 360/50
drawing of chuck using an ibm 360/50 computer

Moore mentions first having ported his Forth system to the
IBM 360/50
(wikipedia.org).

The System/360 (or S/360) computer systems have been extraordinarily profitable,
largely due to availability, longevity, and compatibility.
IBM claims to be the primary firm to make use of
microcode
(wikipedia.org)
to supply a suitable instruction set throughout all S/360 computer systems
regardless of the {hardware} variations between fashions.

The cheaper 360 computer systems used microcode whereas the dearer
and highly effective machines had hard-wired logic. NASA even had some one-off
fashions of IBM 360 made only for them.

Till microcode got here alongside, for those who purchased a “low cost” pc to get
began after which upgraded to a extra highly effective pc, you’ll have
to re-write your applications in a brand new instruction set. (In case you occur to
have written your applications in a high-level language like Fortran, you
would nonetheless must re-compile your applications from punchcards, and also you
would want the Fortran compilers on each computer systems to be completely
suitable!) It is easy to see why with the ability to improve with out
altering your software program would have been interesting.

System/360 computer systems have been
a “huge wager” (5 billion {dollars} in accordance with IBM themselves:
System 360: From Computers to Computer Systems
(ibm.com)) that almost destroyed the corporate.
The wager clearly paid off as a result of they made these machines
from 1964 to 1978.

Oh, and it wasn’t simply the instruction set that was suitable. The
360 computer systems additionally had standardized peripheral interfaces, which have been
suitable between machines.
There was an enormous marketplace for peripheral gadgets. IBM
themselves made 54 completely different gadgets equivalent to reminiscence, printers, card
readers, and so forth. The 360 additionally spawned a complete third-party peripheral
{industry}, very like the IBM PC-compatible period that began in 1981 and
continues to the desktop pc I am typing on proper now in 2023.

Moore wrote Forth from scratch in S/360 meeting.

Then…

Forth ported to the Honeywell 316
drawing of chuck using a honeywell 316computer

I drew Chuck behind the system on this one as a result of I could not
carry myself to obscure an inch of that wonderful pedestal console.

You may see the
Honeywell 316
(wikipedia.org)
and the brochure
(wikimedia.org)
picture from which I made my drawing.

Simply have a look at the space-age traces on that factor! It seems to be straight
out of a Star Trek set. Sadly, there’s principally no probability the one
Moore truly labored on had this console. Lower than 20 of them have been
offered. However due to my drawing, we will faux.

Past simply its look, this specific console has a extremely
wild historical past. The extravagant present firm, Neiman Marcus, truly
supplied the Honeywell H316 with this pedestal as a “kitchen pc”.
It value $10,000 and would have include a two-week course to study
enter recipes and stability a checkbook utilizing toggle switches and
lights to point binary information! (So far as anybody is aware of, none of those
have been truly offered.)

The advert for the Honeywell Kitchen Pc was in full “Mad Males”
mode and was extraordinarily patronizing, as was sadly typical for
the time. However for those who can look previous that, the entire thing is kind of
humorous:

“Her souffles are supreme, her meal planning a problem? She’s
what the Honeywell folks had in thoughts after they devised our Kitchen
Pc. She’ll study to program it with a cross-reference to her
favourite recipes by N-M’s personal Helen Corbitt. Then by merely pushing
just a few buttons receive an entire menu organized across the entree.
And if she pales at reckoning her lunch tabs, she will program it to
stability the household checkbook…”

You may see a tiny scan of the unique advert with a lady admiring
her new Honeywell Kitchen Pc that hardly suits in her kitchen
here
(wikipedia.org).

However shifting on from the pedestal…

The implementation of Forth on the H316 is taken into account to be the
first full, stand-alone implementation as a result of it was truly
programmed on the pc itself and was used to create different
Forths. It’s at this level that Moore has achieved a completely
ascendant system.

However wait, there’s moore…er,
sorry, extra!

As is typical for a Chuck Moore endeavor, this
telescope software pushed different new boundaries:
The system truly ran throughout two computer systems (we’re about to see
the second) and gave real-time entry to a number of astronomers.
As a result of it unfold the load the best way it did, there have been no points with
concurrency, which is one thing we programmers wrestle with to this present day.

This real-time management and evaluation was principally a
luxurious accessible on no different system on the time.
Even Honeywell, the creator of those computer systems, had solely been in a position to
obtain essentially the most primitive concurrency for them and it was
nothing like this.

As ordinary, Moore was proper on the very crest of
computing along with his ultra-flexible Forth system.

…And ported to the Honeywell DDP-116
drawing of chuck using a honeywell DDP-116 computer

As talked about above, the Forth system was additionally ported to the
DDP-116
(t-larchive.org).
and used with its “guardian” system on the H316 featured above.

(The DDP-116 was initially manufactured by
Computer Control Company in 1965, however CCC was offered to Honeywell in 1966 and
turned its Pc Controls division.)

The DDP-116 was a 16-bit pc (the primary accessible for
buy), however nonetheless a part of that “second technology” of computer systems
we have talked about earlier than, with particular person
transistors and parts wire-wrapped collectively on enormous circuit
boards. (Take a look at the images on the DDP-116 hyperlink above for all
kinds of wonderful views of the insides and outsides of an instance
machine and its peripheral gadgets!)
It occurs to have additionally been a reasonably uncommon pc. It did not promote
in huge portions just like the IBM methods.

As you’ll be able to see within the drawing, Chuck Moore started to develop in energy as
his system developed and this manifested in further
arms
! Or possibly I began to get a little bit crazy whereas
drawing previous computer systems for these slides within the remaining evenings earlier than I
was as a consequence of give my discuss? I am going to let you determine what’s actual.

However wait, there’s another!

Forth on the DEC PDP-11

(Sure, that PDP-11.)
drawing of chuck using a DEC PDP-11 computer

The
PDP-11
(wikipedia.org) was by some measures the preferred minicomputer ever.

It was a 16-bit machine and had an orthogonal instruction set
(that means the identical instruction could possibly be utilized in a number of methods
relying on the operand. This makes the mnemonics of the instruction
set smaller and extra logical and far simpler to memorize).
This was much more highly effective as a result of I/O was memory-mapped, so the
identical directions used to maneuver values round in reminiscence and
registers may additionally be used to switch information to
and from gadgets.

All advised, these conveniences made the PDP-11 enjoyable to program!
Meeting language programmers rejoiced. The concepts within the PDP-11 unfold
quickly and are to be present in the preferred architectures in use
right now. In comparison with what got here earlier than it, PDP-11 meeting language will
look surprisingly acquainted to trendy meeting programmers.

The unique machines have been made beginning in 1970 with
wire-wrapped backplanes and discrete logic gates.
Later fashions launched “large-scale integration,” which is a time period
we’ll see later, so maintain that query!
These later variations of the PDP-11 have been nonetheless being
made twenty years later in 1990! There are apparently nonetheless PDP-11s
performing essential duties right now, with nuclear energy vegetation being considered one of
essentially the most outstanding examples.

It is laborious to see in my drawing, however the PDP-11 entrance panel is one
of essentially the most iconic pc interfaces ever made. Hobbyists make
working fashions, together with ridiculously cute and superior miniature
variations. Listed below are two mannequin variations – click on on them to go to the
authentic wikipedia.org recordsdata, the place you’ll be able to admire their full magnificence:

pdp11 panel1
pdp11 panel2

It might be tough to overstate the affect of this machine.
Most likely essentially the most well-known piece of software program launched on the PDP-11
was the primary model of
Unix
(wikipedia.org)
that really bore the identify “Unix”.

It was additionally the birthplace of the
C
(wikipedia.org)
programming language.
Dennis Ritchie ported Ken Thompson’s B language to the PDP-11 to
reap the benefits of its talents. Unix was then re-written in C
beginning with Model 4.
So the Unix we all know right now and a big portion of the command line
utilities which can be commonplace with a Unix-like system have been programmed
on the PDP-11. (And you’ll thank Richard Stallman’s GNU challenge for
liberating these for the lots. GNU stands for “GNU’s Not Unix!”)

You will additionally observe that Chuck Moore has gained his
fourth and remaining arm in my drawing above
(“fourth,” ha ha).
This may increasingly or could not replicate precise occasions.
Additionally, I am unsure if Moore would have been utilizing a video terminal at
that point. It is doable. DEC’s first video terminal was the
VT05
(columbia.edu),
which got here out in 1970.

All of this porting of Forth to new machines is feasible due to
oblique threaded code.
an abstract drawing of boxes and arrows representing threaded code in memory

“Threaded code” on this utilization is not
associated to concurrency, i.e. “multi-threaded programming”.

It is code that’s composed of subroutines addresses.

Threaded code may be machine code or interpreted.

Wait, aren’t most applications composed of calls to subroutines?

That is true. The large distinction is that
threaded code
(wikipedia.org) on this sense
would not truly comprise the directions to name the
subroutines. It shops simply the addresses.
Subsequently one other routine is chargeable for advancing
a pointer over the tackle
record and executing the subroutines.

Huh?

Yeah, there is not any manner round it, threaded code is sophisticated.

And oblique threaded code is much more sophisticated (and
tougher to clarify).

“Hey, wait!” I hear you saying. “If Chuck hates complexity so
a lot, why did he use such a fancy methodology for Forth?”

That is utterly honest.

However earlier than we tackle that, I am going to attempt to briefly clarify how
threaded code is saved and executed.

First, this is how regular machine code may be written:

Direct calls (not threaded):

jmp 0x0804000
jmp eax
    

That is the best sort of “name” to retailer in a program.
We merely have the jmp (bounce) instruction adopted
by the tackle to leap to.
Right here I present each a hard-coded tackle
(0x0804000) and a register
(eax).
Each of those are “direct” for our functions.

Alternatively, many processors have a extra superior name
instruction. A name is extra sophisticated as a result of it has to do further
work behind the scenes. It should retailer a return tackle on “the stack”
earlier than leaping to the required tackle. Then a ret
(return) instruction on the finish of the referred to as routine can use the
saved tackle to renew the execution simply after the “name website” the place
the decision was first made. Why are return addresses saved on a stack?
That is as a result of you’ll be able to nest calls. Pushing addresses as you bounce and
popping them in reverse order as you come back retains issues good and neat.
This “the stack” just isn’t what Forth refers to as “the stack”. Forth’s
principal stack is best referred to as “the parameter stack”. Many Forth
implementations additionally have a return stack!

Anyway, that is direct and it is not threaded. Simply bounce to an tackle.

Step one of complication is including indirection.

Oblique calls (not threaded):

jmp [eax]
    

For this instance to make sense, it’s essential to know that the
sq. brackets across the register ([eax])
is a typical meeting language conference which means
“the worth on the reminiscence tackle that’s saved in register eax”.

So jmp [eax] means “bounce to the tackle
saved on the tackle saved in register eax.”

That is oblique.

So now we’ve the “oblique” a part of “oblique threaded
code.” However what is the “threaded” half?

Storing threaded code:

<addr pointing to code>
<addr pointing to code>
<addr pointing to code>
<addr pointing to code>
    

As a substitute of containing the precise directions to leap or
name subroutines:

jmp 0x0804000
jmp 0x080A816
jmp 0x08C8800
jmp 0x08C8DD0
        

Threaded code shops simply the record of
addresses:

0x0804000
0x080A816
0x08C8800
0x08C8DD0
        

There are two penalties of storing code like this:

  • The tackle record takes up much less reminiscence than the total code to
    make the bounce. (Actually, it takes a lot much less on some
    historic machines.) That is good.
  • Some kind of “code interpreter” will should be written to
    execute this record. You may’t simply ship an inventory of addresses
    to a processor and count on it to work. This could possibly be good or unhealthy.

One other manner to take a look at the record of addresses above is that,
conceptually, threaded code is principally an inventory of subroutines.

To finish our definition of “oblique threaded” code, we simply
must put each ideas collectively:

Storing oblique threaded code:

<addr pointing to addr pointing to code>
<addr pointing to addr pointing to code>
<addr pointing to addr pointing to code>
<addr pointing to addr pointing to code>
    

That is the place it will get fairly loopy. So now we have a second
stage of indirection. Why on Earth would we do that?

Effectively, this permits us to retailer a separate “code interpreter”
(or “interior interpreter”) for various varieties of subroutines!

As a substitute of pointing instantly at subroutines, these addresses level
at interpreters.
Discuss final flexibility – each subroutine in an oblique
threaded program can have its personal {custom} interpreter for the remainder
of its directions…every of which can be threaded…or
not directly threaded!

However what calls all of those interior interpreters?
An outer interpreter, after all! The outer interpreter is the
half we truly work together with once we sit right down to sort
at a Forth terminal.

In Forth, oblique threaded code is an inventory of
addresses pointing to the “interior interpreter” parts of
phrases, which execute the remainder of the phrase.
What sorts of interior interpreters may we’ve, anyway?
Effectively, for instance, we’d have one type of phrase that shops a string
in reminiscence and one other that executes machine code. However the one
restrict is your creativeness.

Make sense?

I personally wouldn’t have understood
that clarification in any respect till a lot later in my journey (I do know this
as a result of comparable – most likely higher – explanations flew proper over
my head). Little question you are quicker than me at apprehending these items
and are already midway by means of implementing your personal Forth based mostly on
these descriptions.

None of the remainder of the fabric requires understanding any
of the above, so please do not feel it’s essential to totally
grok
(wikipedia.org)
it earlier than persevering with. Oblique threading is a crucial a part of
Forth’s historical past, however there are many Forths that don’t use it.

drawing of a minicomputer saying 'i have 16k of core!'

Threaded code was far more frequent within the days of yore.

It is vitally dense, compact on disk and in reminiscence.

Along with its compact storage, threaded code
would have been much more environment friendly on the modern
machines throughout Forth’s gestation as a result of
calling subroutines typically wasn’t so simple as the
name instruction discovered on “trendy” architectures.

Subroutine and procedure call support
(clemson.edu) by Mark Smotherman explains:

“1963 – Burroughs B5000 – A stack-based pc with assist for
block-structured languages like Algol. Parameters and return tackle
are saved on the stack, however subroutine entry is a reasonably complicated
operation.”

So the reminiscence and efficiency enhancements of this fashion of
subroutine name have been probably
very nice certainly. This is without doubt one of the causes for Forth’s
legendary status for top efficiency
.

We’ll revisit this matter from one other angle quickly. However for those who’re
serious about these mechanics
(and need to see the origin of the bins and arrows
drawings on the prime of this part), take a look at this multi-part
article collection for The Pc Journal,
MOVING FORTH Part 1: Design Decisions in the Forth Kernel
(bradrodriguez.com),
by Brad Rodriguez.

The essential factor is that we have now totally traced the origins
of Forth from a easy command interpreter to the full-blown
interactive language, editor, working system, and
methodology of code storage and execution
it turned.

drawing of chuck moore as a superhero with a cape and bowtie

That is Forth’s origin story.

  • Postfix notation (RPN)
  • Stack-oriented
  • Concatenative programming fashion
  • Interpreted
  • Extremely adaptable to machine architectures
  • Extraordinarily compact

This provides us the why.

Ultimately! Now we will put all of it collectively:

Forth is postfix as a result of that is a pure
order for the pc and lends itself to an extremely minimalistic
interpreter implementation: get the values, function on them;

Forth is stack oriented as a result of that is a
compact and handy technique to retailer
values while not having so as to add variables or identify issues;

Forth is concatenative as a result of constructing a
language that may function as a string of phrases is extremely
versatile and may adapt to simply about any programming fashion with out
any assist from the language itself. (And it seems that is
very true while you throw in higher-order capabilities);

Forth is interpreted as a result of that’s
interactive and permits the programmer to make quick adjustments on
the fly or just “play” with the system. That is a part of
Forth’s adaptability and suppleness;

Forth is self-hosting as a result of you’ll be able to
bootstrap a Forth implementation from a handful of phrases
applied in meeting after which write the remainder in Forth;

Forth is extraordinarily compact as a result of machines at
the time had restricted reminiscence and this gave Forth an edge on
different interpreters (and even compiled languages!) on
mainframes and mini-computers.

Now that we’ve every part in historic context, I feel it is
a lot clearer why Forth exists and why it takes the peculiar
type that it does.

None of this was deliberate. Chuck did not sit down at a terminal
in 1958 and conjure up Forth. As a substitute, he grew a system to
serve his wants and to make use of recent {hardware} because it was made
accessible.

Studying about Forth’s historical past is an excellent technique to perceive
what makes Forth particular and what it is about.

However even figuring out all of this, I used to be nonetheless a good distance off from a real
understanding of how this all comes collectively in an
precise working system. I did not actually perceive the way it labored.
And I did not perceive what Forth was truly prefer to use
In different phrases, I nonetheless did not perceive Forth as a
programming language.

Someplace alongside the best way, I got here throughout these quotes…

“To grasp Forth, you need to implement a Forth.”

— Any individual on the Web

And

“Check out JonesForth.”

— All people on the Web

I’ve talked about it earlier than, however I am going to level it out once more. Discover the
phrasing “implement a Forth.”

As we have established, Chuck Moore believes a Forth system is finest
when it’s custom-tailored to the system and activity at hand. So it
ought to come as little shock that writing your personal Forth or Forth-like is
fully “par for the course” in any would-be-Forther’s quest to
uncover the True That means of the language and enter the paranormal realm
the place All is Revealed.

Effectively, what else may I do?

Having no different clear course of research, I made a decision to heed the
knowledge of the gang.

Presenting…

My faithful Asus EeePC 701 waiting romantically on the bed. Text reads 'Assembly Nights'

To essentially get to understand it, I took Forth to mattress with me.

I wrote
Assembly Nights
once I realized how a lot I used to be having fun with myself:

“During the last three months, I’ve developed an uncommon
little nighttime routine…”

I ready myself for coping with the JonesForth supply
(i386 meeting language within the GNU GAS assembler)
by studying some meeting and Linux ABI fundamentals.
JonesForth is 32-bit solely and makes use of the Linux system name (“syscall”)
ABI instantly.

Then I spent roughly a yr porting JonesForth into an entire
working copy in NASM assembler. (Sure, that is a “port” from one taste
of i386 asm to a different.)

I did a tiny bit nearly each evening. A whole lot of it was debugging in
GDB.

my giant gold on gray logo for nasmjf

My NASM port of JonesForth: nasmjf

Opening the third eye by (re)implementing Forth.

This is the
nasmjf web page

Within the technique of writing the port, I realized how a conventional
oblique threaded Forth works.

And I realized that it takes time to soak up such a
twisty-turny methodology of code execution.

Particularly if the x86 meeting language tips are new to you want
they have been for me.

JonesForth ascii artwork:
jonesforth ascii art explaining flow of threaded code

One of many first stuff you encounter while you open up the
jonesforth.S (a single file which comprises the meeting
language portion of JonesForth) are many ASCII artwork diagrams.

Richard W.M. Jones does a wonderful job of strolling you thru
the workings of the interpreter and explaining the i386 instruction
set options he makes use of.

If the diagram above appears bewildering, I agree.

So, after all, I believed possibly I may do higher…

This is my try (from the nasmjf supply):
my nasmjf ascii art explaining flow of threaded code

After I used to be completed with my port, I attempted to make an ASCII artwork diagram
of my very own to seize my new understanding.
Actually, that is considered one of a number of.

With the good thing about the gap of time, it’s clear to me that
this stuff solely make sense when you already perceive them to
a point. However the act of making them is extraordinarily helpful
for solidifying your understanding.

However wait, there’s extra!

Each ASCII artwork diagrams above are simply half of the entire
oblique threaded execution system. They’re simply displaying how the “interior
interpreter” works to execute Forth phrases.

Maybe you recall from the part about oblique threaded code
above that the second stage of indirection permits completely different
“interpreter” routines to execute several types of threaded
subroutines? Effectively, that is all these two ASCII diagrams are attempting
present.

However once we say that Forth is an interpreted language,
this isn’t what we’re speaking about. There’s additionally the “outer interpreter”
that the programmer interacts with.

The oblique threaded code is simply the tip of the iceberg!

nasmjf interior/outer interpreter diagram:
my nasmjf diagram showing outer and inner interpreter

Within the vector picture I made above for nasmjf, I tried to map out
the entire factor in my very own phrases.

In case you take something from this picture, it is that
INTERPRET seems to be up phrases (capabilities) by identify and calls
them by executing the interpreter routine whose tackle is saved in
the phrase (once more, that is the oblique threading half). In flip, there
could also be any variety of interpreters, however the three principal sorts utilized in
JonesForth are:

  • Pure meeting language routines are their very own interpreters.
  • “Common” Forth phrases use the DOCOL interpreter.
    DOCOL executes the remainder of the threaded code within the phrase,
    most of which is only a record of addresses, however a few of
    which will likely be information. That is the “regular” type of threaded
    subroutine.
  • Numeric literals have a tiny interpreter routine inline with
    the information that simply pushes their worth to the stack. Numeric
    literals do not must be phrases, although, in JonesForth,
    they’re only a little bit of inlined machine code.

However even figuring out this solely helps to clarify how code begins
executing. How does one of these Forth know what to run after a phrase is
full?

Ah, for that we’ve this:

To get from one code phrase to a different requires a little bit of
meeting pasted on the finish of every one. That is
the NEXT macro. Right here it’s from nasmjf:

%macro NEXT 0
    lodsd     ; NEXT: Load from reminiscence into eax, inc esi to level to subsequent phrase.
    jmp [eax] ; Leap to no matter code we're now pointing at.
%endmacro
    

Discover the time period “code phrase”. That is the Forth time period for phrases
written in pure meeting language.

Each code phrase has this macro on the finish. (Some Forths truly
name a subroutine for this. JonesForth makes use of this two-line macro
as a result of the motion is so environment friendly in i386 machine code.)

Keep in mind the record of addresses within the clarification of
“oblique threaded” code? That is how we execute them sequentially.

This implementation makes use of the i386 lodsd instruction
to handle two operations in a single: transfer a “double phrase”
from reminiscence right into a register, after which replace one other register
in order that it factors to the following “double” spot in reminiscence.

(Rant: And a “double” is 32 bits on Intel chips for the actually
annoying motive that they stored the definition of “phrase” at 16 bits
even because the platform moved to 32 after which 64-bit structure. So
“phrase” on Intel architectures is a totally meaningless factor
that you just simply must memorize as “16 bits” although
“phrase” is meant to be the native information measurement of the structure.
And what’s worse is that the instruments for working with applications on
Intel chips like GDB then check with every part with the
corresponding C names for every part, which naturally assumed that
the structure names could be based mostly on actuality. However they are not.
So phrases like “double” and “lengthy” are principally simply completely
nugatory legacy rubbish to memorize and helpful solely to C and Intel
structure veterans.)

Okay, so now the eax register factors to the following
threaded subroutine tackle in reminiscence. The jmp begins
executing no matter that factors to, which would be the “interior interpreter”
for that subroutine.

Bought that?

A whole lot of shifting elements, proper?

There’s extra:

To get from one colon phrase to a different makes use of a little bit of
meeting pasted on the finish of every in a bit referred to as
the EXIT macro. Right here it’s from nasmjf:

DEFCODE "EXIT",EXIT,0
    POPRSP esi            ; pop return stack into esi
NEXT
    

Keep in mind, there’s two elementary sorts of phrases in a
conventional Forth like JonesForth:
“Code” phrases and “colon” phrases.
Code phrases are primitives written in machine code. Colon phrases are
the “common” phrases truly written within the Forth language.

These “colon” phrases (so-named as a result of they’re assembled
by way of the “COLON” compiler, which we’ll speak about in a second),
all finish within the so-called EXIT macro.

The EXIT macro handles the return stack. Then
there will likely be a NEXT after that to conclude no matter code
phrase primitive we have been in (we’re at all times in a minimum of one as a result of the
“outer-most” interpreter is a code phrase primitive!), so the
course of we described above will robotically begin the place we left off
on the “name website” of the phrase we
simply completed executing.

In case you weren’t misplaced earlier than, certainly this may do the trick?

I do have one other try to clarify how this all nests in
a kind of indented pseudocode:

My remark in nasmjf trying to clarify the
execution of oblique threaded
code as a nested
sequence of NEXT and EXIT and QUIT:

; QUIT (INTERPRET)
;     * common phrase
;         DOCOL
;         NEXT
;         * common phrase
;             DOCOL (codeword
;             NEXT
;             * code phrase
;                 <machine code>
;             NEXT
;             * code phrase
;                 <machine code>
;             NEXT
;         EXIT
;         NEXT
;    EXIT
;    NEXT
; QUIT (BRANCH -8 again to INTERPRET for extra)
    

This nested view of the method is as shut as I’ve ever been to
explaining (to myself) what the complete execution stream
seems to be like at a excessive stage.

I am certain each Forth implementer has their very own psychological mannequin.

You will discover we did not even speak about QUIT.
Apart from the identify, that one’s not practically as unhealthy – it is actually
simply the tip of the outer interpreter loop.

(So, yeah, we’ve EXIT and
QUIT, neither of which go away Forth… Hey, it was the
Nineteen Sixties. Issues have been completely different then.)

Completely nothing else drives the stream of an oblique
threaded Forth software: It is addresses saved in
registers, a return stack, and a handful of meeting directions
on the finish of every machine code phrase leaping to the following instruction.

It is like a fragile clockwork machine.

Do not you see how easy it’s?
drawing of chuck as crazy charlie explaining a theory with wild eyes and a wall covered in paper and strings

Historic observe: The above “Loopy Chuck” drawing is a parody of
a preferred meme with actor Charlie Day’s character within the episode
“Candy Dee Has a Coronary heart Assault” from the present It is All the time Sunny
in Philadelphia
:

“Each day Pepe’s mail’s getting despatched again to me. Pepe Silvia, Pepe
Silvia, I look within the mail, this entire field is Pepe Silvia!”

You, citizen of the distant future, is not going to have acknowledged this
parody, however a minimum of now you’ll be able to look it up.

Forth is complicated when taken as a complete. However it’s fabricated from tiny
items, every of which is very easy. The idea was created
over a interval of years on very constrained methods.
Every half created solely as wanted.
an abstract drawing of boxes and arrows representing threaded code in memory

I am going to repeat your query from earlier than so you do not have to:


“Hey, wait! But when Chuck hates complexity so
a lot, why did he use such a fancy methodology for Forth?”

That is the place the historic context is, as soon as once more, very revealing:

As we have seen, Charles H. Moore didn’t create Forth suddenly in a
single lightning bolt of inspiration.
It started as a easy command interpreter and executor and grew
from there.
It has at all times consisted of tiny little elements, working collectively.

Every of those tiny elements is very simple by itself.

And every was added over a time frame as the necessity arose.

I feel that is the genius of Forth: That every one of those little
items can work collectively to make a working system and but nonetheless
stay impartial
.
You may study every of those in isolation. You may change them
in isolation.

Final flexibility and ease on the lowest stage of
the implementation comes at the price of simple understanding at
increased ranges.

When rising a system like this, most of us would have thought
greater, Moore thought smaller.

Let’s do the identical.
I’ve thrown the phrases “code phrase” and “colon phrase” round so much.
I’ve defined them a bit, however we have by no means given a correct introduction.

Let’s go small:

Once more, Code phrases are primitives written in machine language
provided by the Forth implementation.

Let’s examine some actual code phrases so we will de-mystify them
as soon as and for all. These are very simple
and very concrete examples of precise NASM meeting language supply
from my nasmjf port of JonesForth:

Small and easy:

DEFCODE "SWAP",SWAP,0
    pop eax
    pop ebx
    push eax
    push ebx
NEXT
    

Is that actually SWAP? Sure, it truly is! We’re simply telling the
CPU to pop the 2 most up-to-date values from the stack after which push them
again within the reverse order.

(JonesForth makes use of the i386 name/return stack as a Forth parameter
stack so we will use the native “pop” and “push” to make these
operations simple. In change, we lose the power to make use of “name”
and “ret” for subroutines.)

The DEFCODE macro is housekeeping – it creates the
entry’s header within the Forth phrase dictionary.

Discover the NEXT macro we talked about beforehand?
Keep in mind, that is simply one other two traces of meeting pasted on the
finish of this routine.

Even Smaller:

DEFCODE "DUP",DUP,0
    mov eax, [esp]
    push eax
NEXT
    

We’re down to simply two directions now! We transfer the worth pointed
at by the esp register into eax after which push it onto the
stack.

To grasp why this duplicates the highest merchandise on
the stack, it’s essential to know the way the esp register is used.
This is the related remark from the JonesForth supply:

“On this FORTH, we’re utilizing the traditional stack pointer (%esp) for the
parameter stack. We’ll use the i386’s “different” stack pointer (%ebp,
normally referred to as the “body pointer”) for our return stack.”

Which implies that esp factors to the present prime of
the parameter stack. So pushing that worth on the stack duplicates
the highest worth. (This might even have been written extra clearly with
three directions: one “pop” and two “push”es.)

The Smallest:

DEFCODE "DROP",DROP,0
    pop eax
NEXT
    

Now we’ve a complete Forth phrase outlined as a single
instruction! DROP simply “removes” the highest worth from the stack. On this
case, we pop it into the eax register after which do not do
something with it, primarily throwing it away. (Alternatively, we
may have decremented the esp register, however on this case,
the “pop” is each shorter and clearer.)

Now let’s have a look at these three phrases in motion in a actual
Forth program that strikes some actual numbers round
in reminiscence…

8 7      8 7
SWAP     7 8
DROP     7
DUP      7 7
    

The code phrase primitives we have simply outlined are utilized by the
remainder of the Forth implementation to outline colon phrases within the
language itself. In case you write Forth purposes, your personal
colon phrases will most likely use these closely.

You may as well name them interactively within the interpreter.

The above instance exhibits what it may be like to make use of these
three primitives proper on the keyboard. The column on the precise
exhibits the state of the parameter stack after every line of enter.

Other than pushing the 2 numbers on the stack (8 7)
, we have now seen the meeting language code for your entire
program proven above. That makes this beautiful “naked steel” stuff, proper?

This is the walk-through:

  • We begin with 8 after which 7 on the highest of the stack.
  • SWAP reverses the order of the stack so 8 is now on the highest.
  • DROP pops the 8 and throws it away. Now solely 7 stays.
  • DUP pushes a second copy of seven onto the highest of the stack.

Once more, these directions may exist within the definition of a phrase or
you possibly can sort them interactively within the working Forth interpreter.
The end result is similar.

I feel there’s one thing fairly magical about realizing that
typing these directions is working particular machine code
sequences precisely as they have been entered. On this implementation,
there is not any optimizing compiler or digital machine performing as middle-man.
You actually are speaking instantly with the processor.

nasmjf has 130 code phrases. Principally for effectivity.

In case you weren’t already questioning, maybe you at the moment are:
What number of Forth phrases should be outlined in machine code
to have a “bootstrappable” Forth system?

There are some theoretical minimums. However as you get right down to an
absurdly small variety of directions, the Forth code written with the
primitives (to implement the remainder of the language) approaches absurdly
giant quantities of convolutions that check the boundaries of each programmer
ergonomics and computational inefficiency.

Take a look at this wonderful article by Frank Sergeant:
A 3-INSTRUCTION FORTH FOR EMBEDDED SYSTEMS WORK
(utoh.org).

“What number of directions does it take to make a Forth for
goal growth work? Does reminiscence develop on timber? Does the associated fee
of the event system come out of your personal pocket? A 3-
instruction Forth makes Forth inexpensive for goal methods with
very restricted reminiscence. It may be introduced up shortly on unusual new
{hardware}. You do not have to do with out Forth due to reminiscence or
time limitations. It solely takes 66 bytes for the Motorola MC68HC11.
Full supply is supplied.”

You learn that proper: 66 bytes.

And later:

“Absolutely the minimal the goal should do, it appears to me,
is fetch a byte, retailer a byte, and name a subroutine. All the things
else may be completed in high-level Forth on the host.”

Which jogs my memory, do you know there may be such a factor as a
one-instruction set computer
(wikipedia.org)?
And after all you’ll be able to run Forth on them:
16-bit SUBLEQ eForth
(github.com).

However that is nuts.

How about one thing a little bit extra lifelike?

sectorforth has 10 code phrases.

Cesar Blum’s
sectorforth
(github.com)
is:

“…a 16-bit x86 Forth that matches in a 512-byte
boot sector. Inspiration to put in writing sectorforth got here from a
1996 Usenet thread.”

See? There’s Usenet once more. It wasn’t simply me studying all that lore.

The creator’s
posting of the project to the Forth sub-reddit
(reddit.com)
has further perception:

“I’ve at all times been fascinated by the thought of getting a
minimal kernel of primitives from which “every part” may be constructed.
Earlier than Forth, I had solely seen that within the type of Lisp’s “Maxwell
equations of software program”, which is cool, however at all times left me a little bit
dissatisfied as a result of it’s too summary to construct one thing that you just
can truly work together with – you’ll be able to’t escape of its esoteric
nature…

With Forth, nonetheless, you can begin from nearly nothing, and begin
including issues like ifs, loops, strings, and so forth., issues that look extra
like your day-to-day programming. I discover that there is a whole lot of
magnificence in that.”

Notice: The assertion about Maxwell’s equations certainly refers to
Alan Kay’s well-known quote about LISP from
A Conversation with Alan Kay
(acm.org):

“Sure, that was the massive revelation to me once I was in graduate
faculty – once I lastly understood that the half web page of code on
the underside of web page 13 of the Lisp 1.5 handbook was Lisp in itself.
These have been “Maxwell’s Equations of Software program!” That is the entire
world of programming in just a few traces that I can put my hand over.”

Okay, so we have talked about code phrases
which can be simply chunks of machine code that may be referred to as upon
at any time.

Now let’s have a look at what colon phrases are all about…

Let’s make one:

: SDD SWAP DROP DUP ;
    

A colon phrase is so-named as a result of its definition begins with the
:” character.

The instance colon phrase definition above creates a brand new phrase referred to as
SDD that may be a composition of the three code phrases we
outlined earlier: SWAP, DROP, and
DUP.
Maybe the phrase “composition” brings to thoughts the concatenative
terminology we explored earlier on this quest?

As this instance demonstrates, colon phrases are outlined fully
by different phrases, which can be code phrases or different colon phrases.
You may as well have numeric values, e.g. 8 and seven, which
are dealt with by the interpreter.

(You may as well have strings, which seems to be like information…however these are
simply enter that occurs to observe one of many particular phrases, e.g.
." (dot quote), that is aware of deal with the enter!)

Let’s examine it in motion:

8 7      8 7
SDD      7 7
    
The impact of calling our new SDD phrase is, after all,
equivalent to calling the three separate phrases SWAP,
DROP, and DUP in sequence.

In oblique threaded code phrases,
this colon phrase has been “compiled” into the addresses of
the “interior interpreters” for every of the three code phrases.
However be happy to disregard this element!

Let’s demystify this additional as a result of the Forth “compiler” is
most likely a lot, a lot less complicated than you’d assume:

This is what actually occurs once we enter this:

: SDD SWAP DROP DUP ;
    

Colon (:) fetches the phrase identify (SDD) and units “compile mode”.

Semicolon (;) completes the phrase’s entry within the dictionary and unsets “compile mode”.

It would nonetheless be shocking that “:” is a Forth phrase.

It seems to be just like the kind of factor we might name “syntax” in different
programming languages, but it surely actually is not. It is a phrase.

You may even change “:” with your personal definition
to increase or alter Forth to do your bidding!

It could be laborious to totally grasp for some time, however
Forth’s solely
syntax is the whitespace between tokens of enter.

Tokens are tokenized by a phrase referred to as “WORD”, which is an
extremely complicated overload of the time period. Sorry.

(You will additionally discover I’ve talked about the time period “dictionary” a pair
instances now. It is type of apparent {that a} dictionary can maintain phrases, however
I have not correctly defined the Forth dictionary but. Don’t be concerned,
we’re nearly there.)

Okay, so “:” switches the “outer interpreter” into
compile mode and ; switches it again. However what does
that imply?

“Compiling” in Forth means placing considered one of two issues into reminiscence:

  • The tackle of a phrase, or
  • A worth literal and a little bit of code that pushes it on the stack

At its easiest, compiling is rather like executing, however we’re storing
addresses as an alternative of leaping to them.

Truly, that is understating the magnificence and ease of how this
works, which is without doubt one of the most mind-blowing issues in Forth.

Forth makes use of the identical interpreter to each compile
and execute code!

In a conventional Forth, the interpreter executes phrases as you
enter them. Except you are in “compile mode”, then it’s
compiling these phrases as addresses into reminiscence on the fly
as you enter them.

It is straight from the keyboard to reminiscence.

To make this concrete, let’s step by means of the instance.

This is our definition once more:

: SDD SWAP DROP DUP ;
        

In “regular mode”, the interpreter is executing every part as we enter it.

When the interpreter encouters the “:” phrase, we’re
nonetheless in “regular mode”, so it seems to be “:” up within the
dictionary, finds it, and executes the phrase. The definiton of
:” will accumulate the identify “SDD” and activate the “compile
mode” swap.

Now when the interpreter hits the “SWAP” phrase, it would
search for its tackle within the dictionary as ordinary, discover it, and
retailer the tackle within the subsequent accessible reminiscence slot the place we
compile new phrases (an important built-in variable referred to as
HERE” retains monitor of this reminiscence place).

The identical factor occurs for “DROP” and “DUP“.
We’re compiling as quick as we will sort!

Then a bunch of actually fascinating issues occur when the interpreter
will get to “;” (SEMICOLON).

First, “;” is seemed up and located within the dictionary and
then…Hey, wait!
Why is not the tackle of the “;” phrase
additionally compiled into our new definition? That is a
nice query!

Time for one more trick. One of many flags saved in a phrase’s
dictionary entry is the “quick” flag. When this flag is turned on,
the phrase is at all times executed instantly
even in compile mode.
The “;” phrase is a direct phrase, so it executes as an alternative
of being compiled.

(Able to have your head turned inside-out? There are additionally
tips for compiling quick phrases into phrase definitions!
It is easy sufficient, however nonetheless fairly mind-bending stuff while you first
encounter it.)

The definition of “;” turns off compile mode. Then it
does some housekeeping to finish the entry of the brand new
SDD phrase within the dictionary.

As quickly as “;” returns management to the outer
interpreter, we’re now sitting in regular mode once more and our new
SDD phrase is obtainable to be referred to as instantly or compiled
into different phrases.

See what I imply? It is all made of those tiny little elements.

Every half is extremely easy, however making an attempt to clarify how the
elements match collectively takes paragraphs of textual content.

Talking of easy…

The tiny algorithm that govern the interpreter:

  • WORD will get a token.
  • Is it within the dictionary? (And are we compiling?)
  • Is it a numeric literal? (And are we compiling?)
  • In any other case, error!

Let’s take a look at our instance code once more. The primary line
runs, the second line compiles:

8 7 SWAP DUP DROP

: SDD SWAP DROP DUP ; 8 7 SDD
    

It might be annoyingly redundant to stroll by means of the 2 traces of
Forth above step-by-step as a result of they’re practically equivalent. The one
distinction is that the primary line merely executes every phrase as it’s
encountered (SWAP, DUP, DROP). The second line compiles these three
phrases into a brand new phrase referred to as SDD. The results of each traces is similar.

Solely the numbers (8 and seven) and the areas separating phrases have
any particular that means to Forth’s “outer” interpreter.
All the things else is seemed up within the dictionary.

Ah, however did you discover the order of the bullet factors above?
We examine to see if a token is within the dictionary earlier than
we examine to see if it’s a numeric literal. Sure, even numbers are
seemed up within the dictionary first! Does that maybe provide you with any concepts
about that magic trick I promised in the beginning of this text?

Moreover, enter just isn’t returned to the primary Forth “outer”
interpreter till a dictionary phrase completes executing. So there may be
completely no restrict to the sorts of
domain-specific language
(wikipedia.org)
you’ll be able to create.

And if that weren’t sufficient, You may as well change each single piece
of the Forth interpreter itself. Keep in mind, they’re all impartial little
cogs within the machine. Forth is the last word freedom.

I’ve alluded to this in a number of other ways above, however I am going to make
a daring declare:
Forth has the best syntax and subsequently the best
parser, interpreter, and compiler ever utilized in a “mainstream”
general-purpose programming language.

Two different languages beforehand talked about, Lisp and Tcl, are additionally
famously syntactically minimalistic languages. Individuals have
written extremely tiny implementations of every:

Thoughts you, each of those folks (Justine “jart” Tunney and Salvatore
“antirez” Sanfilippo) are unimaginable programmers, however these examples
trace at what is feasible.

However Forth certainly takes the cake. Even a licensed non-genius
like myself can write a complete Forth interpreter in a
couple hundred meeting directions. (See “Meow5” beneath.)

Due to its excessive simplicity, tokenizing Forth may be completed in
a mere handful of meeting directions on many processors.

And as talked about, as soon as you have written a Forth interpreter, you are
nicely in your technique to a working Forth compiler.

I’ve alluded to Forth’s flexibility and extensibility on a number of
completely different events now. However that is no mere celebration trick. Forth
depends on the truth that you are able to do something in Forth.

Within the subsequent instance, we’ll see how Forth implements management buildings.

The definition of IF…THEN from jonesforth.f:

: IF IMMEDIATE ' 0BRANCH , HERE @ 0 , ;

: THEN IMMEDIATE DUP HERE @ SWAP - SWAP ! ;
    

This proper right here is without doubt one of the most mind-blowing issues about Forth,
and a strong motive to title this, “The programming language that writes
itself.”

Even one thing as elementary as IF is outlined in
the language! Forth just isn’t the one language that may do that, however
few languages invite the programmer to take part so totally
within the interior workings as typically or as joyfully as Forth.

Determining how the IF and THEN definitions above truly
work is left as an train for the reader, however this is a quick
clarification of the brand new phrases they use:

'       - will get the tackle of the phrase that follows, placed on stack
0BRANCH - department to the following worth if the highest of the stack has 0
,       - 'compile' the present stack worth to the reminiscence at HERE
@       - fetch worth from tackle on stack, put worth on stack
!       - retailer to reminiscence (stack comprises tackle, then worth)
        

(By the best way, I am going to go on the report to say this: The
early elements of bootstrapping Forth in Forth (a minimum of
the highest 25% of jonesforth.f) is considerably extra
mind-bending than implementing the low-level code phrase definitions
written in meeting language. Actually, any time I wanted to return to
the meeting, it was like a comforting blanket of simplicity in contrast
to the logic puzzle of these Forth-in-Forth primitives!)

However, even seeing management buildings like IF..THEN
applied within the language could not have ready you for seeing this
subsequent trick.

This could drive house the truth that Forth has nearly no native
syntax:

The definition of ( ) nested feedback from jonesforth.f:

: ( IMMEDIATE
    1
    BEGIN
        KEY DUP '(' = IF DROP 1+
        ELSE ')' = IF 1- THEN
        THEN
    DUP 0= UNTIL
    DROP
;

(
    To any extent further we will use ( ... ) for feedback.
...
    

Yeah, you learn that proper. Even feedback are applied
within the language! And you’ll re-define them or add your personal type of
feedback!

A few of you’re soiling yourselves in pleasure proper now.
A few of you’re soiling yourselves in worry.
We’re all simply sitting right here in our personal filth now.

And now, finally, we’re prepared to debate the facility of the Forth
dictionary.

A Forth dictionary historically makes use of a linked record.

Phrase matching is finished ranging from the finish
(most up-to-date entries) first, so:

  • You may redefine any phrase, even those initially
    outlined in meeting!
  • Phrases relying on earlier definitions of redefined phrases
    will not break as a result of the compiled addresses nonetheless level to
    the unique phrase, not the brand new definition!
  • You are in full management!
  • Once more, Forth = freedom!

It is not simply minimalistic syntax. Arguably, the
actual motive Forth is so extensible is due to
the dictionary.

As talked about within the factors above, newer phrase definitions
override older ones with the identical identify – the interpreter stops on the
first match.

However as talked about above, present compiled phrases that use the
previous definitions should not affected as a result of
identify of the previous phrase, they’ve saved the tackle.
The tackle of the previous phrase nonetheless factors to the previous phrase.

You do not have to strictly change. You may prolong
phrases by calling the unique phrase from a brand new one with the identical identify!

You might be maybe questioning what occurs if
you try to make a recursive phrase. By
default, ‘:’ (COLON) marks the phrase presently being compiled into the
dictionary as hidden or disabled in order that earlier definitions may be
referred to as, as talked about.
For this reason we’ve a phrase referred to as RECURSE which permits inserts a
name to the present phrase inside itself. As a result of all info
in Forth is world (together with the tackle of the present phrase being
compiled, defining RECURSE is extremely easy (simply 4 phrases within the
JonesForth definition).

Moreover making new management buildings or different sorts of extensions
to the language, what else can we do with these talents?

grayscale apple

It is not simply the language itself that’s unusually malleable.
Your program written in Forth may be versatile too.

Right here is an instance lifted and paraphrased from Considering Forth
by Leo Brodie.

Say we create a variable to carry a variety of apples:

VARIABLE APPLES
20 APPLES !
APPLES ? 20
	

Forth variables put addresses on the stack.

Notice: I’ve a bodily copy of Considering Forth as a result of
I feel it is nice. However the publishers have kindly made it accessible
at no cost on-line:
Thinking Forth (PDF)
(forth.com)

Let’s stroll by means of the three traces above. This is the primary line:

VARIABLE APPLES
        

The VARIABLE phrase creates a brand new spot in free reminiscence. Then
it creates a brand new phrase within the dictionary referred to as APPLES that pushes that
specific reminiscence tackle on the stack when it’s referred to as.

(Notice that like “:”, “VARIABLE” is grabbing the following token of enter
to be used as a brand new dictionary identify. That is doable as a result of “the little
cogs within the Forth machine” can be found for any use you’ll be able to consider.
And a type of cogs is the phrase WORD, which will get the following token from
the enter stream. Each “:” and “VARIABLE” use WORD to do that, similar to
Forth’s personal outer interpreter!)

Okay, so we’ve a variable named APPLES now. The subsequent line is:

20 APPLES !
        

This places the worth 20 on the stack, then the tackle for APPLES.
The “!” (STORE) phrase shops the worth 20 on the APPLES tackle.
(In different phrases, “!” takes two values as enter: an tackle and
a worth. It shops the worth at that tackle.)

Conceptually, you’ll be able to consider the above as APPLES = 20
in “regular” programming syntax.

And now the third line:

APPLES ?
        

This line prints the worth saved at APPLES. The phrase “?” fetches a
numeric worth from an tackle and prints it (which pops the worth off
the stack once more). Once more, APPLES places its tackle on the stack. So “?”
merely takes an tackle from the stack as enter for printing.

By the best way, this is your entire definition of “?” in JonesForth:

: ? @ . ;

Have a look at how small that’s! The one factor it’s essential to know to
perceive this definition is that “@” (FETCH) pops an tackle from the
stack and fetches the worth saved at that tackle and places the worth
on the stack. “.” (DOT) pops a worth from the stack and prints it as a
quantity.

Okay, on with our instance.

We’re about to be dealt a horrible blow…

We pepper our program with this APPLES variable.

The applying works completely for a pair years.

Then we’re advised that we should now maintain monitor of two completely different
sorts of apples: pink and inexperienced. What to do?

red apple
green apple

Sadly, that is precisely the kind of conundrum we see in actual
life software program on a regular basis.

You knowingly ready for all kinds of various portions
of apples, but it surely by no means occurred to anybody that we would want to
monitor completely different sorts of apples.

This downside appears very unhealthy. Do we’ve to utterly re-write our
software?

(Effectively, outdoors of this instance, the proper reply may be
“sure”. Possibly this adjustments the entire “principle” of this system, within the
Programming as Theory Building
(ratfactor.com)
sense. By which case, a re-write or huge refactor of our apple counting
program is probably going the precise reply. However for this instance, we’re
assuming that we’ve 1000’s of traces of
apple-handling performance that can not must
change. We’ll say that grouping the apples by shade right here is simply an
important floor element.)

All proper, clearly we won’t retailer two values in a single
variable and count on the entire present code to nonetheless work. So what
may we probably do?

This is a really intelligent and really Forth resolution:

A brand new variable will retailer the present sort of apples.

VARIABLE COLOR
	

As with “APPLES” above, VARIABLE creates a reminiscence house and a brand new
phrase referred to as “COLOR” that places the tackle of the reminiscence house on the
stack when it’s referred to as.

Subsequent, we’ll create a second new variable and a brand new colon phrase.

red apple

“REDS” will depend pink apples.
Colon phrase “RED” units the present sort of apple to pink:
COLOR = REDS:

VARIABLE REDS
: RED REDS COLOR ! ;
	

Keep in mind, variables are additionally phrases within the dictionary, so we have
created three further phrases up to now: COLOR, REDS, and RED.

(Solely considered one of these, RED, is recognizably a operate.
However actually all three of them are.)

As it’s possible you’ll recall from earlier, “!” (STORE) takes two parameters,
a worth and an tackle, and shops the worth at that tackle.

  • COLOR is the tackle of reminiscence holding the tackle of the present apple depend variable
  • REDS is the tackle of reminiscence holding the pink apple depend
  • RED units COLOR to the tackle of REDS

It may be useful to see the C equal of the RED phrase:

void RED(){
    COLOR = &REDS
}
        

After which…

green apple

Identical for inexperienced.

VARIABLE GREENS
: GREEN GREENS COLOR ! ;
	

We have added a complete of 5 new phrases. The 2 new inexperienced ones
are equivalent to the pink ones above:

  • GREENS is the tackle of reminiscence holding the inexperienced apple depend
  • GREEN units COLOR to the tackle of GREENS

This is the C equal of GREEN:

void GREEN(){
    COLOR = &GREENS
}
        

Yet one more change…

Lastly, we alter “APPLES” from a variable to a phrase that will get
the present depend by shade:

: APPLES COLOR @ ;
	

As it’s possible you’ll recall from earlier, “@” (FETCH) fetches the worth
saved in a variable and places it on the stack.

So “APPLES” will get the worth saved in COLOR and places that
on the stack.

The worth saved in COLOR occurs to be an tackle.
That tackle occurs to be the reminiscence pointed to by both REDS or
GREENS.

It might appear like this C code:

int *APPLES(){
    return COLOR;
}
        

This “get the tackle of the tackle” stuff could sound tremendous
complicated. However working with reminiscence addresses (aka “pointers”) is
how variables work in Forth, so to the adept Forth programmer,
the thought of passing addresses round will likely be deeply ingrained and
no huge deal.

Okay, so we have pink and inexperienced apple counts. That a lot
is obvious. However certainly there may be nonetheless a whole lot of work forward of us…

Now we’ve to re-write any use of APPLES, proper?

Improper! The usage of APPLES is equivalent. The syntax hasn’t
modified one bit for any present code. We simply want to ensure we have
set the precise shade.

Test it out:

20 RED APPLES !
30 GREEN APPLES !

GREEN APPLES ? 30
APPLES ? 30

RED
APPLES ? 20
	

All the present code that makes use of APPLES will nonetheless work
precisely the identical manner with completely no modifications.

Moreover, have a look at how English-like it reads to retailer
"20 RED APPLES !" or question "GREEN APPLES ?".

The important thing to understanding why this works is to do not forget that
“APPLES” was already a phrase that put an tackle on the stack
as a result of that is how variables work in Forth.
So once we modified it to a colon phrase that places an tackle on the
stack, it is no change in any respect. It is nonetheless doing the very same factor.
It simply occurs that the tackle will change relying on the lively
apple shade.

At each single alternative, Forth has taken the best
(you may even say, laziest) and most versatile methodology
for implementing a function.

Wait, I hear a distant screaming:

“How may this probably be okay?! You name this ‘freedom’, however
I name it unchecked chaos materials! This isn’t okay!”

Effectively, possibly.

However I feel one motive this truly is okay, on a
conceptual stage, is that APPLES did not actually change
what it initially did.

Coming from the traditional programming language world, we’ve clearly
damaged the abstraction:
“APPLES” was a variable earlier than, and now it is a operate.

However you are not within the regular programming world anymore.
Right here, in Forth-land, a variable is a phrase that places an
tackle on the stack. And a operate is additionally only a phrase.

“APPLES” is nonetheless a phrase that places an
tackle on the stack. There is no such thing as a conceptual change on the
language stage. We didn’t break an abstraction as a result of there
was no abstraction to interrupt.

Forth gives what you may name “atomic models of computing”
on the language stage. It’s a language the place you make the
abstractions.


grayscale apple

To Forth, it is all simply phrases in a dictionary.
“VARIABLE” is simply one other phrase
you possibly can have written your self.

Do you see now why Chuck Moore rejects the standardization
of Forth? It ossifies ideas like VARIABLE so that they lose their
flexibility.

The instance above can be one other demonstration of the best way
the language Forth “writes itself”: a tiny handful of primitives may be
used to bootstrap the remainder of the language within the language itself. The
huge flexibility of the primitives permits practically unbounded freedom.

I extremely suggest implementing Forth (or porting it like I did) to grasp
the way it works.

By inspecting Forth from the bottom flooring on the meeting language stage,
I gained appreciable confidence in my understanding of how all of the shifting
elements match collectively.

To be sincere, it is tough for me to think about being to in a position to perceive all of the
particular person elements with out going by means of this course of. However all people learns
in a different way.

“I did not create Forth, I found it.”

— Chuck, apocryphally

See Also

(I’ve been unable to discover a supply for the quote above.
It most likely comes from an interview.)

If Forth really is a elementary technique to specific computation, then
it is kind of like
Gödel and Herbrand’s common recursive capabilities, Church’s lambda
calculus, Turing’s theoretical machines, Publish’s canonical methods, and
Schönfinkel and Curry’s combinators.
(I can hear livid objections warming up from a thousand armchairs…)

Actually, that is true of all programming languages, even the
huge, messy ones. Proper? Any language that may specific common
computation is…universally highly effective; it might specific something
that’s computable.

However I feel Forth belongs to a extra rarified group. Forth is a
elementary sort of programming language design.
And I am not alone in considering so. For instance, take a look at
The seven programming ur-languages
(madhadron.com).

I am going to let philosophers angrily break up hairs over what I simply mentioned above,
however I feel the precept is true. And it is true all the best way down
to the (lack of) syntax within the language.

Why do I consider this? Effectively…

Making nasmjf gave me so many concepts, I had to strive some
experiments.

Forth is an incredible playground for concepts.

I used to be nonetheless keenly conscious that my nasmjf challenge to
port JonesForth to NASM was nonetheless only a (very detailed) examination of
a remaining artifact. I used to be not re-tracing Moore’s footsteps, however
imitating his work. In high quality artwork phrases, I made a “grasp copy” (coaching myself by
copying the work of a grasp artist). In different phrases, I introduced
my sketchbook to the museum.

However what would occur if I attempted making a portray of my very personal?

my lenovo 11e thinkpad with assembly code waiting romantically on the bed with a candle. text reads 'Assembly Nights II'

meow5 cat logo

An train in excessive concatenative programming the place
all code is concatenated (at all times inlined).

We explored what it means to be a “concatenative” programming language
originally of my journey above. In brief, in a concatenative
language, information implicitly flows from one operate to a different like a
manufacturing facility meeting line.

Like Forth, Meow5 occurs to be concatenative as a result of it makes use of
the identical “parameter stack” idea.

In contrast to Forth or most different sane languages, Meow5 is a thought
experiment taken too far
. Particularly, the thought,
“as an alternative of threading operate calls by storing their addresses, what
if we simply retailer a replica of the entire operate?

In compiler parlance, that is “inlining”, quick for
inline expansion
(wikipedia.org).
It’s a frequent optimization method
for avoiding the overhead of a operate name for small capabilities.

Let’s use the phrase DUP for instance. Keep in mind once we seemed on the
meeting language supply of the DUP code phrase? It was only a single
meeting instruction:

pop eax
        

It might be extremely foolish to have a number of jumps to and from
a single-instruction phrase!

(And, it comes as no shock that
“actual” Forth implementations typically inline small primitives such
as DUP. Some even present an INLINE phrase to permit the programmer
to specify this explicitly.)

My query was: What if we do this for every part?
At what level is that this not a good suggestion?
Clearly at some level, a operate is simply too giant to inline.
However each code phrase in JonesForth
was fairly tiny by trendy requirements. With right now’s CPUs and their
comparatively huge caches it appeared to me that you possibly can take
this inlining idea fairly far earlier than it obtained ridiculous.

And would not the CPU simply love seeing all of these directions
executing in a single straight and steady sequence with no jumps?
If I have been a CPU, I’d like it.

Plus, it could make compiling a stand-alone executable nearly
trivial as a result of each phrase in a 100% inlined language
would comprise all of the machine code wanted for that
phrase.

Right here is the canonical instance:

: meow "Meow." print ;
meow
Meow.

: meow5 meow meow meow meow meow ;
meow5
Meow.Meow.Meow.Meow.Meow.
	

The thought is that meow5 compiles into 5 full
copies of meow!

This instance appears to be clearly naughty and wasteful. However I am
not a superscalar, out-of-order executing trendy processor and neither
are you. So the query stays: At what level does having a
little one operate which features a full copy of each guardian and
grandparent and each ancestor operate all the best way again to the
starting spiral out of all sane proportions? Effectively, you possibly can spend an
afternoon figuring it out on paper, or you possibly can be like me and spend
the higher a part of a yr writing an meeting program.

Spoiler alert: I think about Meow5 to be a
pleasant little failure. The issue is not inlining machine code –
that works nice, and, certainly, the exported ELF executables from Meow5
work precisely as I imagined. The issue is information, and most
conspicuously, information within the type of strings. Let’s take the
meow phrase for instance: You both have to repeat the string
“Meow.” 5 instances, as soon as for every phrase that makes use of it, or go
by means of some sophisticated hoops to trace which phrase makes use of the string. And
you need to do this two other ways: Its location in reminiscence within the
reside interpreter and in it is vacation spot within the stand-alone ELF reminiscence
format. Both manner, the purity and ease is misplaced, which was the
entire level of the experiment. Additionally, it would come as no shock that I
later found that Forth implementations typically have an INLINE phrase
(as I discussed above), which is a significantly better technique to selectively
instruct the compiler about which phrases you want to copy fully. As a
program, Meow5 is a failure. However as a challenge, it’s a success
as a result of I realized so much.

Consider it as an artwork challenge.

Anyway, the level is…

Regardless of trying to go my very own manner,
it is exceptional what number of instances Forth’s resolution was the
path of least resistance.

Many times I’d say, “Aha! That is why.”

To begin with, you may discover I ended up utilizing “:” and “;” to
outline new capabilities.
Forth makes liberal use of symbols and abbreviations, which
could make it fairly laborious to learn. However I’ve to confess, “: … ;”
has grown on me. So I adopted that in Meow5. In order that’s most likely
essentially the most seen factor. However that is simply on the floor.

Secondly, utilizing a postfix notation is completely the trail
of least resistance for a stack-based language – every part is available in
the order anticipated by the language. So your interpreter may be
shockingly easy as a result of it might execute statements within the precise order
it will get them.

(Aspect observe: That is additionally how the
PostScript
(wikipedia.org)
printer and show language works. The printer can start printing as
quickly because it recieves the doc as a result of every part is outlined within the
order it’s wanted and by no means will depend on later info. This could
even be a drawback of PostScript for viewing paperwork on
screens: You may’t simply render a web page mid-document as a result of
styling and formatting controls have to be learn of their entirety from the
begin of the doc to the present web page as a way to make sure you’ve
obtained every part!)

I used to be decided to make issues simple for myself,
so I can say with some certainty that Forth is without doubt one of the
most “minimal effort” languages you’ll be able to think about.
If I may have considered a better (or lazier) technique to do one thing,
I’d have completed it!

There was simply one place I made a decision to deviate
from Forth although I knew it could make implementation tougher.

To make a string in Forth, you utilize the phrase ", which
wants an area after it to be seen as a phrase, which seems to be awkward:

" Whats up World."
    

This has at all times bothered me. Chuck Moore even admits this in
his unpublished e-book,
Programming A Problem-Oriented Language (PDF)
(forth.org)
within the part titled 6.3 Character strings:

“What does a personality string appear like? Of all of the methods you may
select, one is totally pure:

    "ABCDEF...XYZ"
            

A personality string is enclosed in quotes. It could actually comprise any character
besides a quote, particularly together with areas.”

Proper! So by golly, that is what I’d do in Meow5, like
each wise language!

Meow5 has this extra pure quoting fashion:

"Whats up World."
    

However the results are cascading. And so they restrict flexibility.

If we maintain studying Chuck’s phrases, he explains what is going to occur
for those who do that:

“We get in hassle instantly! How do you acknowledge a personality
string? By the main quote, after all. However do you modify your phrase
subroutine to acknowledge that quote? In case you accomplish that it’s possible you’ll by no means use a
main quote for another objective. A lot better that the quote is a
phrase by itself, handled like another dictionary entry, for it might then
be re-defined. However phrases are terminated by areas, and I nonetheless resist
making quote an exception. So let’s sort character strings:

    " ABCDEF . . . XYZ"
            

And he was proper, after all.

I ended up having to place exceptions for the " character in
a number of locations within the Meow5 interpreter, together with my
get_token operate, which serves the identical objective as
the “WORD subroutine” Moore talked about above.

And now all further interpreter options must work
round or duplicate the particular " character dealing with!

It appears one can both observe Moore’s recommendation or re-discover
it for oneself. As for me, I at all times take pleasure in re-discovering issues for
myself. One of the best half is that “aha!” second once I understand why
issues are the best way they’re.

Although, to flip this entire factor on its head, I truly assume it
was price the additional effort, hassle, and lack of purity to do
this! (I additionally included escape sequences, e.g. n and
", whereas I used to be at it.)

One other instance of straying from Moore’s recommendation
and having to find it for myself:

I made a decision to have a few of my capabilities go away the stack alone after utilizing
the highest worth.

Some capabilities are largely used to look at a worth, however they pop
that worth off the stack. To maintain working with the worth, you’ve got
to do a DUP to duplicate it first.

Since I used to be certain I’d at all times need to maintain the worth after these
specific capabilities, it appeared very wasteful to must do a DUP every
time. Why not simply peek at it and go away it on the stack?

Moore recommends simply popping every part so that you
do not have to recollect.

However I believed that was foolish. So I went forward and made some capabilities
that simply peek on the worth and go away it on the stack.

However as you will have guessed, he was completely proper.

Having some phrases pop the stack and a few phrases peek was a nightmare.
I stored forgetting which phrases did or did not alter the stack and it
stored inflicting issues. I utterly regretted it and ended up
making all of them pop like Moore suggested.

(Another choice that occurred to me after I modified all of them would
have been to have a particular naming scheme for non-popping phrases, which
most likely would have been high quality, count on then I’d have needed to bear in mind
the identify… so trouble both manner.)

Now we’ve one more motive for the title of this
article.

When you begin down the Forth path… the remainder simply kind of
“writes itself”.
Chuck Moore already discovered the trail of least resistance.

To sum up the methods through which “Forth writes itself” up to now, we’ve:

  • Forth is boostrapping
  • Forth is metaprogramming
  • Forth may be your OS and your IDE/editor
  • Forth is the trail of least resistance for writing a Forth

In case you got down to make the easiest doable interpreter
for a model new CPU structure, you may find yourself writing
a Forth whether or not you need to or not.

Forth allows you to outline extra Forth in Forth so that you
can Forth when you Forth. And the Forth editor is Forth
and may be prolonged with Forth, so can Forth Forth in Forth Forth Forth
Forth. (I am going to let you determine which of these are nouns, adjectives,
or verbs and whether or not or not I’ve the precise variety of them.)

And if that weren’t sufficient, Forths typically comprise assemblers
so you’ll be able to outline further code phrases in Forth, too so that you by no means
want to depart Forth when you’re in it.

JonesForth has the stub of an in-Forth assembler close to the tip so we
can see how one may work. This is the remark introducing it:

(
    ASSEMBLER CODE --------------------------------------------

    That is simply the define of a easy assembler, permitting
    you to put in writing FORTH primitives in meeting language.

    Meeting primitives start ': NAME' within the regular manner,
    however are ended with ;CODE.  ;CODE updates the header in order that
    the codeword is not DOCOL, however factors as an alternative to the
    assembled code (within the DFA a part of the phrase).

    We offer a comfort macro NEXT (you guessed what it
    does).  Nevertheless you needn't use it as a result of ;CODE will
    put a NEXT on the finish of your phrase.

    The remainder consists of some quick phrases which increase
    into machine code appended to the definition of the phrase.
    Solely a really tiny a part of the i386 meeting house is roofed,
    simply sufficient to put in writing just a few assembler primitives beneath.
)
        

Simply strive to not go insane from the limitless energy.

After which there’s this:

Hand-written 1Kb binary
binary layout of planckforth as taken from the repo

This picture comes from the
PlankForth repo
(github.com).
It is one of the vital
stunning items of code I’ve ever seen. It is a full ELF binary
with a working Forth implementation that matches in lower than 1Kb.
As you’ll be able to see, there’s sufficient room left over for an outline and
copyright on the finish.

The binary is saved as an ASCII hex represention that may be turned
right into a working binary utilizing xxd -r -c 8.

However the very best half is bootstrap.fs, written in
line-noise-like operators and progressively turning into readable Forth
after a pair hundred traces.

Fortunately, feedback are one of many very first issues applied
and it is nearly like seeing micro organism spell out phrases in a petri dish:

h@l@h@!h@C+h!k1k0-h@$ok:k0-h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!
h@l@h@!h@C+h!k1k0-h@$ok h@k1k0-+$h@C+h!ih@!h@C+h!kefh@!h@C+h!l!

h@l@ h@!h@C+h! k1k0-h@$ kh@k1k0-+$ h@C+h!
    i       h@!h@C+h!
    kkf     h@!h@C+h!
    kLf     h@!h@C+h!
    ok:k0-   h@!h@C+h!
    ok=f     h@!h@C+h!
    kJf     h@!h@C+h!
    k0k5-C* h@!h@C+h!
    kef     h@!h@C+h!
l!

 **Now we will use single-line feedback!**

 planckforth -
 Copyright (C) 2021 nineties
...
        

Unimaginable.

One other hand-written machine code Forth (in 1,000 bytes and with
a Forth system in 1,000 traces!) is
SmithForth
(neocities.org)
by David Smith.
You may see and listen to Smith stroll by means of SmithForth on YouTube:
SmithForth workings
(youtube.com).

And as it’s possible you’ll recall from earlier, Cesar Blum’s
sectorforth
(github.com)
is a mere 512 bytes!

There are nearly as many Forth implementations as there are
stars within the evening sky.

Forth is an thought that has taken type in numerous purposes.

Many Forths are {custom} and home-grown.

Nevertheless it has had nice success in an enormous number of roles:

  • Energy vegetation, robotics, missile monitoring methods, industrial automation.
  • Embedded language in video video games.
  • Databases, accounting, phrase processors, graphics, and computation
    methods. (You may say, “legacy software program.” However I say, “Elegant
    weapons for a extra civilized age,” to paraphrase a sure smart
    Jedi.)
  • Within the trendy Open Firmware boot loader.
  • Processors of all sizes and shapes.
  • Microcontrollers of all sizes and shapes.

If it goes “beep” and “boop”, somebody has written a Forth for it!

For some notable makes use of, listed below are some beginning factors:

I feel
Open Firmware
(wikipedia.org)
is especially fascinating. It got here, like many issues, from
the high quality engineering minds at Solar Microsystems.

“Being based mostly upon an interactive programming language, Open
Firmware can be utilized to effectively check and produce up new {hardware}.
It permits drivers to be written and examined interactively.”

Maybe one of the vital thrilling makes use of of Open Firmware was the
Area Shuttle
ESN, which ran on a radiation-hardened
UT69R000
(cpushack.com)
processor!
A paper on the ESN,
Developing plug-and-play spacecraft systems: NASA Goddard Space Flight Center’s (GSFC) Essential Services Node (ESN) (PDF)
(zenodo.org)
notes that:

“Open Firmware can debug {hardware},software program, plug-in drivers, and
even the firmware itself. Open Firmware gives interactive instruments
for debugging methods.”

By the best way, I hope this transient point out of house know-how has moist
your urge for food for extra, as a result of we’re nearly there!

However first, I’ve a pair extra drawings of cool computer systems you
ought to see. Maybe you’re conscious of the massive number of Nineteen Eighties house
computer systems?

Examine these out:

drawing of the jupiter ace home computer

Working system: Forth.

OS and library of routines in 8 KB of ROM.

The onboard Forth was “Ten instances quicker than [interpreted] BASIC” and
lower than half the reminiscence necessities.”

(The quote above is from Well-liked Computing Weekly, 1982.)

The
Jupiter Ace
(wikipedia.org)
was a British house pc of the early Nineteen Eighties.

It has a fan-made web site, the Jupiter ACE Archive from which
has the web page,
What is a Jupiter ACE?
(jupiter-ace.co.uk):

“The main distinction from the ‘introductory pc’ that was the
ZX81, nonetheless, was that the Jupiter ACE’s designers, from the
outset, supposed the machine to be for programmers: the machine
got here with Forth as its default programming language.”

That web site has tons of sources. And for those who’re into that kind of
factor, you additionally owe it to your self to go to the “What’s…” web page
linked above after which hover your mouse over the picture of the ACE’s
circuit board. Each single IC, capacitor, and resistor is recognized
and defined in little tooltips!

It is not day by day you see a programming language listed as
an working system
for a pc. However it’s possible you’ll recall
that as early because the “IBM 1130 minicomputer at an enormous textiles
producer” period, Moore already had an editor and file administration
options. And you’ll actually write {hardware} drivers in Forth for those who
have the precise code phrase primitives. And as we’ll see quickly, there
is totally no restrict to how low-level Forth can go.

(There’s additionally no restrict to how high-level Forth can go. The e-book
Considering Forth by Leo Brodie, the identical e-book from which
we obtained the apples instance above, is filled with examples of purposes
written in very “English like” high-level phrases.)

The ACE by no means offered very many models, however it’s prized by collectors
right now. I’d take one.

The
What is Forth?
(jupiter-ace.co.uk)
web page has a wonderful clarification of Forth normally, however particularly
as an all-encompassing computing system:

“Traditional Forth methods use no working system. As a substitute of storing
code in recordsdata, they retailer it as source-code in disk blocks written
to bodily disk addresses. That is extra handy than it sounds,
as a result of the numbers come to be acquainted. Additionally, Forth programmers
come to be intimately accustomed to their disks’ information buildings,
simply by modifying the disk. Forth methods use a single phrase “BLOCK”
to translate the variety of a 1K block of disk house into the
tackle of a buffer containing the information. The Forth system
robotically manages the buffers.”

Many people fondly bear in mind the boot-to-BASIC computer systems of the Nineteen Eighties,
however are you able to think about rising up with the Jupiter ACE in your house and
truly understanding it?

The ACE ran on the
Zilog Z80
(wikipedia.org)
CPU, which was extremely well-liked on the time for low-power computer systems
and has had an amazingly lengthy life. It was used within the higher-end TI
graphing calculators such because the
TI-85
(wikipedia.org)
I had in highschool in 1996, which I spent many a cheerful afternoon
programming in TI-BASIC.

drawing of the canon cat word processor home computer

Working system: Forth.

OS, workplace suite, and programming atmosphere in 256 KB of ROM.

Revolutionary interface by Jef Raskin.

One other pc with Forth as an working system!

The Canon Cat
(wikipedia.org)
is a very fascinating machine for a variety of completely different
causes, the first of which is the keyboard-driven interface
by UI pioneer Jef Raskin.

Raskin wrote a e-book titled
The Humane Interface
(wikipedia.org)
with some provocative concepts which can be most likely
very a lot price re-visiting.
For instance, I like these two design guidelines:

  • Elimination of warning screens – trendy software program
    purposes typically ask the person “are you certain?” earlier than some
    probably dangerous motion; Raskin argues they’re
    unhelpful as a result of customers are likely to ignore them out of behavior,
    and that having a common undo
    eliminates the necessity for them.
  • Common use of textual content – Raskin argues that graphic icons in
    software program with none accompanying textual content are sometimes cryptic to
    customers.

The Cat was the {hardware} and software program incarnation of Raskin’s
design philosophies.

Additionally, you have to take a look at the image of Jef with a
little mannequin of the Cat on his Wikipedia web page:
Jef Raskin
(wikipedia.org).
Direct hyperlink to the picture: here
(wikipedia.org).

The Cat ran on a
Motorola 68000
(wikipedia.org)
CPU, which was additionally used within the Apple Macintosh and was one of many
first 32-bit processors, that includes 32-bit instruction set, registers,
and non-segmented reminiscence addressing.

Attending to the Forth interface would not appear to have been a prime
precedence on the Cat.

Quoting Dwight Elvey on the DigiBarn pc museum,
Canon Cat: Enabling Forth
(digibarn.com),
the method sounds a bit awkward:

“Spotlight the string: Allow Forth Language.
Then do: entrance, reply
Then: shift, usefront, house
You at the moment are in Forth.
It’s essential to do: -1 wheel! savesetup re
Entrance the editor, use the setup to set the keyboard to ascii
so that you could sort the characters with
shift , and shift .
Do a usefront disk.
It is going to save to the disk in order that it is going to be prepared
the following boot with simply the: shift, usefront, house
to restart Forth.
To undo the Forth mode: Forth? off 0 wheel! re [sic everything]”

(Notice that “USE FRONT” is a devoted key on the Canon Cat
keyboard that allows you to apply no matter operate is printed on the
entrance of one other key on the keyboard. Intelligent, proper? All the
Cat’s interactions are carried out by means of the keyboard like
this.)

And if that course of weren’t sufficient to place you off, this warning
appears notably dire and, if something, hilariously understated:

“Use care whereas in Forth mode as usefront shift : will
format the disk (a good suggestion to make a backup or
a minimum of take away the disk whereas experimenting).”

However all of that makes it sound worse than it’s.
Because of trendy streaming video know-how, you’ll be able to
see Dwight Elvey
boot up a cat and demonstrate it
(youtube.com).
As you’ll be able to see, attending to the Forth interface is actually not a
prolonged course of in any respect as soon as you realize what to do. Only a couple keystrokes.
And the Cat is a extra compact pc than I imagined from the images.

In case you like industrial design or fascinating pc interfaces,
you owe it to your self to take a look at the wonderful footage of
Jef Raskin’s team designing the Canon Cat (1985)!
(digibarn.com)

If you wish to see a bunch of images of a classic Cat in
wonderful form, take a look at Santo Nucifora’s
Canon Cat
(vintagecomputer.ca).

If nothing else, simply let this truth marinate in your head for a
little bit: The Canon Cat had an OS, workplace suite, and
programming atmosphere in 256 KB of ROM.
This
doc (not together with the pictures) is sort of precisely that
measurement!

Okay, now we’re prepared for…

title says Forth in Space and chuck is an astronaut on EVA who says May the Forth be with you.

Simply one of the vital thrilling makes use of of Forth is house
exploration as a result of house is intrinsicly superior.

We have already seen how Chuck Moore was intimately
concerned in programming ground-based radio telescopes.
However Forth has additionally discovered its manner into tons (actually and idiomatically)
of precise house craft in outer house!

NASA is legendary for having stringent guidelines about software program
that runs on spacecraft. Which is smart, given the price of these
machines and the problem and even impossibility of getting
to them to make fixes.

unreadable list of a ton of nasa projects using forth

The record of initiatives utilizing Forth at NASA compiled by James Rash in 2003 is simply too lengthy to simply record right here.

The picture on the precise is deliberately too small to learn. As you
can see, it is a huge record.

The unique NASA hyperlink has died, however the web page was archived by
the Wayback Machine at archive.org. There is a good copy
hosted right here as nicely:
Forth in Space Applications
(forth.com).

I have not discovered an inventory like this for the ESA, however the Philae
lander featured beneath could be one very outstanding instance.

(By the best way, although Forth is not featured right here, there is a enjoyable overview
of some CPUs utilized in numerous house missions:
The CPUs of Spacecraft: Computers in Space
(cpushack.com).)

(The picture to the precise could be very tall. We want some extra textual content for
wider screens. So, whereas it is not about Forth,I will not miss this
alternative to say considered one of my favourite computing-in-space books:
Digital Apollo: Human and Machine in Spaceflight
(mit.edu)
by David Mindell. It is going to change the way you have a look at the Apollo missions,
computer systems normally, and the position of astronauts in house craft!)

nasa mission patch for ssbuv

“There’s at all times nice concern about software program reliability, particularly with flight software program.”

From the paper
Forth in Space: Interfacing SSBUV, a Scientific Instrument, to the Space Shuttle (PDF)
(acm.org)
by Robert T. Caffrey et al:

“There’s at all times an amazing concern about software program reliability,
particularly with flight software program. The results of a software program error in
flight could possibly be dramatic. We have been in a position to produce dependable software program
by writing a Forth routine on the PC, downloading the software program, and
testing it interactively. We diversified the inputs to a routine and
checked the power of the routine to function appropriately beneath all
situations. In consequence, in the course of the STS-45 Shuttle mission, the
SPAIM flight software program labored completely and with none issues.”

Forth methods may be multi-tasking and this allowed the system to
monitor itself. Every activity had its personal stack and a watchdog activity may,
for instance, examine the well being of one other activity by monitoring the
different activity’s stack. (Stack depth was discovered to be a great indication of
activity well being. In different phrases, malfunctions would typically trigger the stack
depth to develop unchecked.)

“The power of the Forth growth system to debug {hardware} and
software program interfaces, mannequin lacking {hardware}, simulate system
malfunctions, and assist system integration dramatically helped in
the short technology of error-free software program. The interactive,
built-in and multitasking options of the Forth system proved to
be the important thing components within the success of the SPAIM methods
growth. A number of methods equivalent to stack depth monitoring,
tackle monitoring, cycle time monitoring, and error flag
monitoring supplied system checks throughout each the system
integration course of and the precise Shuttle mission.”

The interactive nature of the Forth system is once more discovered to be not
simply very handy, but in addition a large productiveness increase for all
phases of programming, debugging, and testing.

The SPAIM system used a 16-bit Intel 87C196KC16 microcontroller,
which is a MIL-SPEC member of the
Intel MCS-96
(wikipedia.org)
household. These began out as controllers for Ford engines within the Seventies.
They continued to be made in numerous incarnations till 2007 and have been
typically utilized in frequent gadgets equivalent to laborious drives, modems, and printers.
In contrast to many chips headed to house long-term, this one wasn’t “rad-hard”
(hardened in opposition to the consequences of radiation).

robot arm in space shuttle

Given the enter of three-axis joystick instructions, management a
50-foot lengthy, six-joint arm with six completely different coordinate methods.

Whole system developed by one programmer in 5 weeks.

The Space Shuttle Robot Arm Simulator
(forth.com)
was a fancy machine with some difficult necessities.

It seems that you could’t simply use the identical robotic arm on
the bottom for simulations because the one that can go into house.
For one factor, contending with gravity adjustments the necessities to
such a level that it is a utterly completely different robotic!

“The GSFC arm, for instance, is designed to hold as much as a thousand
pound payload at its tip. With the intention to do that it makes use of a excessive
strain (4000 psi) hydraulic system moderately than electrical motors as
on the RMS.

“Due to the utterly completely different nature of the joint controls,
the unique RMS software program was not usable besides as a supply of
algorithms.”

So the simulator arm couldn’t work the identical manner,
but it surely needed to faux it did
.

You may see in my drawing that the arm lived in a full-scale
simulated shuttle bay and was accompanied by an infinite mannequin
satellite tv for pc. (That satellite tv for pc seems to be just like the Hubble Area
Telescope to me, which appears believable, given the dates on this
challenge.)

Simply pay attention to those I/O necessities:

“The RMSS comprises fourteen separate processes: one for every joint,
one for every joystick, one for the digital show panel, a
simulation course of, a trending course of, and several other supervisory
processes.”

However, as appears to be a development with Forth-based house software program,
the work was impeccable:

“Simulation testing was so thorough that when the arm software program was
put in on website, not a single change was made to the manager
management algorithms.”

Does Forth suggest excellence, or does excellence suggest Forth? Ha ha.

Severely, although, writing a system like that in 5 weeks
is fairly astounding.

drawing of the shuttle launching

JPL’s ground-based management software program for shuttle SIR-A and SIR-B
radar imaging devices.

This part began off as an excuse to attract a Area Shuttle. However
it is truly an amazing instance of how a “reside” interactive system
can save a mission, even when the software program itself hasn’t been deployed into
house.

The paper:
Forth as the Basis for an Integrated Operations Environment for a Space Shuttle Scientific Experiment (PDF)
(forth.com)
describes a variety of {hardware} failures that needed to be
overcome.

“It was within the first day of information taking that we seen
the primary downside…”

The SIR-B’s transmitting antenna had shorted, ensuing within the
anticipated 1000 watts of energy being diminished to a faint 100 watts.

“Because the returned echo was negligible as obtained by the SIR-B
antenna it was determined to extend the achieve of the receiver.
The issue was in not understanding what had occurred to trigger
the failure. [It] was not instantly obvious what the
acceptable achieve needs to be…”

Forth-based, extremely adaptable SMDOS to the rescue!

“No downside. With the recommendation of the radar engineers, the Forth
module that was used to generate the show was shortly
modified to supply a calibrated show. The achieve of the
receiver was elevated till an ideal bell-shaped sample
once more appeared on the show.”

Then a second {hardware} failure:

“This was solely the beginning of our issues. A satellite tv for pc on board
did not deploy correctly. The shuttle needed to stay in excessive orbit
till the issue was resolved earlier than it may fireplace its engines to
descend to the orbit that had been deliberate for the SIR-B information
taking. ”

Now the shuttle wouldn’t be within the deliberate orbit for data-taking.
A second SMDOS adaptation mounted that.

Then a third {hardware} downside with one other
antenna:

“A bolt had sheared within the antenna’s pointing mechenism and the KU
band antenna was trashing round, threatening to destroy itself. It
was obligatory for an astronaut to exit the shuttle (EVA) in a
spacesuit to pin the antenna down.”

Now the shuttle needed to rotate to level at a relay satellite tv for pc to
collect information (to tape!) after which rotate in the direction of Earth to transmit
the recorded information, and repeat.

“After all this meant a wholly new data-taking technique. Once more
the SMDOS computer systems have been put to work displaying new plans for the
stringent new situations.”

They misplaced tons of information, after all, however a minimum of they have been in a position to
salvage 20% of it by rotating and capturing and rotating and
transmitting. None of which might have a been doable if that they had not
been in a position to modify the software program on the spot.

Conclusion:

“When the antenna feed failed and we realized that the software program had
to adapt to that failure, it was comparatively simple given the
interactive Forth enviroment to vary the required module to satisfy
the brand new specs. That is clearly past the capabilites of
most languages.”

Different methods are interactive, however Forth could also be singularly distinctive in
permitting full freedom of modification in an interactive
session.

After all, this type of freedom is double-edged sword if there ever
was one. The implied hazard of that highly effective sword (plus the postfix
notation) has been a tough promote within the company world.

To date, we have simply seen Forth software program in house. Nevertheless it
is usually accompanied by Forth {hardware}.

Yup, Forth {hardware}. Introducing:

block diagram of harris chip

The Harris RTX2010 processor. Utilized in a ton of house
purposes.

That includes:

  • Direct execution of Forth
  • Two {hardware} stacks, 256 phrases deep
  • 8MHz clock, extraordinarily low latency
  • Radiation hardened

The
RTX2010
(wikipedia.org)
and its predecessor, the RTX2000
account for a great portion of using Forth within the house {industry}.
They run Forth natively.

The usage of the RTX line in house might not be soley as a consequence of a selected
love for Forth per se, however due to the particular engaging properties
of those processors – very low latency and the power to shortly
course of the floating level mathematical operations wanted for neat house
stuff like navigation and thruster management. Both manner, the
philosophy of Forth embedded on this {hardware} is appropriate
for the acute environments through which they function.

Largely due to the stack-based design, the RTX 2000 and 2010
have very compact machine code. Subroutines calls take solely a
single cycle and returns are free!
All branches take
precisely one cycle as nicely.

They’re additionally brilliantly minimalistic designs. The complete RTX2000
instruction set suits on a single web page. See the primary PDF hyperlink beneath:

So what sort of spacecraft use these Forth-native processors?

Let’s take a look at a particular pair of spacecraft:

drawing of rosetta approaching comet

First mission to ship a spaceship to orbit a comet after which ship a
lander to the comet’s floor!

The Rosetta spacecraft’s Ion and Electron Sensor instrument used a Harris RTX2010.

The Philae lander used two Harris RTX2010s for full system management (CDMS) and two extra to regulate its touchdown system (ADS).

The ESA’s Rosetta mission
(esa.int)
was massively formidable: Ship a spacecraft to
rendezvous with after which observe a comet across the Solar, deploy
the Philae lander to the floor by dropping it into the comet’s
gravity nicely, observe the lander because it shoots harpoons
into the icy floor of the comet to maintain from bouncing again out
into house, then relay the lander’s communication from the floor again to
distant Earth, 28 minutes away on the pace of sunshine.

Rosetta traveled within the Photo voltaic System for a full decade (2004 to
2014) earlier than assembly up with comet 67P/”Churyumov-Gerasimenko”.
(67P is 4km huge and orbits the solar each six and a half years.)

Rosetta orbited the comet for 3 months after which deployed
the Philae lander to the floor of the comet.

Each craft contained a full laboratory of superior scientific
devices (11 on Rosetta, 9 on Philae) together with some that doubled
as high-resolution cameras with pictures appropriate for people to view.
The whole mission
(wikipedia.org)
is price studying about. There are some improbable pictures
and animations to be seen on the mission web page and on the
comet’s own page
(wikipedia.org).
the philae lander brightly illuminated by the sun against the black backdrop of space

Typically described as being “the dimensions of a washer,” the
Philae
(wikipedia.org)
lander pushed away from Rosetta’s orbit to drop to the floor of 67p.

The image on the proper was taken
from Rosetta’s OSIRIS imager as Philae fell slowly away from the
orbiter.

As a result of the comet’s gravitational pull is so small (enormous boulders
have been noticed shifting round on its floor), a pair of harpoons
have been meant to fireplace into the floor of the comet and maintain the lander
down. These didn’t deploy (probably a mechanical failure) and a
touchdown thruster additionally failed, so Philae ended up having a protracted,
low-gravity tumble on the floor.

It has been speculated that the harpoon failure truly
saved Philae from an much more thrilling journey as a result of research
of the floor discovered it to be tougher than anticipated. It may need
launched itself away moderately than anchoring! Because it was, the lander
bounced with a pressure that was simply shy of escaping the comet’s
gravitational pull fully. It rose a full kilometer above the floor
earlier than slowly returning for one more two bounces to its remaining resting
spot.

A pair of Harris RTX2010s managed Philae’s Lively Descent System.
Take a look at Here comes Philae! Powered by an RTX2010
(cpushack.com):

“Why was the RTX2010 chosen? Merely put the RTX2010 is the bottom
energy price range processor accessible that’s radiation hardened, and
highly effective sufficient to deal with the complicated touchdown process. Philae
runs on batteries for the primary section of its mission (later it would
swap to photo voltaic/again up batteries) so the facility price range is vital.
The RTX2010 is a Forth based mostly stack processor which permits for very
environment friendly coding, once more helpful for a low energy price range.”

Right here is extra info (with footage!) concerning the bodily design
and parts within the Philae management system:
Command and Data Management Subsystem (CDMS) of the Rosetta Lander (Philae)
(sgf.hu).

“Harris RTX2010 processor has been chosen for the DPU boards
as a result of it’s the lowest energy consuming, house certified,
radiation hardened, 16-bit processor with options to supply so
sophisticated capabilities because the CDMS has to carry out. It’s a stack
based mostly, Forth language oriented processor with an unique and
difficult instruction set. CDMS is a real-time management and information
acquisition system, and it has to course of duties in parallel.
Subsequently, a real-time, pre-emptive multitasking working system
has been developed to run software duties executing the required
capabilities in parallel.”

And right here is the lander’s
Active Descent System (ADS) QM User Manual
(spyr.ch)
which has far more element about this pc system, together with a
variety of particulars concerning the Forth software program:

“After resetting the subsystem (power-on reset), the bootstrap
units up the Forth atmosphere, copies the firmware from PROM to
RAM and disables the PROM for additional entry.

After this, the primary phrase Do-App is known as from the Forth system
instantly after setup. You’ll find the primary phrase Do-App within the
file app.fth (see half II). Do-App calls Init-App, which itself
calls different initilisation phrases like Init-ADS. Then the
software enters the primary loop. In the primary loop the next
actions are carried out:

  • reset the watchdog (watchdog is enabled for the QM)
  • put the information into the HK registers
  • get the information from the ADC handler
  • course of CDMS requests”

Regardless of the unlucky touchdown, which put Philae in an excessive amount of
shadow to get as a lot photo voltaic vitality as hoped and at an angle that
made communication with Rosetta tough, Philae was nonetheless
sturdy sufficient to carry out “80%” of its scientific mission, which
is fairly wonderful.

An image taken by the Philae lander because it lay on its aspect, having fun with some daylight on
considered one of its toes:
the outline of deeply fractured rock and ice, the darkness of space in the background, and a lander foot brightly lit by the sun.

Simply have a look at that. An image from the floor of a comet.

For the full-size picture, extra information, and hyperlinks to the opposite CIVA digital camera
pictures, see
CIVA camera 1 view
(esa.int).

There’s a ton of fascinating details about the touchdown and
the ESA’s detective work to determine the place Philae truly ended
up:

Philae ultimately ran out of energy and stopped speaking with Rosetta.

This is without doubt one of the remaining pictures taken by the Rosetta orbiter because it made the
“laborious descent” (managed crash touchdown) to the floor of comet 67p:
photo of comet 67p taken by rosetta (

The picture and an outline are right here: Final Descent Images from Rosetta Spacecraft
(nasa.gov).

“The choice to finish the mission on the floor is a results of
Rosetta and the comet heading out past the orbit of Jupiter
once more. Farther from the solar than Rosetta had ever journeyed earlier than,
there could be little energy to function the craft. Mission operators
have been additionally confronted with an imminent month-long interval when the solar is
near the line-of-sight between Earth and Rosetta, that means
communications with the craft would have turn into more and more extra
tough.”

By the best way, the ESA has a pleasant abstract of the pc {hardware}
utilized by the OSIRIS digital camera on Rosetta which was used to take the floor
picture above and likewise the little image of the descending lander additional
above.
Optical, Spectroscopic, and Infrared Remote Imaging System
(esa.int).

After ending the primary draft of this text, I used to be so enthusiastic about
the Rosetta mission that I ended up ordering and studying
Rosetta: The Outstanding Story of Europe’s Comet Explorer by Peter Bond.
It is a bit of a dry learn, however the subject material is thrilling
nonetheless and the protection is thorough. I like to recommend it if you wish to
know much more about this superior engineering and scientific milestone.
(It doesn’t, sadly, point out Forth.)


Rabbit Gap Alert: This takes us away from
Forth for a second, however studying concerning the
Virtuoso RTOS (real-time working system) ultimately results in a deep,
deep Wikipedia rabbit gap that takes you on a journey to the Inmos
processors, Hoare’s CSP, the occam programming language, the HeliOS
parallel computing working system, and the idea of the
“transputer” microprocessors.

Transputers use entire processors as
constructing blocks for a parallel pc in the identical manner transistors are
used because the constructing blocks for processors. (Thus, transputer =
“transistor pc,” you see?) They have been largely featured in
supercomputers, however additionally they noticed some industrial controller use
and there was even an Atari Transputer Workstation,
ATW-800.

(I’ve deliberately not linked to any of this stuff right here
since you’ll disappear into that gap and by no means see the tip of this
doc, which might be very unhappy. Additionally, I point out “transputers” once more
another time beneath and also you would not need to miss that.)


The Rosetta orbiter and Philae lander now relaxation silently on the
floor of 67p, the place they’ll little doubt keep for billions of
years or till future comet vacationers choose them up and put them
in a trophy room, whichever comes first.

crop of jack rusher from the previous screenshot
“…Area probes written in Lisp and Forth have been
debugged whereas off world… If that they had confirmed their applications
appropriate by development, shipped them into house, after which came upon
their spec was improper, they’d have simply had some useless junk on
Mars
. However what these guys had was the power to sort things
whereas they’re working on house probes… As well as, the spec is
at all times improper!”

— Jack Rusher, Cease Writing Lifeless Applications (discuss given at Unusual Loop 2022)

This is the discuss:
“Stop Writing Dead Programs” by Jack Rusher (Strange Loop 2022)
(youtube.com).

You’ve got obtained 43 minutes to observe it. I am timing you. Do not get
distracted by different YouTube options. Come again right here. I am ready.

Or higher but, take a look at Jack’s superior transcript,
which was tremendous useful once I wished to re-find the above quote:
Stop Writing Dead Programs.
(jackrusher.com).

In his transcript, he notes:

“Had I had extra time, I’d have completed a complete collection of slides
on FORTH. It is a tiny language that mixes interactive
growth, expressive metaprogramming, and super machine
sympathy. I’ve shipped embedded methods, bootloaders, and different
close-to-the-metal software program in FORTH.”

I used to be extraordinarily serious about listening to about Forth methods being
up to date in house, however had a heck of a time discovering any.
I lastly discovered one on a web page that’s in any other case largely
devoted to Lisp’s use on the Jet Propulsion Labs:
1992-1993 – Miscellaneous stories
(sourceforge.io)
on the wonderful, sprawling website for the Mecrisp-Stellaris Forth
(which runs on numerous non-x86 CPUs):

“Additionally in 1993 I used MCL to assist generate a code patch for the
Gallileo magnetometer. The magnetometer had an RCA1802 processor, 2k
every of RAM and ROM, and was programmed in Forth utilizing a growth
system that ran on a long-since-decommissioned Apple II. The
instrument had developed a nasty reminiscence byte proper in the course of
the code. The code wanted to be patched to not use this unhealthy byte.
The magnetometer staff had initially estimated that resurrecting the
growth atmosphere and producing the code patch would take so
lengthy that they weren’t even going to aim it. Utilizing Lisp I wrote
from scratch a Forth growth atmosphere for the instrument
(together with a simulator for the {hardware}) and used it to generate the
patch. The entire challenge took just below 3 months of part-time
work.”

(If anybody has any results in different notable Forth makes use of in house, I might like to
hear about them.)

After we defeat the alien kill-bots and reprogram them, it would
certainly be with a Forth of some kind.
alien kill-bots being controlled by forth

Within the background, one of many Invader machines lies crumpled and
smoking amidst ruins. This was considered one of Earth’s nice cities.

Stomping in the direction of us with its mechanical arms raised in victory, is
one other Invader. However this one is completely different. The tell-tale giveaway is
the opening in its protecting head dome. And is {that a} flag? Why sure, it’s!

At nice value, people managed to entice one of many Invaders lengthy
sufficient penetrate its outer defenses, whereas in any other case leaving the
machine unhurt and operable.

Working feverishly in opposition to a doomsday clock, they burrowed deep into
{the electrical} coronary heart of the machine, figuring out and classifying its
alien capabilities till they understood it nicely sufficient to aim
an interface.

A bus protocol was decoded. Programming work started.

It went poorly. The aliens had unthinkably weird notions of
generalized computing that defied all recognized patterns of software program.

All the things needed to be completed with agonizing labor, stringing
sequences of uncooked bus messages collectively in hopes of getting a
appropriate response.

However then somebody had the brilliant thought to bootstrap a Forth
from the recognized instruction sequences. With this, they may write
a bare-bones interpreter. And, finally, they may experiment
shortly and safely.

Days later, an arm moved. Then they crushed a barrel with a
gripper claw:

BARREL OBJECT-ID VISION TARGET
133 L-ARM-FWD 14 L-CLAW-OPEN
25 L-ARM FWD 14 L-CLAW CLOSE
        

Then a primary four-legged step. Then 20 steps:

PREP-QUAD-LEGS
20 STRIDE-LOOP
        

As ravaged fighters seemed on in amazement, “Defender-1” burst
from the previous brick warehouse and, in a terrific crash, it toppled
one other Invader because it was passing by on patrol.

The machines grappled for a second and it
seemed as if Defender-1‘s clumsy actions could be no match
for the alien, even from a superior place.

However people had decoded all of the weapon methods by then and a
particular phrase had been ready for this second:

: KILL
    100 BEAM-LEVEL
    BOT OBJECT-ID VISION TARGET
    L-BEAM FIRE-FULL
    R-BEAM FIRE-FULL
;
        

Twin blinding beams of vitality struck the enemy full within the torso
and immediately turned its mechanical guts into scorching plasma.
After a second of silence, a single cheer rose up from a doorway
close by and was quickly joined by 100 completely different voices from
locations of concealment within the ruined buildings.

Now the people had the higher hand finally! Different Invader
machines have been disabled or captured. Defender-1 was joined
by Defender-2, after which 3, 4, 5, and extra!

Software program was handed by sneaker-net and by shortwave packet radio.
Metropolis by metropolis, Earth took again management. And together with victory,
phrase of the One True Language unfold throughout the land. Flags
have been raised in honor of its authentic discoverer, Chuck Moore.

The place different abstractions had failed, the common machine
reality of Forth had succeeded.

This is a “household tree” of some notable Forths:
unreadably tiny diagram of lineage of various Forth implementations

Clearly the graphic is unreadably tiny. For the full-size
authentic and the gForth program used to create it, take a look at:

Forth Family Tree and Timeline
(complang.tuwien.ac.at).

One of many hardest issues about making an attempt to study “Forth” is realizing
that there isn’t a single implementation that may lay sole declare to that identify.
As we have seen, a few of Chuck’s first Forths pre-date the identify fully.

There are Forth requirements courting again to the unique ANS Forth
doc and persevering with with the
Forth 2012 Standard and Forth200x committee
(forth-standard.org).

Forths have shared ideas. There are numerous frequent phrases, actually, however purpose-built
Forths could have their very own particular vocabularies.

Additionally, it’s true that making Forths is a minimum of as enjoyable
as utilizing them.

The forest of computing is peppered with pastime Forths. They develop the place nothing
else can survive. They flourish within the solar and within the shade.
Every one is a little bit glittering jewel.

Charles H. Moore based Forth, Inc in 1973. He is continued to port
Forth to varied methods ever since. However he is by no means stopped inventing.
drawing of chuck at a desk programming on a pc with a crt. equipment looks 1990s era

I drew this picture of Chuck from a photograph on this wonderful quote
assortment,
Moore Forth: Chuck Moore’s Comments on Forth
(ultratechnology.com)
compiled by Jeff Fox.

You will discover I added some shade to my drawing for this one, and
that is as a result of I am fairly certain that what we’re seeing on Chuck’s monitor
is…

shadeForth
screenshot of colorforth

The above screenshot is definitely from
a page about etherForth,
(etherforth.org),
which is a
shadeForth
written for GA144 chips. (Do not search for these chips but except you
desire a spoiler for what’s coming in a second beneath!)

What the heck are we taking a look at right here?

So,
colorForth
(wikipedia.org)
is:

“An idiosyncratic programming atmosphere, the colours simplify
Forth’s semantics, pace compiling, and are mentioned to assist Moore’s personal
poor eyesight: colorForth makes use of completely different colours in its supply code
(changing among the punctuation in commonplace Forth) to find out
how completely different phrases are handled.”

And, after all:

“The language comes with its personal tiny (63K) working system.
Virtually every part is saved as supply code and compiled when
wanted. The present colorForth atmosphere is proscribed to working on
Pentium grade PCs with restricted assist for
lowest-common-denominator motherboards, AGP video, disk, and
community {hardware}.”

However the very best description of
shadeForth
and its strengths come from Chuck Moore himself in an interview in
2009,
Chuck Moore: Geek of the Week
(red-gate.com):

“Forth has some ugly punctuation that colorForth replaces by
coloring supply code. Every phrase has a tag that signifies operate;
it additionally determines shade. This appears a small level, but it surely
encourages using capabilities, equivalent to feedback or compile-time
execution, that might be inconvenient in Forth.”

It needs to be famous that the colours may be changed with symbols or
notation, so utilizing the language with out the power to
distinguish shade just isn’t a barrier. Shade is simply a technique to
present this info.

There are a ton of different enhancements past the apparent shade facet,
equivalent to:

“By having phrases preparsed, the compiler is twice as quick. One other
small level, since compiling is just about instantaneous, however this
encourages recompiling and overlaying the modules of an
software. Smaller modules are simpler to code, check and doc
than a big one.”

That interview comprises one other Chuck Moore quote about software program
development normally:

“As a substitute of being rewritten, software program has options added. And
turns into extra complicated. So complicated that nobody dares change it, or
enhance it, for worry of unintended penalties. However including to it
appears comparatively protected. We want devoted programmers who commit
their careers to single purposes. Rewriting them time and again
till they’re excellent.”

That is one thing I’ve seen repeated repeatedly by a few of
essentially the most revered minds in software program: You can not simply maintain including
issues to a program. It’s essential to frequently re-work this system to match
your wants as they alter over time. Ideally, you re-write this system.
Solely time and deep consideration can yield essentially the most elegant, appropriate,
and easy program.

Which brings us to…

Chuck Moore has been combating in opposition to software program complexity for the reason that Nineteen Fifties.

“I’m completely pissed off with the software program I’ve to cope with. Home windows is past comprehension! UNIX isn’t any higher. DOS isn’t any higher. There is no such thing as a motive for an OS. It’s a non-thing. Possibly it was wanted at one time.

— Chuck Moore, 1997

“If they’re ranging from the OS they’ve made the primary mistake. The OS is not going to suit on a floppy disk and boot in ten seconds.”

— Chuck Moore, 1999

These quotes additionally come from Jeff Fox’s quotes assortment,
Moore Forth: Chuck Moore’s Comments on Forth
(ultratechnology.com).

As you have little doubt gathered over the course of this web page,
Chuck isn’t any fan of huge, heavy, sophisticated software program equivalent to
working methods.

He believes in compact, machine-sympathetic programming.

“Mechanical Sympathy” just isn’t Chuck’s time period, however I consider it
precisely describes his philosophy. It comes from this
(apocryphal?) quote by
Formulation One race automobile driver
Jackie Stewart
(wikipedia.org):

“You do not have to be an engineer to be a racing driver, however you
do must have mechanical sympathy.”

The usage of the time period to explain software program comes from Martin Thompson’s
weblog of the identical identify.
In Why Mechanical Sympathy?
(blogspot.com),
he writes:

“Why does the software program we use right now not really feel any quicker than the
DOS based mostly purposes we used 20 years in the past??? It doesn’t must
be this fashion. As a software program developer I need to try to produce
software program which does justice to the great achievements of our
{hardware} buddies.”

Many times, you may see this sentiment echoed by Chuck Moore
and followers of Forth.

I feel it is very fascinating and telling that Forth tends to be
well-liked with “{hardware} folks” equivalent to electrical engineers and embedded
methods designers. In contrast, it appears that evidently “software program folks”
are likely to idolize a extra summary, high-level magnificence as discovered
in languages equivalent to Lisp or Scheme.
After all, it is a gross generalization and should haven’t any foundation actually,
however I do know I am not the one individual to note this development.

Possibly one other technique to describe this facet of Forth is that it has a
“mechanical purity” in the identical manner that Pleasure, with its combinators,
has a “mathematical purity.”

And talking of {hardware}…

Chuck’s actual love appears to be processor design.
These Harris RTX2000 and RTX2010 chips utilized in so many house missions?
That is principally his chip!
chuck as a mad scientist chip creator

No kidding.

Chuck, that sensible rascal, has been designing {hardware} since 1983
beginning with the Novix N400 gate array. An improved design was
offered to Harris to turn into the RTX chips.

Chuck designs processors along with his personal VLSI software program, “OKAD”, written in
500 traces of Forth, after all.

Take a second to pause on that final sentence.

Processor design software program written in 500 traces?

You learn that proper.

OKAD is without doubt one of the Nice Legends of Chuck Moore.
However what, precisely, is it?

First off, VLSI stands for
Very Large Scale Integration
(wikipedia.org):

“Very large-scale integration (VLSI) is the method of
creating an built-in circuit (IC) by combining thousands and thousands or
billions of MOS transistors onto a single chip. VLSI started within the
Seventies when MOS built-in circuit (Metallic Oxide Semiconductor) chips
have been developed after which broadly adopted, enabling complicated
semiconductor and telecommunication applied sciences. The
microprocessor and reminiscence chips are VLSI gadgets.”

The product of VLSI is what we consider once we think about
the trendy picture of “pc chip” in our minds.

“Integration” is solely the shrinking of computer systems from entire rooms to
microscopic considering mud:

  • Computer systems started with processors the dimensions of rooms with
    discrete logic gates you’ll be able to contact (relays to hoover tubes to
    transistors).
  • Then, processors have been shrunk right down to the dimensions of fridges
    with logic boards of built-in circuits (ICs).
  • Lastly, complete processors shrunk down to suit on a single chip by way of
    Very Giant Scale Integration.

(Additionally, in a parallel path from mainstream desktop computing,
VLSI has additionally produced complete computer systems and, more and more,
a number of computer systems on a single chip, additionally
referred to as
“system(s) on a chip” (SoC)
(wikipedia.org).
The traces across the numerous sorts are extraordinarily blurry, however
some acquainted types are microcontrollers, embedded methods,
numerous “cell” gadgets, and so forth.)

Anyway Moore’s,
VLSI Design Tools (OKAD)
(colorforth.github.io)
system an entire processor workshop:

“In 500 traces of
shadeForth,
these instruments present every part required to design a chip.”

OKAD is actually extra of a group of instruments that work collectively to:

  • Describe the fundamental logic gates (constructed of transistors),
  • Design the format of your entire circuit (the three-dimensional multi-layered community of connections between gates),
  • Simulate the circuit electrically (voltage, temperature, capacitance, and so forth.),
  • And export the completed design to the industry-standard
    GDSII
    (wikipedia.org)
    file format that’s given to IC foundries (or “chip fabs”).

For extra about OKAD, I extremely suggest studying the
wonderful solutions to
Did Forth’s inventor Charles Moore really write a CAD program in only 5 lines of code?
(retrocomputing.stackexchange.com).

Transferring on from the software program to Moore’s chips themselves, Moore himself wrote
a pleasant little abstract of his designs. It’s written in Moore’s typical consise fashion,
giving only a few key particulars about every chip:
Forth Chips
(colorforth.github.io).

First, there was the Novix NC4000, which was designed
for a CMOS gate array.

This is a complete e-book concerning the NC4000 chip: Footsteps in an Empty Valley: NC4000 Single Chip Forth Engine (8Mb PDF) by Dr. Chen-Hanson Ting.

To cite Dr. Ting from Chapter 2:

“The Novix NC4000 is a brilliant high-speed processing engine which is
designed to instantly execute excessive stage Forth directions. The
single chip microprocessor, NC4000, features its exceptional
efficiency by eliminating each the peculiar meeting language and
inner microcode which, in most standard processors,
intervene between the excessive stage software and the {hardware}. The
twin stack structure significantly reduces the overhead of subroutine
implementation and makes NC4000 particularly suited to assist excessive
stage languages aside from Forth.”

As you’ll be able to see, this reads similar to an outline of the Harris RTX
chips used within the spacecraft we explored above.

Certain sufficient, if we learn the Historical past part on the
RTX2010 page,
(wikipedia.org)
the lineage is made very clear:

“In 1983, Chuck Moore applied a processor for his programming
language Forth as a gate array. As Forth may be thought of a twin
stack digital machine, he made the processor, Novix N4000 (later
renamed NC4016), as a dual-stack machine. In 1988, an improved
processor was offered to Harris Semiconductor, who marketed it for
house purposes because the RTX2000.”

One other nice article about Moore’s early processor design work
(and a few extra spacecraft mentions!), take a look at
Charles Moore: From FORTH to Stack Processors and Beyond
(cpushack.com)
which is an element considered one of a two-part collection.

After the Novix, got here a wide range of chip initiatives:

  • Sh-Increase (32-bit, 20 Mips),
  • MuP20/MuP21 (21-bit, 100 Mips),
  • F21 (500 Mips – and be sure you take a look at
    F21 in a Mouse
    (ultratechnology.com), which is an entire F21 pc working a
    graphical atmosphere that has been packed
    right into a PC mouse…within the Pentium period!)
  • i21 (21-bit, 55 Mips)
  • X18 (18-bit, 2400 Mips)

These are all actual methods that actually labored. The laborious half has at all times
been discovering prospects.

Over time, different folks have additionally created Forth chips and FPGA
implementations of {hardware} Forth-likes. Take a look at the hyperlinks on
Forth CPU Cores
(forth.org)
and
Forth Chips
(ultratechnology.com).)

Along with
shadeForth,
Moore additionally developed “Machine Forth” as a fair extra
machine-sympathetic language than conventional Forth. It is based mostly on
the machine code of the MuP21 microprocessor listed above.

I will not go into a whole lot of element about Machine Forth, however
listed below are some fascinating hyperlinks:

As you’ll be able to see, Moore has at all times been on the lookout for new methods to work
with computer systems, a partnership between the machine and the programmer.

Which brings us to the present state of Chuck Moore’s artwork…

“Programming a 144-computer chip to attenuate energy” (2013)
screenshot from Chuck's 2013 strange loop talk about 144 computer chip

144 asynchronous computer systems on a chip. Idle cores use 100 nW. Lively ones use 4 mW, run at 666 Mips, then return to idle. All computer systems working flat out: 550mW (half a Watt).

Take a look at Chuck’s discuss at StrangeLoop:
Programming a 144-computer chip to minimize power – Chuck Moore (2013)
(youtube.com)

And this is the official web site:
GreenArrays, Inc.
(greenarraychips.com)
“Extremely-low-powered multi-computer chips with built-in
peripherals.”

Most likely the very best abstract comes from the structure doc,
GreenArrays Architecture (PDF)
(greenarraychips.com):

COMPLETE SYSTEMS: We check with our chips as Multi-Pc Techniques as a result of they’re, actually, full methods. Provide considered one of our chips with energy and a reset sign, and it’s up and working. All of our chips can load their software program at excessive pace utilizing a single wire that may be daisy chained for a number of chips; if desired, most may be bootstrapped by a easy SPI flash reminiscence.

“Distinction this with a Multi-Core CPU, which isn’t a computing system till different gadgets equivalent to crystals, reminiscence controllers, recollections, and bus controllers have been added. All of this stuff eat vitality, occupy house, value cash, add complexity, and create bottlenecks.

“NO CLOCKS: Most computing gadgets have a number of clocks that synchronize all operations. When a standard pc is powered up and ready to reply shortly to stimuli, clock technology and distribution are consuming vitality at an enormous fee by our requirements, but carrying out nothing.”

It goes on to clarify the fine-grained energy utilization, how every pc
communicates with its neighbor, and comparable statements high-level
descriptions.

You should purchase these chips proper now for as little as $20 in portions
of 10. The one downside is that to simply make to make use of of 1, you both
want to purchase the $495 growth board or make your personal. I’ve discovered
valuable few examples of people that have completed this on-line.

One uncommon instance is
Hands on with a 144 core processor
(archive.org of designspark.com).
Article creator Andrew Again even has screenshots of the of the
arrayForth atmosphere (which is principally
shadeForth)

The query, after all, is what do you do with this factor?

It could end up that the reply may be discovered by wanting again into
computing historical past. You do not even have to return very far.

In case you learn the “Rabbit Gap Alert” beneath the image of the floor
of comet 67p above, then you definitely noticed the time period “transputer”.
I feel it could be very fascinating to check and distinction the
GreenArrays GA144 chips to the Inmos transputer chips.
It appears to me, at first look, that something these transputers would
have been fitted to should be a great match for a GreenArrays multi-computer chip
as nicely.


Rabbit Gap Alert 2: One other enjoyable diversion into massively parallel
computer systems is considered one of my favorites: Danny Hillis’s
Connection Machine
(wikipedia.org)
computer systems that includes a “12-dimensional hypercube” routing design.

Hillis himself is a “human rabbit gap” of innovations, concepts, and
writings. He is the creator of considered one of my favourite non-fiction books, “The
Sample on the Stone,” and co-founder of The Lengthy Now Basis
(together with another “human rabbit holes” together with the unimaginable
author and thinker, Steward Model).

One of many initiatives of the Lengthy Now
Basis is the design and creation of the ten,000 yr big
mechanical Clock of the Lengthy Now which is meant to tick as soon as
per yr and have a cuckoo that comes out as soon as each 1,000 years.

There’s additionally a direct connection between the Lengthy Now and the
Rosetta spacecraft: Lengthy Now created the “Rosetta disc”, a particularly
intelligent bodily object containing the micro-etched textual content of over
a thousand human languages. The Rosetta spacecraft carried a nickel
prototype of the disc. In order that’s now sitting on a comet.

As with the earlier rabbit gap alert, I may hyperlink to all of those
folks and issues, however every is a part of an unfathomably deep fractal of
fascinating stuff and I am afraid you may by no means come again to complete
this. However do look them up later!


At any fee,

The one downside with parallel computer systems is that we’re nonetheless
not that nice at programming them.

Heck, we’re not even that nice at serial programming but.

“In case you speak about molecular computer systems which can be circulating in your bloodstream, they are not going to have very a lot energy and so they aren’t going to have very a lot reminiscence and so they aren’t going to have the ability to use a lot vitality.

— Chuck Moore, Programming a 144-computer chip to attenuate energy, 2013

The eventual full domination of x86 PCs in virtually all areas
of computing, adopted by the present rise of highly effective ARM CPUs are
historic computing truth. Unimaginable feats of processor engineering
have made it doable to run what can solely be described as
“supercomputers” on battery energy and put them in our pockets.

Traits in each software program and {hardware} have been in the direction of
ever-increasing layers of complexity. The layers are very deep and
very huge.

As I write this, sure well-liked avenues of computing threaten to
make each present piece of inefficient software program appear completely
frugal by comparability.

(Extremely, we’re not even content material with the
supercomputers on our desks and in our palms. So we depend on
companies which work remotely over the Web on highly effective networks
of computer systems in enormous information facilities. We consider this computing as
low cost and even free as a result of a lot of it’s not directly paid for with
promoting {dollars}. Paid for, that’s, with our consideration and
private information. These information facilities with their screaming cooling followers
and backup turbines are elsewhere, not in our dwelling rooms.
It is easy to easily neglect how all of that is made doable.)

More and more, we depend on massively complicated software program with that appears
to have an never-ending urge for food for computing energy.

However do these developments must proceed?

There’s completely no motive we’ve to make use of more and more
inefficient and poorly-constructed software program with steeper and steeper
{hardware} necessities within the many years to return.

Actually, the reverse could possibly be true.

There are many purposes the place low vitality computing is a
categorical requirement and I consider these purposes will solely
enhance.

Forth-likes may have a robust future as we glance in the direction of:

  • Tiny, ubiquitous computer systems
  • Solar energy
  • Closely constrained VMs

There are bodily realities (such because the pace of sunshine) which
finally govern the pace at which we will carry out a calculation or
the utmost variety of calculations which may be completed with a Watt of
electrical energy utilizing computer systems made out of atoms. These are laborious limits.
However there’ll certainly be different plateaus alongside the best way to reaching these
limits.

Across the yr 2006, we noticed Dennard scaling
gradual to a crawl.
Dennard scaling
(wikipedia.org)
describes the connection between
the shrinking measurement of transistors to the rise of computing pace.
Merely put, smaller transistors can swap at increased speeds and take
much less voltage. This scaling legislation held for a few years. However we reached a
pace plateau at round 4 GHz due to present leakage and warmth.

In
The Free Lunch Is Over
(gotw.ca),
printed in Dr. Dobb’s Journal in 2005, Herb Sutter writes,

“The main processor producers and architectures, from Intel
and AMD to Sparc and PowerPC, have run out of room with most of
their conventional approaches to boosting CPU efficiency. As a substitute
of driving clock speeds and straight-line instruction throughput
ever increased, they’re as an alternative turning en masse to hyperthreading
and multicore architectures.”

Multicore processors and more and more intelligent {hardware} structure
tips have continued to supply will increase in computing energy…but it surely’s
not the identical.

Close to the tip of the article, Sutter advises:

“There are two methods to cope with this sea change towards
concurrency. One is to revamp your purposes for concurrency,
as above. The opposite is to be frugal, by writing code that’s extra
environment friendly and fewer wasteful.
This results in the third fascinating
consequence:

“3. Effectivity and efficiency optimization will get extra, not much less, essential.
These languages that already lend themselves to heavy optimization will discover new life; those who do not might want to discover methods to compete and turn into extra environment friendly and optimizable. Count on long-term elevated demand for performance-oriented languages and methods.”

(Emphasis mine.)

For now, we’re nonetheless consuming the stays of that free lunch.

I am most likely pretty uncommon amongst programmers in wishing it could finish.
I might prefer to see higher emphasis on the craft and artwork of software program.
I might prefer to see us make full and intentional use of the unimaginable
energy accessible to us now.

The
retrocomputing
(wikipedia.org)
pastime has frequently proven how far more we may have completed with the
house computer systems of the Nineteen Eighties if we had continued to make use of them.
In lots of circumstances, they have been proven to have the ability to run applications
beforehand thought inconceivable.
The issues we may do with present {hardware} are certainly
much more wonderful, however it is going to be maybe many years earlier than we discover
out.
chuck moore operating an IBM 704

In 1958, Chuck Moore created a dirt-simple interpreter on an
IBM 704. That pc crammed a room and value about 2 million {dollars}.

I can purchase a extra highly effective pc (minus the superior management panel
with lights and switches) right now for literal pocket change
within the type of a “microcontroller”, an entire pc on a single
silicon chip, and write a strong Forth system for it. That pc
can run on a coin cell battery or perhaps a tiny photo voltaic panel, sipping energy
the place the IBM 704 inhaled it.

There has by no means been a extra unimaginable time for small-scale computing.
Just like the explosion of non-public computer systems within the Nineteen Eighties, the time is ripe
for enjoyable, artistic, fascinating, helpful, and really private
computer systems and software program.

These instruments can do helpful work and so they may also educate and delight us.
Concepts like Forth are ripe for rediscovery as we study thrilling new
methods to compute with arrays of cheap, low-power computer systems.

We are able to pursue this line of considering for pragmatic causes, or simply
as a result of it’s stunning and enjoyable and price doing for its personal sake.

Chuck Moore is principally retired now, programming and toying with
software program with no deadlines or shoppers.

It’s now on us to take up the mantle of Forth, to champion the values
of ingenuity, magnificence, effectivity, and ease.

Forth is…

Easy

To essentially perceive the worth of Forth (and particularly Chuck Moore’s
later work on Machine Forth and the GreenArrays computer systems), we should think about the
distinction between “easy” and “simple”.

We have been blessed with the power to talk of this distinction by
Wealthy Hickey in his sensible discuss,
“Simple Made Easy” (2011)
(youtube.com)
which each and every developer ought to see at a while of their life.
(Or learn the transcript of Simple Made Easy
(github.com)
supplied by Mattias Nehlsen.)

Forth just isn’t simple. It could not at all times even be nice. However it’s actually easy.
Forth is without doubt one of the easiest programming languages there has ever been.

A crafted language

If the very best software program is actually crafted for downside at hand, then
it is smart that an thought programming language would even be
crafted for the issue at hand.

A completely wonderful speak about language design,
Man Steele’s
Growing a Language (1998)
(youtube.com)
demonstrates how languages are constructed up from primitives.
The discuss is a efficiency artwork and deeply insightful.

Steele helpfully additionally wrote up a transcript of the discuss:
Growing a Language (PDF)
(virginia.edu)
Think about Steele is saying “Forth” right here instead of “Lisp” as a result of
the purpose is similar:

“Lisp was designed by one man, a sensible man, and it really works in a manner
that I feel he didn’t plan for. In Lisp, new phrases outlined by the
person appear like primitives and, what’s extra, all primitives look
like phrases outlined by the person! In different phrases, if a person has good
style in defining new phrases, what comes out is a bigger language
that has no seams.”

Go forth and create the proper
programming language for you!

chuck moore as an adorable wizard

I promised I’d present you a magic trick on the finish of this text.

Behold, a brand new definition for the integer 4:

: 4 12 ;
    

Which I shall now use in a sentence:

." The worth of 4 is " 4 . CR

The worth of 4 is 12
    

Tada!

Large due to Ariel and particularly Amy (who was concerned in any respect levels
and to whom we owe “Could the Forth be with you”)
for the numerous wonderful options and fixes for this web page.
And because of a dozen others for catching typos and errors and emailing
them to me. Corrections are at all times a lot appreciated.

Source Link

What's Your Reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0
View Comments (0)

Leave a Reply

Your email address will not be published.

2022 Blinking Robots.
WordPress by Doejo

Scroll To Top