Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

problem passing parameters?

problem passing parameters?

problem passing parameters?


I thought I understood stack programming until I tried postscript. I cannot seem to pass parameters to a named function and get back a result, as in the following example (tested on ghostscript) any help?

0 0 1 setrgbcolor
/average {add 2 div} def
  50 150 average   % this should put 100 on the stack, right?
  100 moveto 100 0 rlineto 0 100 rlineto -100 0 rlineto
} ufill

RE: problem passing parameters?

Your problem isn't the "average" procedure. It would leave "100" on the stack, if you let it.

The problem is that "ufill" expects a path. You're never actually creating a path, because you have those operators bracketed with curly braces.

Curly braces defer execution, and create an array. When you place that array back on the stack, it executes. That's why we call them "procedures" or "functions". They ain't, really. They are executable arrays.

My point is, nothing between "newpath" and "ufill" ever gets executed in your program.

The OTHER problem is that "ufill" expects a more complex path than you're creating. It needs a "self-intersecting" path, in order for the non-zero winding rule to have something to work on. You really just need "fill".


% set currentcolor in the graphics state:
0 0 1 setrgbcolor

% create key-value pair (name/array) in currentdict:
/average {add 2 div} def

% create a new path in graphics state:

% create a currentpoint in graphics state:
50 150 average 100 moveto

% build a path in graphics state:
100 0 rlineto 0 100 rlineto -100 0 rlineto

% close that path with appropriate linejoin:

% fill the currentpath with the currentcolor:

% "output" the page:

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close