HP Forums

Full Version: Print to stack
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
“STRING” is a command of the Prime.
Try replacing “STRING” with something else.
(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
(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;
(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
(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
Code:
PRINT("Result A:"+A+" Result B:"+B+");
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.
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.
Reference URL's