HP Forums

Full Version: HP Prime: Pass "Long" Integers to a Program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

How can I make sure to pass an integer to a program, and not a real?

For example, calling MYPROG(11111111111111111111111199999) from CAS view results in "k" being real in EXPORT MYPROG(k). This causes problems with calling functions in the program that expect integers as arguments, e.g., isprime() or pa2b2() - - "Error: Bad argument type."

Thanks for any insights!

Here's one way to do it.

STEP 1: In CAS, define a function something like this:


In CAS mode, AA(123456789,987654321) returns the full 18-digit product, of course.

STEP 2: Go into the Program Catalog. Notice that it's now shown as a program which can be edited any way you like. For example, you can change the above AA program into:


This has the same effect as the above function when used in CAS mode, but now it looks more like a PPL program. The only real trick here is that you have to start with something saved in CAS mode, then edit it with the Program editor, then run it in CAS mode.

STEP 3: Have fun!

OK, I will try that out. Thanks so much!

Thanks, this works! :))

Only, don't clear the CAS history with "Clear" - - because then AA will be gone from the Program Catalog, as well as from the Memory Manager. Bug or Feature? :(

Only, don't clear the CAS history with "Clear" - - because then AA will be gone from the Program Catalog, as well as from the Memory Manager. Bug or Feature? :(
A known bug. It also resets all the CAS settings! Very annoying. I'm pi^4% sure that it'll be fixed in the next firmware version.

Sounds good - - let's cross our fingers!

I also noticed that programs with the CAS qualifier in parenthesis one cannot run from the program catalog - - the "run" soft key, as well as the "debug" soft key are missing.

Also, the "CAS" programs stay at the bottom list of the program catalog - - and when one edits them, on always has to hit "uparrow" twice in order to get to them. Other programs make it to the top of the catalog right away, which is nice for editing.

One more thing:

On the HP50G, the premise is that everything is an object and obeys the same rules. So, if your argument to a program is a long integer, a matrix, list, binary, complex number, algebraic expression, whatever - - you can pass it to your program with

<< -> k
<< do something here with k >>

and everything works beautifully.

On the Prime, however, you constantly need to be on the guard. Data types get converted, you need to be careful with CAS programs vs. Home programs, the program catalog "run" command only accepts reals, CAS commands don't accept functions you define with the "Define" key - - error message "Unmatch control word", RPN is an afterthought, lists can only have 999 elements, no compiled local variables, symbolic elements cannot be entered in to the matrix editor, etc. - -I could go on and on.

It seems to me that the "unifying" idea behind the Prime are the apps - - and that is OK for students, but how often do I use, say, the "Linear Explorer"? Even the "Solve" app is rudimentary (no complex solutions, and for more than univariate problems, the diagnostics are missing) and could be a lot better - - look, for example, at the "Solvesys" library for the 50G, which has been around for years - - I can't believe that HP couldn't take a clue from that.

Anyway, enough ranting - - I do like the speed of the Prime and the colors are great - - hopefully, things will flesh out over time. And using it interactively, it can be fun!