[comp.lang.postscript] type checking

don@brillig.umd.edu (Don Hopkins) (09/19/88)

Hey all you Forth enthusiasts (and antagonists!!!) out there:

If you want a powerful flexible object oriented multitasking
interactive PostScript programming environment, then get NeWS!  NeWS
officially stands for "Network extensible Window System", but once you
see it in action, you'll realize that it really means "Neat Window
System!" c(-;

NeWS was written to be portable, and it currently runs on a wide
variety of machine's: Silicon Graphics, Sun, Mac II (under AUX), PS/2
and other 386 boxes (under OS/2), and many other systems.

I could go on and on about how great it is to have a window system
with the high level, device independent PostScript imaging model, and
how much fun you can have with arbitrarily shaped windows, and what a
performance win it is to have an extension language built into the
window system that can perform local input processing and feedback,
and its profound impact on client-server network traffic, and what an
interactive programming environment means for the rapid prototyping of
user interfaces, but I'll leave such discussions for comp.windows.news.  
The issue here is PostScript, the *programming language*! (Like xerox,
the verb ;-) 

PostScript is a cross between Forth and Lisp. Objects are typed, like
in Lisp. PostScript procedures can be passed around as arguments on
the stack, and manipulated like any other data type, since they're
just executable arrays. (i.e. "if" takes 2 arguments: a boolean and a
procedure to execute (if the boolean's true)) Arrays are polymorphic
-- each element can be an object of any type.  Dictionaries can be
used like Lisp association lists or Forth vocabularies.  To define
procedures and variables, you associate names with executable arrays
and other values, in dictionaries. The scope is defined by the
contents of the dictionary stack, searched top to bottom.  PostScript
procedures can have named local variables just by pushing a new
dictionary onto the dict stack, storing into it the arguments passed
on the parameter stack, and other local variables, and popping the
dict stack before exiting.  Names in PostScript are more like atoms in
Lisp than like words in Forth: they don't have value slots or
parameter fields -- they are associated with values in dictionaries.
To execute a name, it is looked up on the dictionary stack, and its
associated value is executed.

One thing that makes NeWS such a powerful environment is Owen
Densmore's object oriented PostScript programming package. It provides
a Smalltalk-like class mechanism, using the dictionary stack to
implement inheritence.  NeWS user interface objects such as menus,
windows, buttons, and scroll bars are defined as classes. You can
customize their look and feel by defining subclasses of these objects,
saving time and reusing code by building on top of what is already
there.

The NeWS server is a MuLTiTaSKiNG PostScript interpreter, with an
event queue, and a hierarchy of arbitrarily shaped overlapping drawing
surfaces (canvases). Lightweight PostScript processes live together in
the server, sharing code and data.  Keyboard and mouse input generate
events, which are put on the event queue and delivered to interested
processes in the order that they happened.  NeWS processes can
communicate with each other by sharing data and sending events. NeWS
provides monitors to synchronize access to shared data structures.
You express interest in the types of event you want, and loop awaiting
and servicing them. You can fork off processes to manage interactive
objects, service events, do background processing, or whatever you
like -- they're cheap!  There is also a PostScript debugger that lets
you enter broken processes, examine their guts, fix them up, and send
them on their way.

NeWS smoothly incorporates many important extensions to the PostScript
language. Certain NeWS data types, such as processes, canvases, and
events, behave just like dictionaries. You can even push them onto the
dictionary stack.  A process dictionary contains keys like
/ExecutionStack, /OperandStack, /State, and /Interests, and a canvas
dictionary contains keys like /Mapped, /Parent, /CanvasBelow, /Color,
and /Retained. Reading and writing the values of these keys can have
magical effects. For example, setting /Mapped in a canvas dictionary
to true makes it appear on the screen; the /XLocation and /YLocation
keys of an event are automatically transformed in terms of the current
coordinate system.

If you want to learn PostScript, NeWS is the way to go -- it's an
exciting and gratifying programming environment!  Don't waste your
time trying to learn an interactive interpretive language like
PostScript by spooling files to a laser printer. NeWS isn't
just for Display -- it's for Interaction!

You can take a look and feel for yourself, if you go to the Sun User
Group Southwest Regional Conference in Albuquerque, on September 30th.
I'll be demonstrating the HyperTIES hypermedia browser, and the
UniPress Emacs text editor, two NeWS applications I've worked on that
make extensive use of interactive PostScript.

If you want to know more, send me mail or post questions to the
"comp.windows.news" newsgroup (or the Internet mailing list
"NeWS-makers@brillig.umd.edu"). (If you want to be added to the
mailing list, please send me mail at the address
"NeWS-makers-REQUEST@brillig.umd.edu".)

	-Don
	don@brillig.umd.edu
	...!uunet!mimsy!don

roy@phri.UUCP (Roy Smith) (09/19/88)

don@brillig.umd.edu.UUCP (Don Hopkins) writes:
> If you want to learn PostScript, NeWS is the way to go -- it's an exciting
> and gratifying programming environment!  Don't waste your time trying to
> learn an interactive interpretive language like PostScript by spooling files
> to a laser printer. NeWS isn't just for Display -- it's for Interaction!

	While I happen to be a true-blue fan of PostScript, and at least a
mild afficiando of NeWS, I can't agree that learning NeWS is the way to learn
PostScript.  It's like trying to learn yacc at the same time you are learning
C, or trying to appreciate Shakespere at the same time you are learning how to
read.  NeWS in a complex system and you can't hope to understand what is going
on unless you already know the fundementals of how PostScript works.
-- 
Roy Smith, System Administrator
Public Health Research Institute
{allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net
"The connector is the network"

mh@wlbr.EATON.COM (Mike Hoegeman) (09/20/88)

In article <3492@phri.UUCP> roy@phri.UUCP (Roy Smith) writes:
>don@brillig.umd.edu.UUCP (Don Hopkins) writes:
  >> If you want to learn PostScript, NeWS is the way to go -- it's an exciting
  >> and gratifying programming environment!  Don't waste your time trying to
  >> learn an interactive interpretive language like PostScript by 
  >> - spooling files
  >> to a laser printer. NeWS isn't just for Display -- it's for Interaction!
  >
  >	While I happen to be a true-blue fan of PostScript, and at least a
  >mild afficiando of NeWS, I can't agree that learning NeWS is the way to learn
  >PostScript.  It's like trying to learn yacc at the same time you are learning
  >C, 
  >or trying to appreciate Shakespere at the same time you are learning how to
  >read. NeWS in a complex system and you can't hope to understand what is going
  >on unless you already know the fundementals of how PostScript works.

I think your analogies are pretty weak. You make it seem like there is
tons and tons of NeWS stuff you have to learn before ever getting your
hands on PostScript and that simply is not true.
  
No one says you HAVE to start out using the NeWS extensions to
postscript.  You can just fire up a psh (PostScript Shell) which gives
you an environment pretty similar to that of a plain 'ol printer and
start typing away!! 

Here's all you have to do. 

	newshost % psh
	newshost % executive
	Welcome to NeWS 1.1
	erasepage 10 10 moveto (Hello world!) show
	:
	...etc...
	:

And, As Don was trying pointing out IT's INTERACTIVE !!  Using a
printer to do PostScript development on is downright primitive in
comparison.  How would you prefer to program in C? By submitting batch
jobs via ftp to some remote machine where it get's compiled and then it
mails you back the errors from the compiler? This is pretty much what
you have to put up with if you are programming in PosctrScript via a
printer.

You don't really have to get into using processes, classes, etc.. at
first if you don't want to but you get the bonus of an interactive
environment and the debugger which is worth the price of NeWS alone if
need to do alot of postscript debugging.

-mike

barnett@grymoire.steinmetz.ge.com (Bruce G. Barnett) (09/21/88)

In article <23378@wlbr.EATON.COM>, mh@wlbr (Mike Hoegeman) writes:
> You can just fire up a psh (PostScript Shell) 

A much easier way is to use the postscript.el mode that
comes with the GNU-emacs/NeWS package on columbia.edu.

Then edit your postscript file, type C-c C-c, and the postscript
is displayed on the screen. Change one line, whatever, type C-c C-c again,
and you see the differences. 

You may have to write something that draws a blank box as the image is
temporary, and a new image overwrites the old one. (without clearing).

But this is a very easy way to learn what postscript is doing, and
requires NO knowledge of NeWS other than starting, installation, etc.

You can learn NeWS by adding extensions later.
-- 
--
Bruce G. Barnett  <barnett@ge-crd.ARPA> <barnett@steinmetz.UUCP>
		uunet!steinmetz!barnett

childers@unet.pacbell.COM (Richard Childers) (09/23/88)

In article <13613@mimsy.UUCP> don@brillig.umd.edu.UUCP (Don Hopkins) writes:

>Hey all you Forth enthusiasts (and antagonists!!!) out there:

Postscript is, *at best*, a highly specialized subset of Forth ...

>You can take a look and feel for yourself, if you go to the Sun User
>Group Southwest Regional Conference in Albuquerque, on September 30th.

Ah, I knew there was *something* commercial involved.

>I'll be demonstrating the HyperTIES hypermedia browser, and the
>UniPress Emacs text editor, two NeWS applications I've worked on that
>make extensive use of interactive PostScript.

And selling them, no doubt. Please don't use the Usenet for advertising,
covertly or overtly.


-- 
  "The leech's kiss, the squid's embrace,   ..!{amdahl,ames,oliveb,pacbell}!
   The prurient ape's defiling touch:        childers@chaos.unet.pacbell.COM
   And do you like the human race ? 
   No, not much."                        -- Aldous Huxley, 'Ape And Essence'

ron@topaz.rutgers.edu (Ron Natalie) (09/24/88)

Lighten up, chum.  HyperTies and pie-menus are Don's research projects
at the University of Maryland.  Don has done more than anyone outside
of Sun (perhaps even inside of Sun as well) to further the interactive
postscript environment as provided by NeWS.  Don's stuff is of such a
high quality that Sun goes out of their way to make sure that there is
a workstation at his disposal to demonstrate whatever he's cooked up
this time.

ns@cat.cmu.edu (Nicholas Spies) (09/25/88)

Could someone explain the relation between NeWS and Display PostScript? Also,
does anyone know _why_ PostScript and Forth are similar? Is it just a
consequence of both being stack-based, or was PostScript developed from 
Forth? Or from L* (L-star)? (L* was developed at CMU some years ago and also
used datatyping of stack items; sorry I don't name of its author offhand...)

I've always wondered what might constitute the smallest set of language
primitives that would allow the construction of an arbitrary number of
program constructs of arbitrary complexity (that is, "any program"). Forth,
as defined in F-83, has about 130 language primitives (of which, usually,
only a third or so are Forth "primitives" defined in machine code, depending
on the taste of the implementor).

In contrast, POP-11 (mentioned by Dick Pountain in Byte a while ago) is
based on a vitual machine that has only 17 instructions (it is also
stack-based). POP-11 combines aspects of Forth, LISP, Prolog and even Pascal:
it compiles to VM instructions and in interpreted (sort of like Forth); makes
extensive used of lists; has built-in sophisticated pattern-matching and
database support, but looks fairly much like a structured procedural
language. You also have access to compiler, as in Forth...

As a further digression, factorial of n can be calculated in POP-11 with:

define fact(n);
	if n == 1 then
		1
	else
		n * fact(n-1)
	endif;
enddefine;

Although Forth is fun to work with, its primitives seem rather arbitrary,
with (useful) oddities such as -TRAILING, >BODY and TIB having the same
official status as DUP and SWAP. Perhaps Forth standardization (which I
feel is sine qua non for its general acceptance) would benefit from factoring
and defining genuine, irreducable primitives on the one hand, and then
the environment/I-O aspects of the language in terms of these primitives,
of course leaving actual details of implementation to implementors.

Distilling Forth down to a smaller set of kernal primitives might make it
more consistant and, paradoxically, closer to the minimalist philosophy
espoused by Chuck Moore than Forth as it now exists...


Alpha-POP for the Mac is available from:

Cognitive Appliations Ltd	Computable Functions, Inc.
4 Sillwood Terrace		35 South Orchard Drive
Brighton			Amherst, MA 01002
BN1 2LR				413-253-7637
England

My only connection with Alpha-POP or its authors is as a satisfied customer.

-- 
Nicholas Spies			ns@cat.cmu.edu.arpa
Center for Design of Educational Computing
Carnegie Mellon University