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: Acknowledgments
  18: 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

RPN operations can be divided roughly into the following groups.