No, it's not "Hello World" :-)
Inspired by one of Eddie's blogs (thanks Eddie!), I tried to write a program to take values from the stack and return values to the stack when executed from the command line in RPN home mode. The goal is the ever-popular rectangular to polar and polar to rectangular conversions. Figuring I'd better try to crawl before walking, I started by just trying to take two values from the stack and return a result based on those values:
EXPORT POL(X,Y)
BEGIN
RETURN ATAN(X/Y);
END;
I typed the above in, went to the home screen in RPN mode, keyed in 3 ENTER 4 ENTER POL ENTER. Hallelujah! 36.8699 was returned to the stack on level 1! Excited with my success, I edited my program as follows:
EXPORT POL(X,Y)
BEGIN
RETURN ATAN(X/Y);
RETURN SQROOT(X2+Y2);
END;
There were no syntax errors, so I hoped the first return statement would put the angle on the stack as before, and the second would push the magnitude. Unfortunately, 3 ENTER 4 ENTER POL ENTER yielded only the 36.8699 result as before. If I comment out the first RETURN statement, I get the correct answer of 5 for the magnitude. So, is there any way to have the program calculate and push both values onto the stack?