Programming in PostScript - Computerphile
Audible free book: www.audible.com/computerphile
PostScript is more than just a 2D graphics language, it's a fully operational programming language - Professor Brailsford explains how it works.
Reverse Polish Notation and the Stack: • Reverse Polish Notatio...
At 7min 15seconds the Professor refers to for as being the 'operand' when he meant the 'operator'.
The Professor's PS Program: bit.ly/postscriptprog
/ computerphile
/ computer_phile
This video was filmed and edited by Sean Riley.
Computer Science at the University of Nottingham: bit.ly/nottscomputer
Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: bit.ly/bradychannels
Пікірлер: 203
I love Professor Brailsford's videos; he explains things in a very understandable manner and has a knack for anticipating possible questions and misconceptions.
I love Professor Brailsford's presentation style. Pity I never had teachers like that.
Thanks for the video, Professor. For anyone trying the tutorial, it is useful to include the command showpage at the bottom of the script to get your page drawn! You'll not see much otherwise.
I used to love "programming" in PS in the early nineties. Had excellent reference books from Adobe. Even wrote a ray-tracer for a DEC laser printer. Took an entire day to get the results.
This guy is who I want to be when I'm older.
I enjoy your computer history lessons. Some of your stories brings memories that I can remember seeing that type of equipment. My father worked in data processing for banks since the 1960's. Sometimes I would go to the office with him and see the machines at work. Then when I was in the US Navy, the computers were core memory, and loading programs with the half inch mag tape on reel to reel. They did not necessarily want the most cutting edge computers onboard a combat ship, because it needed to be proven technology and had to be made and tested to withstand the harsh conditions that could occur in that environment.
And suddenly TeX does not seems so bad...
@JelmerBorst
10 жыл бұрын
has not ever been bad ;-)
@ZardoDhieldor
10 жыл бұрын
I think TeX is great for documents, but PostScript seems to be more powerful. If I want to insert a graph in a LaTeX maths document I use PS graphics. LaTeX couldn't do graphs itself.
@JelmerBorst
10 жыл бұрын
***** start off with a template, an easy compiler such as sharelatex.com and some Google. The more you use, the easier it becomes
@TheAaaargh
10 жыл бұрын
Zardo Schneckmag GNUplot, a powerful plotting program, can export straight to LaTex. All you have to do in your .tex file is to then \include{graphFile.tex} where you wnat the graph to be. :)
@alcesmir
10 жыл бұрын
Zardo Schneckmag LaTeX can do graphs and graphics by itself! Check out the pgfplots and TikZ packages.
This man should narrate everything.
These series are fantastic. As someone using higher-order programming languages but never having done a theoretical CompSci course I really appreciate the diversity, pacing, and level of depth of these videos. Fantastic job to everyone involved.
Using the standard mathematical signs for the axis, don't see that often in a programming language.
Someone should invent a postfix language called 'Yoda'.
Nice video, professor. Postscript is still used, for exporting high quality graphics files and many professional programs (for example for music engraving) let you print to a PS file... Great to further tweaking...
"Postscript" is a resolution-independent, page description language It underpins all DTP (Desktop Publishing) & pre-press software, including Adobe InDesign, Illustrator, QuarkXPress, etc. etc. etc. If you create PDF's then you'll be using it without realising so
What a nice time to post new Computerphile video! I can eat lunch while I watch.
I've seen some fairly complex and computationally intensive programs written in postscript. My brother showed me a project of his, at Lisbon U, doing a genetic selection algorithm for composite materials. That was about 15 years ago and I was just a child back then. I didn't understand much of the programming side but it stuck with me how versatile postscript can be. It was also probably the first time i've seen genetic algorithms in action. Another direct application of postscript programming: all graphics in his published papers were done in postscript. The papers were written in TeX and TeX allows embedding postscript graphics. You can write the postscript bits by hand, which means you can create graphics that do live computations, and that is very useful especially if you're writing math proofs.
Computerphile just gets better and better.
Of all the people on Computerphile, Professor Brailsford is the only one whose videos require me to consult the Jargon File on a regular basis. And it's awesome. bang: n. Common spoken name for ! (ASCII 0100001), especially when used in pronouncing a bang path in spoken hackish. In elder days this was considered a CMUish usage, with MIT and Stanford hackers preferring excl or shriek; but the spread of Unix has carried ‘bang’ with it (esp. via the term bang path) and it is now certainly the most common spoken name for !. Note that it is used exclusively for non-emphatic written !; one would not say “Congratulations bang” (except possibly for humorous purposes), but if one wanted to specify the exact characters “foo!” one would speak “Eff oh oh bang”. See shriek, ASCII.
Can you PLEASE do a video on FORTH and also some of it's version history. And a follow up video with some FORTH programming? Thanks. I do like your videos a lot.
Thanks, this video brought back memories. I did some PostScript programming for fun back in 1989 or 1990 in an editor called LSE on a VT220 terminal connected to a microVAX and a DEC laser printer.
Interesting. Any possibility of getting some TeX / LaTeX videos?
I don't want the videos to stop. I'm learning way too much right now haha. Thanks so much for the great resources!
Doesn't the mul operator pop the 100 and the loop counter off the stack and replace it with the product? What happens with the next loop iteration? Answer: the curly braces protect the stack so that the loop value is preserved for the next iteration.
This is awesome. I had no idea what postscript was, but this makes perfect sense to me. Thank you Computerphile.
One of the most interesting videos on the channel, among many amazing ones. Interesting even for us who are supposed to know such stuff, but belong to a younger generation. Professor Brailsford is always a joy to watch. This video definitely needs a follow-up (and preferable several ones!) - you got me interested in stack-based languages :-) P.S. Of course Linux is better for programming - I'd even argue that Unix-like OSes are better for everything.
Wow, I actually understand this now. I feel like I have a slightly better grasp on pointer position and stack pushing. Nicely done; I wouldn't mind more of these!
another great video with Dr. Brailsford. born to teach.
Don't worry, Brailsford, I never saw you as "the history guy". I see you as "the text guy".
@kaitlyn__L
10 жыл бұрын
or "the relaxing guy" :3
@justahker3988
10 жыл бұрын
"The typesetting guy" would be slightly more accurate.
@kaitlyn__L
10 жыл бұрын
well, he explained the history of error correction first!
I loved this video. Great to see stack languages get a bit of focus. You could probably do a whole series of videos on postscript: defining new operators and the concatenative nature of the language. I'd be very interested in that. Also from the looks of things in the comments, a video on programming paradigms would be very interesting to people.
Postfix is so elegant. I love it!
Lovely to hear about another stack based language, this really reminds me of the days when I was starting out whith Forth Thanks allot!
Very nice explanation. This PostScript language is difficult to read because of all the implicitly expressions in it.
I love reverse polish notation, it's a little weird at first, but the advantage is that you can describe data flow in a very concise form. So: In C or Java, you'd write a "square" function like this: int square( int x ) { return x * x; } In a postfix language you could probably get away with something like (not sure if this works in Postscript): /square { dup * } def The above pseudo-code means: duplicate the item on the stack and then multiply. It might not seem like it, but the latter is much more computer friendly. Translating the second program is very easy. The C/Java program would require several passes to generate the machine code. One problem is that the system has to try and remember the call signature while reading the code, so if I called square: square("hello"); This would give an error, because "hello" is not an integer. The machine has to remember that square only accepts integers, where as, in the reverse polish notation, it has already read or generated all the parameters before the function is called, so: "hello" square When the machine sees the square function and tries to execute it, the string "hello" will be on top of the stack. When running the square function, it will try to multiply two strings, and yield an error. It doesn't have to figure out the order or operations or a complex set of nested function calls. It can simply read and execute and halt at the first error. Simple but effective. The above was a simple example, but for more complex statements things quickly get difficult in C/Java style. Here, postfix starts to shine. Example: C/Java: square( squareRoot( 2 ^ 10 )); Postfix: 2 10 ^ squareRoot square Another cool thing here is that functions can be spliced, so looking at the last few symbols, we could define a function with: /myFunc { 10 ^ squareRoot square } def myFunc takes a number and raises it to the power 10, then takes the squareRoot, then squares it, and returns the result. You can cut/paste a sequence of symbols, and replace with a single symbol.
I like how the Apple monitor is turned around to face the wall, like it's in Timeout!
I'm rather surprised. I'd have expected 0,0 to be the top left corner, not the bottom left.
I see OpenSuse on the screen, the professor is a linux user :D
Awesome! This makes me wanna see you do something on TeX or maybe LaTeX or one of the other ones.
***** You should really include a link to the source file in the video description. It's not too bad in this video, but if you venture on to a bit longer code snippets you really should do it. Other than that, I'm very glad to see some actual programming on here!
@possiblydavid
10 жыл бұрын
It actually is in the description now.
very good and informative, I'd like to see more videos like this!
Thank you Professor! Loved watching this. Great teaching style.
When the for-loop counter is multiplied by 100, doesn't the result replace the original loop counter in the stack?
Try the example below, changing the "/maxdepth 1 def" to other values & see the fractal pattern become more & more complex as the iterations are increased (if I go above 13 my computer takes a while to render the (extremely) complex image) This example really shows the power of this language
That moment when you smile a wry smile as you realise that you've actually programmed with ghostscipt and ghostview before! Wow, the programming I've done actually can be adapted. Yay!
"both for Linux and Mac and PC" - I like it! ☺ Seems like they switched to Qubits already!
For someone who's only used languages using PreScript notation this is extremely confusing. I don't see why this type of notation would be useful. Can someone elaborate on that please ?
Followed this on KDE with kate and Ocular. I had to add the command "showpage" at the end of the script to produce visible text.
Why on earth would they make the coordinate system start in the lower left corner and run up the page? Text runs down the page.
Why doesn't this corrupt the stack? If the loop counter is popped off the stack by mul and replaced by the answer how does the loop know the correct number to increment for the next loop? Is the loop count stored somewhere else but also pushed to the stack?
Hrrm, have you not screwed up the stack -- the loop counter is now lost and the stack is one level higher than it was? -- maybe the postscript interpretation of end-of-loop always re-normalizes the stack position and actually stores the loop count elsewhere, or similar?
I remember Push and pop stack handling! used it in BAL. Never was much good at it, guess it's because I was drunk most of the time, but this was a great poke to the remember button. Thank you
This is old school! Very nice :D
¡Fantástico! Gracias chicos.
So then the loop counter value that is on the stack is basically a copy of the same value stored somewhere else?
In 92 I created a ps program to print forms that flows data across pages differently in each section long before wysiwg databases.
If you haven't already done so, a video on types, typed vs. untyped languages and compiled vs. interpreted languages would be helpful for intuition. strings, characters, numbers, structs, objects, references, data structures and algorithms ... I think it would be fun :)
@Christophe_L
10 жыл бұрын
I agree! Categorization of languages is a topic that isn't discussed very much in the classroom, and is usually left for Computer Scientists.
is there a reason you had to define n=6 and then reference n, instead of just referencing 6 directly? or was that just to show how defining variables worked? would a for loop with parameters 1 1 6 not work?
Loved this!!!!
The most amazing thing with Postscript is the ability to redefine operators. I am probably wrong, but I do not think you can redefine basic operations in most programming languages. For example, can you redefine "+" in C? I do not know of any other language that you can do the following: (keep in mind a == just shows you a result). -------- Program: 5 3 add == ------ Result 8 ----- Program %!PS /add { systemdict /add get exec 1 systemdict /add get exec } def 5 3 add == ------ Result 9 Now anytime you use add in the program after the statement above, it will not add properly. This may seem useless, but you would be amazed on what you can do with the above and modify a printers behavior.
If you are on a Mac, simply save the document as a TEXT file (NOT MS-Word, for example) & drag & drop onto "Preview" ... this will render the Postscript
writing non-trivial programs in postscript is a nightmare. there are a lot of things it can't do (e.g. sockets, unbuffered reads), since it has no facility for system calls. it's a lot easier if you make liberal use of dictionaries, and get a good understanding of how it handles references, but it's still not much use as a general-purpose language. it's an interesting challenge though.
I recall Brian Reid writing the DECwrl logo in postscript using all manner of tricks to get it to look right!
I remember running into a paper on fractals that used postscript to generate all it's illustrations...
Funny enough I had my first time learning people call exclamation mark "Bang" through a music game In The Groove 2 which had a music track in it that was named modernly enough, just "!" - some people addressed it as "Bang by so and so" and I was like "But it is exclamation mark... no?"
When the increment counter on the top of the stack is removed, does it get replaced somehow? How does that work?
Loved programming my HP48 in RPN
+1 for bang! Never heard of "shriek" before. Is that common in the UK?
Interesting. I never knew that postscript was an actual programming language. I always thought it was just a document format.
@RealDealHolyfield2099
10 жыл бұрын
Me too. I used to used a Postscript printer called Postscript Level II to export Autocad drawings to other graphic programs. I never thought about the underlying code.
Question from US: Since A4 size paper is metric based, is it ever confusing the fonts are measured in dots per inch? I never realized the inch units are also part of the programming language.
For the exch operator, what if there's more than two operands? Will it just flip the order of all of them on the stack?
So now I know what it means when I print something to the PostScript printer and get a stack overflow. I guess to many things were on the stack, and information got lost?
thank you, that was awesome
If the "mul" Operator takes the for-counter out of the stack, how does the programm know what the count is for the next round?
it's really bothering me that his omputerphile> is not enclosed. how bout or
@5lammer
10 жыл бұрын
not really, just considering
@Niosus
10 жыл бұрын
Sam Smith (Poor you
@ze_rubenator
10 жыл бұрын
Niosus I hate it when people end in the middle of
@aphilra
10 жыл бұрын
Detecting a little bit of OCD here ;D
@daisukekichigoru4900
10 жыл бұрын
IT'S CDO!!!
I'd like to see some stuff about assembly
So, if RPN languages are strictly LIFO on the stack, how is it possible for my HP48 to scroll through and pick values out of the stack?
What if you want to use /n multiple times? what's the function for that?
A small remark. Python is not an interpreted language: it's compiled to bytecode, which is then executed in a virtual machine, just like Java, C#, and a lot of other languages.
as a programmer I find this very interesting
Can you talk about LaTeX as well at a later stage?
I don't understand. Wouldn't popping the for loop's counter off of the stack break the for loop? The second time through the loop, the for command would try to pop the current value of the counter only to find that it isn't there, having been popped earlier.
Why doesn't postscript use the coordinate system where 0,0 is the upper-left corner of the paper. AFAIK this coordinate system was developed for TVs and was ported for a lot of use in computers because it is very intuitive for how we read documents and create them in our heads. It is less intuitive maybe for those who have done lots of paper math but it is much easier to work with if you are trying to make something readable and seems like it would be a perfect fit for postscript. Is there something I am missing or is this something that has been covered before?
Make a video on the OSI Model, please!!!
Is that a "Buffy the vampire slayer" DVD in the background beside the monitor ?
@GegoXaren
10 жыл бұрын
Not a DVD, it is a binder.
nice video!
can you please talk about something other than postscript
Good stuff indeed.
Who else has seen what happens if you send PS to an old HP LaserJet without the PS cartridge being in? :-)
This is very interesting BANG
Can you explain how computer gets data from hard drive ?
When you write comments in the middle of a video, instead of " " you should write "".
Which distro/DE was the professor using?
@kaitlyn__L
10 жыл бұрын
elsewhere in the comments says opensuse!
Can you make graphical games in PostScript?
Please talk more about algorithms :)
I love how this is one of the few files that actually assumes you have a brain, and teaches you something ^_^
Lisp has not been only an interpreted language for a very long time.
are thse your professor from computer science course?
Can you show how computer gets data from hard drive?
So why not "10 100 mul moveto"? Would that work too without the exchange?
@Turidus
10 жыл бұрын
i dont think so, i think you would get" x 1000 moveto". 10 and 100 would multilply, giving you 1000, and moveto would take the 1000 and the number of loops as argument. at least if it executes mul for moveto.
"It's easy to get software for both Linux, Mac and for PC [...]" Both? So, does this mean it is easy to get PostScript software for Mac based Linux distributions and and for PC based Linux distributions? What about ARM?
@boblake2340
10 жыл бұрын
I just installed gv on a raspberrypi, which uses the ARM processor. It works :)
Upvoted, but will break your fingers for the defocuses sooner or later.
Also very entertaining