Category:PostScript: Difference between revisions
move initlib |
|||
Line 9: | Line 9: | ||
*[http://code.google.com/p/postcanvas/ postcanvas - Open-source PostScript interpreter written in JavaScript] |
*[http://code.google.com/p/postcanvas/ postcanvas - Open-source PostScript interpreter written in JavaScript] |
||
*[http://pages.cs.wisc.edu/~ghost/ Ghostscript opensource postscript interpreter with a lot of extensions. ] |
*[http://pages.cs.wisc.edu/~ghost/ Ghostscript opensource postscript interpreter with a lot of extensions. ] |
||
==Library== |
|||
Here is a library of functions tested in ghostscript. It is assumed to be loaded before startup with a command line such as |
|||
<lang> |
|||
ghostscript -q -dNODISPLAY -c '(initlib.ps) run' |
|||
</lang> |
|||
initlib.ps |
|||
<lang postscript> |
|||
% given [sym x y z] get sym and [x y z] separately |
|||
/getname {dup 0 get exch} bind def |
|||
/getbody {dup length 1 sub 1 exch getinterval} bind def |
|||
/rup {3 1 roll} bind def |
|||
/rdown {3 -1 roll} bind def |
|||
% convenience for binding. |
|||
/. {bind def} bind def |
|||
/' {load} bind def |
|||
% .makeoperator is ghostscript specific. But this gives us lexical binding. |
|||
/# {exch dup rdown .makeoperator bind def} bind def |
|||
% A few lispy words |
|||
/first {0 get}. |
|||
/car {first}. |
|||
/!first {dup first}. |
|||
/rest {dup length 1 sub 1 exch getinterval}. |
|||
/cdr {rest}. |
|||
/!rest {dup rest}. |
|||
/head {dup length 1 sub 0 exch getinterval}. |
|||
/!head {dup head}. |
|||
/tail {dup length 1 sub get}. |
|||
/!tail {dup tail}. |
|||
/cons {[rup aload pop] }. |
|||
/tadd {[rup aload length 1 add -1 roll] }. |
|||
/uncons {getname getbody}. |
|||
/concat {exch [ rup aload pop counttomark -1 roll aload pop ] }. |
|||
% higher order |
|||
/map { |
|||
[ rup forall ] |
|||
}. |
|||
% [1 2 3 4] {1 add} map |
|||
/fold {rup exch rdown forall}. |
|||
% [1 2 3 4 5] 1 {add} fold |
|||
% let requires "end" to denote end of scope |
|||
/let {dup length dict begin reverse {exch def} forall}. |
|||
% let* assumes dictionary management is separate. |
|||
/let* {reverse {exch def} forall}. |
|||
% [1 2 3 4] 0 {+} fold |
|||
% name - filter is taken so we are left with.. |
|||
/find { |
|||
4 dict begin |
|||
/aif {0 /get /if}. |
|||
/atox { [ exch cvx {cvx} forall ] cvx}. |
|||
[ rup [ /dup rdown /exec /not [{pop}] aif ] atox forall ] |
|||
end}. |
|||
% ifs with stack invariant predicates. |
|||
/ift { |
|||
4 dict begin |
|||
[/.if /.then] let* |
|||
count array astore /.stack exch def |
|||
/_restore {clear .stack aload pop}. |
|||
.stack aload pop .if { |
|||
_restore .then |
|||
} { |
|||
_restore |
|||
} ifelse |
|||
end}. |
|||
% 2 {1 gt} {=} ift |
|||
/ifte { |
|||
4 dict begin |
|||
[/.if /.then /.else] let* |
|||
count array astore /.stack exch def |
|||
/_restore {count array astore pop .stack aload pop}. |
|||
.stack aload pop .if { |
|||
_restore .then |
|||
} { |
|||
_restore .else |
|||
} ifelse |
|||
end}. |
|||
% 1 {2 gt} {3 * =} {2 * =} ifte |
|||
/apply {exec}. |
|||
/i {cvx exec}. |
|||
% make a unit list. |
|||
/unit {1 array astore cvx}. |
|||
/succ {1 add}. |
|||
/pred {1 sub}. |
|||
% combinators |
|||
/linrec { |
|||
[/.if /.then /.rec /.join] let |
|||
.if {.then} {.rec /.if ' /.then ' /.rec ' /.join ' linrec . join } ifelse |
|||
end}. |
|||
% and convenience |
|||
/reverse {{} {exch cons} fold}. |
|||
/puts {print (\n) print flush}. |
|||
/, {(=============\n) |
|||
print pstack |
|||
(=============\n) print}. |
|||
% set the prompt |
|||
/prompt {(>| ) print flush} bind def |
|||
</lang> |
Revision as of 22:22, 24 March 2011
![Language](http://static.miraheze.org/rosettacodewiki/thumb/2/27/Rcode-button-language-crushed.png/64px-Rcode-button-language-crushed.png)
This programming language may be used to instruct a computer to perform a task.
See Also: |
|
---|
PostScript originated as a printer definition language invented by the founders of Adobe. The language was necessitated by the increasing demands of printing and rendering jobs on the computers of the 70s. These tasks were therefore pushed to the printers themselves, with the result that printers now had chips and built in interpreters for PostScript. With the growth of printing complexity, some printers ended up having even more powerful processors than the master systems themselves.
Although now almost displaced by the Portable Document Format (PDF), also developed by Adobe, PostScript's USP lies in it's being a Turing complete language with support for the basic data types and fundamental structures and concepts of Computer Science. Many interpreters and viewers of PostScript are available, some even for free. Although primarily a language suited for 2D graphics, PostScript is complete as a language and able to hadle normal computation tasks.
See Also
Subcategories
This category has the following 3 subcategories, out of 3 total.
@
- PostScript Implementations (empty)
- PostScript User (28 P)
Pages in category "PostScript"
The following 91 pages are in this category, out of 91 total.