I'm proud of the Reverse Polish Notation calculator shown below (think HP
50g in rpn mode). My question is, can you devise an adverb monad so that
sqrt =: %: monad
produces the sqrt verb below?
Examples
clear'' NB. Initialize global vector STACK
5 2 enter''
5
2
1 dup''
5
2
2
times''
5
4
plus''
9
sqrt''
3
Verbs
clear =: 3 : ',.STACK =: '''''
NB. create and display empty STACK
enter =: 4 : ',.STACK =: STACK , x'
NB. x a list of numbers
dup =: 4 : ',.STACK =: STACK , (- x) {. STACK'
NB. x a non-negative integer
drop =: 4 : ',.STACK =: (- x) }. STACK'
NB. swap?
chs =: 3 : ',.STACK =: (_1 }. STACK), - _1 {. STACK'
sqrt =: 3 : ',.STACK =: (_1 }. STACK), %: _1 {. STACK'
plus =: 3 : ',.STACK =: ( _2 }. STACK), +/ _2 {. STACK'
minus =: 3 : ',.STACK =: ( _2 }. STACK), -/ _2 {. STACK'
times =: 3 : ',.STACK =: ( _2 }. STACK), */ _2 {. STACK'
divide =: 3 : ',.STACK =: ( _2 }. STACK), %/ _2 {. STACK'
--Kip Murray
--
Sent from Gmail Mobile
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm