navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top Programming.html#Programming Gri: Mathematics Gri: RPN stack operators index.html#Top Gri: RPN stack operators

10.9: Rpn (reverse-polish notation) Calculator

Gri can do simple mathematics on numbers. The syntax is reverse-polish notation (`rpn'), which is used in some calculators. Most users can learn rpn in a few minutes, so don't worry if you don't know RPN yet.

Syntax: rpn expressions can be used anywhere Gri expects a number. RPN expressions start with a opening curly brace (`{') which is immediately followed by the word `rpn'. rpn expressions end with a closing curly brace (`}'). Instead of `set x size 10' you could write `set x size {rpn 20 2 /}', where the expression `{rpn 20 2 /}' tells Gri to insert the number 20 onto a stack, then insert the number 2 above it on the stack, and then divide the top two items on the stack. The following are equivalent:


set x size {rpn 20 2 /}           # 10 = 20/2
set x size {rpn 30 2 / 5 -}       # 10 = (30/2-5)
set x size {rpn pi 3.1415 / 10 *} # 10 = 10*pi/pi

If an rpn expression contains a variable whose value is ``missing'', then the value of the result of the expression will also be missing (unless the value of the missing variable is thrown away with a ``pop'' operator). However, if a missing value just happens to occur as the result of an intermediate calculation, then the result is not considered to be missing.

RPN operations can be divided roughly into the following groups.

navigation map