Porting Postscript code to TRANSCRIPT
Mark Wieder
mwieder at ahsoftware.net
Sat Jan 17 20:05:12 EST 2004
Alejandro-
Saturday, January 17, 2004, 1:55:40 PM, you wrote:
AT> But I do not understand how these commands or
AT> functions works on the data: dup store exch mat sub.
Well, this is based on forth, not postscript, but:
dup: takes the top item on the stack, makes a copy and leaves both
copies on the stack. If you say
1 2 3 dup
you will leave this on the stack:
1 2 3 3
store: do you mean grestore? I don't know what store would be.
exch: in forth this is call swap. It takes the top two items on the
stack and reverses their position. If you say
1 2 3 exch
you will be left with
1 3 2
mat: this looks like a command defined in the code. See the line
/mat {rawdata} def
which looks to me as if it takes the matrix of raw data and stuffs it
onto the stack.
sub: subtract.
length 1 sub will leave length-1 on the top of the stack.
--------------
So the line
/finderrdist {ytt sub exch xtt sub dup mul exch dup mul add sqrt} def
creates a handler called "finderrdist" that returns the square root of
(x squared + y squared), where x squared is the square of the sum of
the difference between the xvalue passed to finderrdist and the value
xtt, and y squared is the difference between the yvalue passed to
finderrdist and the value ytt.
Think of it unrolled as:
ytt sub -- y - ytt
exch -- get x out from under the result
xtt sub -- x - ytt
dup mul -- x^2
exch -- get y out from under x squared
dup mul -- y^2
add -- x^2 + y^2
sqrt -- square root of the result
This comes out in Transcript as:
local xtt
local ytt
-- Return the error distribution of a point x, y
-- from the point xtt, ytt
function finderrdist x, y
local yErr
local xErr
put x - xtt into xErr
put y - ytt into yErr
return sqrt(xErr^2 + yErr^2)
end finderrdist
--
-Mark Wieder
mwieder at ahsoftware.net
More information about the use-livecode
mailing list