I don't want to be just the person in computerphile who does all the history and nothing but history I'd actually like to do some
Programming with you and some of you in the comments what she said
Why don't you do Java or teach us some C or something, and I thought no
I've got a very good opportunity here to lead off from the PostScript story
That's I've been telling and actually do some PostScript programming with you
It's pretty easy to get software both for Linux for Mac and for PC that will enable you to
Run of the programs as I develop with you and even create ones of your own and I think that's important
It's no use me getting into some language where the support is utterly minimal
PostScript was invented ass Adobe by John Warnock and a team of co helpers it built on work that he'd done
several years earlier when he worked with the Evans & Sutherland graphics company
I think he'd done some more work on it's
In a language called Jam when he was at Xerox PARC
The M in Jam standing for John John and Martin that's right M is for Martin Newell
Anyway, it became fully fledged when it got to Adobe. It's a very big language
It's got something like 400 operators in all but I think I've already said and let me emphasize again
It's far more than a two-dimensional graphics language. It is a full-blown programming language
It can do anything as any other language can do it can do anything that the Turing machine can do and for that reason
It's called a Turing complete language
We're going to print out six instances of the text computer file
first of all
I'm going to do it with if you like a proper conventional PostScript program and
No surprises in guessing that it will involve a for loop that goes around six times
It's vital that you know, something about PostScript and how it works
First of all, it's an interpreted language many of you will know what that means. It means it's things like
Perl Python
JavaScript for the older generation among you it's things like lists
What it means if you have an interpreted language is you look at what has been
Requested in the program and you do it there and then that way you gain great flexibility
It doesn't necessarily run all that fast. That's the real challenge
it's in the very nature of PostScript that it uses a
notation called post fix and
that in turn relies for its
Execution environment on this notion of a stack we may be in a position to put this out as a separate
Film in its own right? This is postfix. I
think his name is pronounced on and like
Yanukovych people being unable to pronounce his name correctly and getting all the stresses and accents wrong
Decided that rather than pronouncing what they found hard. They would call this
polish
Notation now actually polish notation applies to using anything that isn't in fix. I've seen prefix notation being called
Forward polish notation. I've seen postfix giving its traditional name of reverse
polish notation
The stack is last in first out storage
The last thing I put on the stack I pushed it on was this little white one?
The only thing I can directly get at at the top of the stack is the same thing
So it's the last thing in and it's the first thing off and the act of taking it off
The stack is called popping the stack. So we'll keep this to one side just to remind us that
PostScript is totally totally stacked based in every single thing it does and I'm now in a position
That I can actually go through the four loop version of the program with you
I'll be talking about stacks until you're fed up of hearing about them
First of all, anything beginning percent in PostScript is a comment
There's a very special comment right at the top of your post group program
which effectively
invites you to announce which version of adobe postscript this program will be compliant with
What I've said here is this requires PostScript defined by Adobe version 2.0 aught
Most of the time in most PostScript interpreters nowadays, you don't really have to bother about that
minimum you can get away with is just the percent and the exclamation mark
Opinions differ as to whether exclamation mark or typical shriek or bang. It's all from comic books, you know shriek
Exclamation mark exclamation mark or bang lots of exclamation marks. I don't call it back
So when I say % bang it means it's the top of a postscript program PostScript allows you to have things like characters
Real numbers integer numbers things of that sort that you would expect
It's not what is called a strongly typed language
You don't have to tell PostScript here that six is an integer
It knows and it's fairly cavalier about what it will let you do with those but then it says if you ask me to define
Six as being n which is what this is doing then fine
I'll regard it as being an integer version of six if you mean no six that I can print out on the printer
So it's the ASCII character six then I will give you
Conversion operators that will convert it into printable strings
So if it finds out from context what it thinks is plausible for the type of these things. So here we go
Look our first example use of reverse polish
PostScript notation
/n means I want to define a variable called n here it is
on the stack
There's the six
Death is a postcode operator, which does definitions in other words
It binds a value to a variable name. So what this is saying is
make my integer variable n
Represent the value 6 and it does that by taking them off storing away n with the value 6 inside it somewhere inside
Postscript memory now. Here's another
wonderful example of
postscript postfix use
First op around this time the font name
Ocr-a, so what I'm saying to postscript here is you know where the fonts are kept
But I'm using find one called ocra and push on the stack of the name the font name
ocra when you found OCR a push on here the required point size of it and the
Operator this is called select font. So it binds this point size to this font and says right that's what we're using
I think I said
Way way back and early on that we might encounter conventional programming constructs in PostScript. And we do this is a full loop
But notice it's in postfix the operand which is the four comes last
Next to last in the curly braces is a bunch of program that we wish to
Execute every time we go around this for loop the weird thing. Oh,
It's maybe not all that weird
Actually, is that the start value the increment value and the final value are specified up at the top here?
So when you come to think about it
if you're only to promote the for up to the top here, it would look a bit like
Java or C
But writing it out this way. Okay, you push the start value you push the increment value and
n the terminating value but n has been defined as six so it's saying basically
Stopping a1 in steps of 1 up to 6 do the following piece of program every time it goes round
What you can rely on
Happening is that the current value of the loop counter will be available to you in the loop body
every time round so it will start off as 1
And I'll do the loop
Then I will increment the 1 to being a to
Choose this one for to next try around the loop
The loop cans will be 2 but here's the really handy thing
It could be 2 but you can access that value of 2 at the top of the stack
Every time you look at the top of the stack
You can rely on having current value of the loop counter there what the loop is going to execute is 10
100 move - there's the operator here are the operands so this one
is the x
position and the default units are
Typographic points and you all know about that 72 points to the inch
This one is the Y position. So all that's happening here your coordinate system
Starts down here at 0 0
it starts at the lower left-hand corner and everything is relative to here if I say
Move 10 in the X Direction 2 there and move a hundred in the Y direction to here. That's
About an inch and a bit attend is about 1/7 of an inch. So roundabout there
I will print my first computer file to be fair
You sometimes find that you 0 0 gets a little bit misaligned with the bottom of the physical paper
Particularly, if you insist on printing onto a full size paper as if it was us letter size paper
But I hope you get the idea here 0 0 we're gonna move a little bit in on the x axis
look a 7th of an inch about an inch up between every instance of this banner as we go up and every time
we do that move to we then gone to the next aisle and it's just says show the
string computer file
Now the way you do strings in PostScript is not with double quotes like you would in Java or C
You put them in round brackets parenthesis
so the only thing now to say well alright, it goes around 6 times they get six versions of
Computer file coming out what on earth is all this and why are you doing that?
first of all
I say a hundred mole Mull is going to say to itself to have the multiply now want two things to multiply together
But do remember I warned you or I told you that at the top of the stack
Every time around the loop is the current loop counter value. So the first time around
This is one
So basically I'm saying a hundred mole and you say that's not enough operands
You need two operands from oh, no
I don't because one of them is implicitly there already at the top of the stack is a one so I'm pushing a
100 on top of it take this big one that represents something big like a hundred I put it on top
But there's the one already there then I say multiply
So the answer is hundred times one is a hundred and I push that back on the top of the stack now the first time
around of course one times under is trivial is 100 but the next time around is going to be two times 100 which will make
200 then three times 100 and so on
Once I've got the correct Y position
Calculated I'm going to use this black one to represent the 10 and remember the 10 points is the X offset every time
Okay, so
I've got now a hundred
I've got ten
How many trouble is?
Unfortunately, you don't want a hundred ten move to
You want 10?
100 move to in other words if I'd written 10
100 move to you stack the 10 you stack the hundred you do the move to the bigger hundred is on top
not underneath
Why did it end up underneath?
well
It ended up there because I wanted to do some calculation and I left it behind as the answer
But PostScript has the answer if your operands on the stack of the wrong way around you do the exchange
the exch operator
I've got a hundred and ten. I need them the other way around
Well, I exchange them
There. Well I've changed what would have been a hundred ten moved to into 10 100 moved to and
don't forget as you read left to right in all of these things the 10 and the
100 the 10 gets pushed on the first the hundred gets pushed on afterwards and that's exactly the order in which
Move to expect to find them. He lifts them off and it says
Why value will be on top the x value will be underneath?
That's the use of exchange then to flip things around at the top of the stack and from then on you know
Everything is utterly
Straightforward, okay
So we've analyzed this PostScript program now with a simple for loop you're familiar with
Moving to a new position on the page with the fact that the show operator
Shows the immediately preceding string of characters and that there's another operator called select font
Which can be used to decide which font you're using and what point size you want it at so there we are
That's the original full loop version of it, which has all the right effects the interpreter
I'm using the PostScript clone interpreter is one of the most famous ones. It's called go script
It was originally written in the early 90s by a guy called Peter Deutsch. It's freely out there
One of the many things that's been added to it over the years is a slightly more powerful
viewing front end as it were called ghost view but ghost vu still relies on go script underneath
So what I'm going to do now is to run ghost view on the for loop version of the program
see the
multi star
crap
Okay, so that's the for loop and that produces six computer files running up the page
We'd like to thank audible.com for supporting us computerphile video
And if you'd like to check out one of their huge range of books go to audible.com slash
Computerphile and you can try one for free today. I'd like to recommend Douglas Adams's book douglas adams
did The Hitchhiker's Guide to the galaxy which I love and then rescued from his computer after his sad death was a book called the
Salmon of doubt. So check that out if you get the chance, so that's audible.com slash computerphile. You can try one for free
Thanks them for supporting this video