Post Reply 
Print to stack
10-28-2022, 12:04 AM
Post: #1
Print to stack
Hi again,

The rookie is back with another question or so.

I'm trying to print to the stack from a program. Everything online seems to make it look easy enough. However I can't get hardly anything to work.

Code:

EXPORT string(A,B)
BEGIN 
PRINT("Result A:"+A);
PRINT("Result B:"+B);
RETURN {A,B};
END;

This is a simple enough program but it does not return anything to the stack except the name of the program and the digit "1" which I assume means the program terminated correctly.

I've tried printing from the command line but if I don't get a Syntax Error I get nothing but again, the name of the program and the digit "1".

I've tried various options both in Home and CAS...no joy. What do I need to do to print a program result to the stack? Is it another one of the excessively complicated DIMGROB situations?

Thanks for your help
Find all posts by this user
Quote this message in a reply
10-28-2022, 12:22 AM (This post was last modified: 10-28-2022 12:26 AM by Ioncubekh.)
Post: #2
RE: Print to stack
Code:
EXPORT demo(a,b) // x2 arguments required by program named demo
BEGIN 
PRINT("Result A:"+a);
PRINT("Result B:"+b);
END;

At home screen type
demo("cat", "cow")
demo(3,2) //numerals only

HP Prime G1
Python via Android Termux...
Find all posts by this user
Quote this message in a reply
10-28-2022, 12:25 AM
Post: #3
RE: Print to stack
“STRING” is a command of the Prime.
Try replacing “STRING” with something else.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
10-28-2022, 03:15 PM
Post: #4
RE: Print to stack
(10-28-2022 12:22 AM)Ioncubekh Wrote:  
Code:
EXPORT demo(a,b) // x2 arguments required by program named demo
BEGIN 
PRINT("Result A:"+a);
PRINT("Result B:"+b);
END;

At home screen type
demo("cat", "cow")
demo(3,2) //numerals only

Thanks, this almost worked. It only sends item B to the stack and omits item A. It's frustrating that something so simple can turn to be so complicated. Any ideas on that?
Thanks again,
Bob
Find all posts by this user
Quote this message in a reply
10-28-2022, 04:10 PM (This post was last modified: 10-28-2022 04:15 PM by jfelten.)
Post: #5
RE: Print to stack
(10-28-2022 03:15 PM)forexbob Wrote:  
(10-28-2022 12:22 AM)Ioncubekh Wrote:  
Code:
EXPORT demo(a,b) // x2 arguments required by program named demo
BEGIN 
PRINT("Result A:"+a);
PRINT("Result B:"+b);
END;

At home screen type
demo("cat", "cow")
demo(3,2) //numerals only

Thanks, this almost worked. It only sends item B to the stack and omits item A. It's frustrating that something so simple can turn to be so complicated. Any ideas on that?
Thanks again,
Bob

try this:
Code:
EXPORT demo(a, b)
BEGIN 
PRINT("Result A: "+a);
PRINT("Result B: "+b);
return {a, b};
END;
Find all posts by this user
Quote this message in a reply
10-28-2022, 04:54 PM
Post: #6
RE: Print to stack
(10-28-2022 04:10 PM)jfelten Wrote:  
(10-28-2022 03:15 PM)forexbob Wrote:  Thanks, this almost worked. It only sends item B to the stack and omits item A. It's frustrating that something so simple can turn to be so complicated. Any ideas on that?
Thanks again,
Bob

try this:
Code:
EXPORT demo(a, b)
BEGIN 
PRINT("Result A: "+a);
PRINT("Result B: "+b);
return {a, b};
END;

This does return the two input values to the stack in a list but I was hoping to have the values returned to different levels in the stack. i.e Result "a" on level 2 and result "b" on level 1.
I don't think I explained myself properly initially. Having now been more specific, any ideas?

Thanks
Bob
Find all posts by this user
Quote this message in a reply
10-28-2022, 07:50 PM
Post: #7
RE: Print to stack
(10-28-2022 12:04 AM)forexbob Wrote:  Hi again,

The rookie is back with another question or so.

I'm trying to print to the stack from a program. Everything online seems to make it look easy enough. However I can't get hardly anything to work.

Code:

EXPORT string(A,B)
BEGIN 
PRINT("Result A:"+A);
PRINT("Result B:"+B);
RETURN {A,B};
END;

This is a simple enough program but it does not return anything to the stack except the name of the program and the digit "1" which I assume means the program terminated correctly.

I've tried printing from the command line but if I don't get a Syntax Error I get nothing but again, the name of the program and the digit "1".

I've tried various options both in Home and CAS...no joy. What do I need to do to print a program result to the stack? Is it another one of the excessively complicated DIMGROB situations?

Thanks for your help

"PRINT" doesn't print to the stack, guess you're talking about the HOME screen(or CAS screen). "PRINT" prints to the terminal. You can look at the terminal with <On>+<T>

For reference: on the Home screen type "PRINT" then push the Help button.
HTH, Günter
Find all posts by this user
Quote this message in a reply
10-28-2022, 07:56 PM
Post: #8
RE: Print to stack
Code:
PRINT("Result A:"+A+" Result B:"+B+");

HP Prime G1
Python via Android Termux...
Find all posts by this user
Quote this message in a reply
10-29-2022, 05:47 AM
Post: #9
RE: Print to stack
I think what forexbob is going for is to return results to the RPN Mode stack. I could be wrong, but to my knowledge PPL does not have stack commands in programming mode.
Visit this user's website Find all posts by this user
Quote this message in a reply
10-29-2022, 09:34 PM
Post: #10
RE: Print to stack
When running a program and printing the output to the terminal, only the last printed line or expression is sent back to the Home screen as a text object. It makes no difference if the entry mode is textbook or RPN.

If you want to use the numeric answers from your program on the Home screen, save your answers into variables. Then use the Var key to insert the variable name into the entry line of the Home screen.

To access A through Z variables, use Var key, Home tab, Reals or just type in the variable name.

To access exported program variables, use Var key, User tab, Program name, and select the program variable.
Find all posts by this user
Quote this message in a reply
Post Reply 




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