Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

RPN ( expression )

Featured Replies

Name & Parameters: [color:red][big] RPN ( expression ) [/big]

Description: This CF will allow you to evaluate an expression with Rerverse Polish Notation.

where entry detrmines order of operation, using a stack to push and pull from.

RPN input would be written :) 10 25 2 * + 40 +

Infix input would be written : ((25 * 2) + 10) + 40

For more info: http://en.wikipedia.org/wiki/Reverse_Polish_notation

Sample Input:

10 25 2 * + 40 +

Results:

100

Recursive: yes

Formula:

// RPN( expression )  or Reverse Polish Notation 

// by Stephen Dolenski 



Let ([

exp = Substitute( expression ; " " ; ¶) ; // pivot expression into a return sep list.

exp_len = ValueCount ( exp ) // count entries.

];





//============================



If(  $i   >   exp_len ;   



Let( $i = 1 ; $stack)

;





If(  Filter( GetValue(exp ; $i) ; "*+-/")  ≠ $null ;   // value is operator



     Let ([

          $result =  Evaluate(GetValue ($stack ; 1 )  &  GetValue(exp ; $i)  & GetValue ($stack ; 2 ))  ;

          $stack =  Substitute( $stack ; [GetValue ( $stack; 1 )  & "¶" & GetValue ( $stack; 2 )  & "¶"  ; $result &¶] ; [GetValue ( $stack; 1 )  & "¶" & GetValue ( $stack; 2 ) ; $result]);

          $i = $i+1

          ]; 

          RPN( exp ) 

          ) // end let



     ; // else append stack



        Let ([ 

        $stack = Case( $i = 1; GetValue (exp ; 1 ) ; GetValue(exp ; $i) & ¶& $stack );

        $i = $i+1

        ]; RPN( exp )

        ) // end let

     ) // end if



) // end if





//============================



) // close let

 

Required Functions:

Author(s): Ocean West

Date: 03/28/06

Credits:

Disclaimer:

FM Forums does not endorse or warrantee these files are fit for any particular purpose. Do not post or distribute files without written approval from the copyright owner. All files are deemed public domain unless otherwise indictated. Please backup every file that you intend to modify.

RPN.fp7.zip

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.