I'm not sure what you are looking for, but here's what I did:

f=:    13 :',.S=: (_2 }. S) ,%/ _2 {. ,.S=: (_2 }. S),*/_2 {.,.S=: (_2
}.S),-/_2 {.,.S=: (_2 }.S),+/_2 {.,.S=:S,(-x){.,.S=:(_1 }. S),-_1
{.S=:,.(S=:''''),y'
   
   2 f 1 2
0
   
   divide times minus plus 2 dup chs 1 2 enter clear ''
0
   
Linda   
      
   

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Kip Murray
Sent: Thursday, June 05, 2014 1:46 AM
To: [email protected]
Subject: [Jprogramming] rpn calculator

The following emulates a simple reverse Polish notation calculator which
operates on numbers at the bottom of a stack, replacing them by the result.
 How would you do it?  (Beware of line wrap.)

   clear =: 3 : ',.STACK =: '''''
   enter =: 4 : ',.STACK =: STACK , x'  NB. x a list of numbers
   chs =: 3 : ',.STACK =: (_1 }. STACK), - _1 {. STACK'
   dup =: 4 : ',.STACK =: STACK , (- x) {. STACK'  NB. x a non-negative
integer
   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'

   clear''
   1 2 enter ''
1
2
   chs ''   NB. Change sign of bottom number
 1
_2
   2 dup''  NB. Can use dup to keep a copy of numbers about to be combined
 1
_2
 1
_2
   plus''  NB. 1 plus _2 is _1
 1
_2
_1





-- 
Sent from Gmail Mobile
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to