Post Reply 
New to RPL; Please critique this working sample. Thanks.
09-14-2016, 05:56 AM (This post was last modified: 09-14-2016 06:01 AM by Nick.)
Post: #1
New to RPL; Please critique this working sample. Thanks.
I'm new to RPL. Please critique the following code. I was surprised at the amount of nesting required to implement the local variable + algebraic object style -- that I could not simply keep accumulating (or even reusing) the local variables across multiple objects within the same scope.

Device: HP-48G [Revision R]
Formula: http://www.cs.utsa.edu/~cs1063/projects/...ation.html
Input: M D Y
Output: JD

This was my first thought (failed):

Code:
<< -> m d y
    'IP((14-m)/12' ->NUM -> a
    'y+4800-a' ->NUM -> y
    'm+12*a-3' ->NUM -> m
    'd+IP((153*m+2)/5)+365*y+IP(y/4)-IP(y/100)+IP(y/400)-32045'
>>

...but experimentation showed that the local variables are only accessible to the algebraic or program object immediately following their definition and any subsequent objects within the same scope lose access to the previously defined local variables after additional were defined.

The corrected code:

Code:
<< -> m d y
  << 'IP((14-m)/12' ->NUM -> a
    << 'y+4800-a' ->NUM
       'm+12*a-3' ->NUM -> y m
       'd+IP((153*m+2)/5)+365*y+IP(y/4)-IP(y/100)+IP(y/400)-32045'
    >>
  >>
>>

15087d ; 298.5

Is this appropriate / necessary for handling multiple formulas and the creation of additional local variables? It seems the structure and scope could get messy.

Any feedback is appreciated.

Thanks,
Nick

Edit: Added Device Model / Revision
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
New to RPL; Please critique this working sample. Thanks. - Nick - 09-14-2016 05:56 AM



User(s) browsing this thread: 1 Guest(s)