Thursday, October 24, 2013

HP Prime Programming Tutorial #1: LOCAL, RETURN

Over the next month, maybe month and a half, I plan to post programming tutorials for the HP (Hewlett Packard) Prime.

If you have programmed with the HP 38G, 39g, or 39gii, this language will be similar to those. The programming language for the Prime is named the HP Prime Programming Language (HPPP).

Throughout this tutorial, I am going to use the latest version of the software.

How to start writing a program:

1. Press Shift + 1 (Program).
2. Press New. It is the second touch key.
3. Enter the name of the program. Pressing the ALPHA key twice will turn on UPPERCASE ΑLPHA-LOCK. Pressing ALPHA, Shift, ALPHA will turn on lowercase alpha-lock. To exit any lock, press the ALPHA key one more time. When happy with the name, press Enter.

Rules for Program Names:

1. Letters, numbers, and the underscore character (_) only.

2. The program name must start with a letter.

Structure of a HP Prime Program

A HPPP program is encased of an EXPORT - BEGIN - END structure. The layout is generally like this:

EXPORT program_name(arguments)
commands and comments go here

Each line containing a command generally must end with a semicolon (;). A semicolon can by type by pressing ALPHA then the Plus key ( + ).

Comments can be typed. The are designated by two forward slashes. The slashes are typed by pressing the Divide key ( ÷ ). Anything in the line following the two slashes is ignored in running the program.


Our first program is SQIN, because "Hello World" programs are so 2000s. SQIN takes a number, squares it, then calculates the reciprocal. In short we are defining a custom function:

SQIN(x) = 1/x^2


RETURN: returns a result to the stack (home page). You can return numbers, lists, vectors, matrices, strings, or a combination of these times.
Access: Tmplt, 1. Block, 2. RETURN

All the program code in this tutorial series will be shown in Courier font.


Tip: You can check the syntax of the program just by pressing the Check soft key in the program editor. HP Prime will inform you if there is a syntax error and attempt to point you to the error. If there are no syntax errors, the Prime states "No errors in the program". I use the Check command all the time.

How to run the programs:

Home Mode - Textbook Entry,
Home Mode - Algebraic Entry,
CAS Mode:

Type the program name. Follow the name with parenthesis and enclose the required arguments.

Or use the Toolbox (top row of white keys, 2nd key from the left, it looks like a tool box), select the User touch key, select the program, and input the required arguments.

Home Mode - RPN Entry:

Enter each argument, separate each entry by pressing the Enter key. Type the name, and in the parenthesis state the number of arguments.

For example, if the program TEST has four arguments, the RPN stack would like this:

4: argument_1
3: argument_2
2: argument_3
1: argument_4
TEST(4) to run the program.

Examples to try with SQIN:

SQIN(5) returns .04
SQIN(36) returns .000771604938

The next program will demonstrate the concept of local variables.


LOCAL: Declares any variables to be local to the program. In other words, the variables are created, used, possibly displayed during program execution, and deleted at program termination.
Access: Tmplt, 4. Variable, 1. LOCAL

Tip: You can declare local variables and assign an initial value at the same time. For example: LOCAL K:=1; stores 1 in K and makes K a local variable.

MOPMT calculates the monthly payment of a loan. The arguments are: the loan amount (L), the interest rate (R), and the number of months (M).

LOCAL K:=R/1200;
RETURN "Payment ="+K;

Tip: Use RETURN, TEXTOUT_P, and PRINT to return custom strings, which combine results, messages, and calculations. Parts are connected with a plus sign.

MOPMT(4000, 9.5, 30) returns 150.317437565
MOPMT(370000, 3.5, 360) returns 1661.46534383

Try this and next time in the series I will highlight other things we can do with HPPP. Thanks!


This blog is property of Edward Shore. 2013 


  1. Note: I accidentally published an "unfinished" version of the blog entry last night and removed it when I discovered this. I notice there was a question on the comments section and I would like to answer it here.

    "veganman has left a new comment on your post "HP Prime Programming Tutorial #1: LOCAL, RETURN":

    nice post, I haven't bought a prime yet, and I'm about to, but I think I'll just read your blog for a few before I do, so at least I'll know a few things before I get it.

    My main question at this time, is, is it worth upgrading from the 50g which I do know very well already..."

    My reply is:


    Thank you.

    As you probably noticed, I put two duplicates of the same topic. One of the pages that wasn't quite finished.

    To answer your question, I have and use both the 50g and the Prime and like them both. The Prime has a few new features over the 50g: color screen, rechargeable battery, super fast processor, and two new graphing applications, one for geometry and one for implicit graphs (Advanced Graphing - my favorite app). The Prime adds additional advanced functions such as Si, Ci, Ei, Zeta, and the erf functions.

    The programming language is different, so there could be a learning curve since it is not RPL. Prime does have an RPN mode, though it is not as extensive as the 50g.


    My apologizes for any inconvenience.

    1. The 40G series also uses the same programming language. I think these powerful calculators have a serious handicap because of commercial decisions that make no sense.

      I think that 48G or 48GX was the last real calculator. HP calculators should do RPN and only do RPN! I stil use the 48SX and 48GX everyday.

    2. I thought I was the only one... I am so frustrated by this language. Especially if you want to use the CAS, the both the syntax and the semantics are ill defined and very complicated.

  2. Thanks again, Eddie. I am loving my new Prime. Your blog is always a huge help.

  3. Home Mode - RPN Entry
    Do I need to define allways the number of used arguments to run the program, even if there is definition the number of variables (as in example SQIN) in "EXPORT SQIN(X)" and the program won't even work with bad number of them?

    How can I return to the stack more results from the program (for example in SQIN example RETURN 1/x^2; RETURN 1/x^3;)?

    1. Jouni,

      Answer to first question:
      You can have a program without arguments. I don't quite understand the second part of the first question. Did you mean the use of optional arguments?

      Answer to second question:
      For returning multiple results to the stack, I favor the use of a list of vector. Example:

      RETURN [1/x^2, 1/x^3];

      Multiple RETURN statements do not work well in my experience.

      Hope this helps,


    2. What do you mean by
      I favor the use of a list of vector. Example:
      RETURN [1/x^2, 1/x^3];
      if I right this line in the program, I get Error: Syntax Error..
      Can you please the example as a complete program that works.
      Thanks in advance
      Alaa Diab

    3. Hi Eddie,
      Thanks, the vector approach works like a charm!
      Now another question. The Solve function on this vector.
      Let´s say I made a program that returns VECTOR(x) expressed as [a(x),b(x),c(x)]
      given that b(x) is a known value, what would be the sintaxis for solving VECTOR(x) for x with a(x), b(x) or c(x) known?

      Thanks in advance,

  4. This comment has been removed by the author.

  5. Hi!eddy could you write your post in spanish. It will be great. Please. Take care and thanks.

  6. Thanks Eddie,
    You wonder why HP does not put such straight forward examples in their documentation.
    This is the best information about programming the HP Prime.

  7. I read your post and need to thank you for sharing such pleasant lines. Be that as it may, I likewise need to instruct you to share more data as I had needed to peruse all the more yet didn't get acceptable substance from anyplace.
    integrated voice response

    1. I'll see what I can do. It is why I like to post programs: for documentation and anyone can learn from the examples.

  8. I don't know why, but the program give me a syntax error where I use (,) instead (;) on the first line program of MOPMT.
    Is possible that is caused due the language settings that I am using portuguese? Or this is caused by RPN ou Algebraic Mode entry?

    1. In Settings, at "Digit Grouping" area choose as decimal symbol the "." instead of ",".
      For example: 123,456.789 or 123 456.789
      Of course after this you have to make changes to the programs you have written. "," instead of ";"

  9. Hi Eddie
    Thank u very much for sorting our problems and may God bless u a million times my brother. Eddie could u pls help on HP Prime this time to get the value of K if K=M/b x d sq x Fcu
    M=200 kNM say 200x10 expnt 6
    b=300 mm
    d=675 mm
    Fcu= 30 N/mm sq
    The answer = 635.8mm

  10. This comment has been removed by the author.

  11. It is our need that you put it here in your post as much useful that all can take it as a good thing from your site. Thank you.
    digital marketing services in delhi

  12. The subsequent time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my option to read, but I actually thought youd have something fascinating to say. All I hear is a bunch of whining about something that you could possibly repair in the event you werent too busy looking for attention. free online casino slots

  13. I think this is a real great article post.Really looking forward to read more. Visit at
    Crazy Video Hub

  14. This is a great post ! it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading kardashian sex tape
    porn sex video hd
    mia khalifa sex video
    sunny leone sexy movie

  15. Hi,

    Thanks for sharing great post keep up the good work keep writting great stuff i am also running chatting website have a look link below

    best chatting site

  16. it was a wonderful chance to visit this kind of site and I am happy to know. thank you so much for giving us a chance to have this opportunity..

  17. A Scientific Calculator
    is a Calculator designed to calculate science,

  18. I find problems with the Financial Calculators , it's complicated


Review: Calculated Industries Pipes Pro (Model 4095)

Review:  Calculated Industries Pipes Pro (Model 4095) Quick Facts Model Number:  4095 Company:  Calculated Industries Year of Production:  2...