The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime: Pass "Long" Integers to a Program
Message #1 Posted by Helge Gabert on 31 Oct 2013, 10:46 p.m.

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!

      
Re: HP Prime: Pass "Long" Integers to a Program
Message #2 Posted by Joe Horn on 1 Nov 2013, 12:30 a.m.,
in response to message #1 by Helge Gabert

Here's one way to do it.

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

AA(x,y):=x*y

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:

(x,y)->BEGIN
  x*y;
END;

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!

            
Re: HP Prime: Pass "Long" Integers to a Program
Message #3 Posted by Helge Gabert on 1 Nov 2013, 11:14 a.m.,
in response to message #2 by Joe Horn

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

                  
Re: HP Prime: Pass "Long" Integers to a Program
Message #4 Posted by Helge Gabert on 2 Nov 2013, 5:34 p.m.,
in response to message #3 by Helge Gabert

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? :(

                        
Re: HP Prime: Pass "Long" Integers to a Program
Message #5 Posted by Joe Horn on 3 Nov 2013, 11:12 a.m.,
in response to message #4 by Helge Gabert

Quote:
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.
                              
Re: HP Prime: Pass "Long" Integers to a Program
Message #6 Posted by Helge Gabert on 3 Nov 2013, 11:34 a.m.,
in response to message #5 by Joe Horn

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.

                                    
Re: HP Prime: Pass "Long" Integers to a Program
Message #7 Posted by Helge Gabert on 3 Nov 2013, 1:12 p.m.,
in response to message #6 by Helge Gabert

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!


[ Return to Index | Top of Index ]

Go back to the main exhibit hall