r+
r-
r*
r/
rpn
9.0
top
← prev up next →

Reverse Polish NotationπŸ”— i

(require rpn ) package: rpn

Reverse Polish Notation (RPN) is a way of writing expressions commonly found in calculators and Forth-like programming languages. In RPN, an expression is a list of instructions for manipulating data on a stack. The most basic instruction is to push a value onto the stack. Function call instructions pop a function’s arguments off the stack and push its results onto the stack. The rpn library represents an RPN program as a call to the rpn function with the program instructions as arguments.

Examples:
> (rpn 1)

(rpn-stack 1)

> (rpn 123)

(rpn-stack 1 2 3)

> (rpn 123r* )

(rpn-stack 1 6)

> (rpn 123r* r+ )

(rpn-stack 7)

> (rpn 123r* r+ 2)

(rpn-stack 7 2)

> (rpn 123r* r+ 2r- )

(rpn-stack 5)

1RPN StacksπŸ”— i

procedure

( rpn-stack? v)boolean?

v:any/c

procedure

( rpn-stack-push stackinstruction)rpn-stack?

stack:rpn-stack?
instruction:rpn-instruction?

2RPN InstructionsπŸ”— i

procedure

( rpn-instruction? v)boolean?

v:any/c

2.1Pushing OperandsπŸ”— i

procedure

( rpn-operand? v)boolean?

v:any/c

procedure

( rpn-operand v)rpn-operand?

v:any/c

procedure

( rpn-operand-value operand)any/c

operand:rpn-operand?

2.2Calling OperatorsπŸ”— i

procedure

( rpn-operator? v)boolean?

v:any/c

procedure

( binary-rpn-operator binary-function)rpn-operator?

binary-function:(-> any/c any/c any/c )

procedure

( rpn-operator #:functionfunction
#:input-arityinput-arity
#:output-arityoutput-arity)rpn-operator?
function:procedure?
input-arity:natural?
output-arity:natural?

procedure

( rpn-operator-function operator)procedure?

operator:rpn-operator?

procedure

( rpn-operator-input-arity operator)natural?

operator:rpn-operator?

procedure

( rpn-operator-output-arity operator)natural?

operator:rpn-operator?

2.3Arithmetic OperatorsπŸ”— i

3RPN NotationπŸ”— i

procedure

( rpn instruction...)rpn-stack?

instruction:any/c

4Streaming RPN ComputationsπŸ”— i

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /