Post Reply 
line breaks with HP50g
08-25-2015, 05:19 PM (This post was last modified: 08-29-2015 09:35 AM by tigger.)
Post: #1
line breaks with HP50g
I punch in my programs with paragraphs. I can read and understand the program better with them.

After saving the program I get the program without any paragraphs. Can I get them back?
Find all posts by this user
Quote this message in a reply
08-28-2015, 02:03 AM
Post: #2
RE: Paragraphs
Have you tried writing the paragraphs on a piece of paper?

Generally not a standard practice with RPL/RPN code to comment the code on the calculator.
For RPN programs, I tend to go back and comment/mark the code my self in a separate file. For RPL programs (like on a 50g) you can copy them to a computer or memory card and comment them on a computer so you can remember what each step does- but the commented code never gets copied back to the calculator for execution.

Attached is an example of some value adding comments for RPN code (for the HP 42s).

Hope that helps, TTFN!


Attached File(s)
.pdf  EulerTotientFunction_HP42S.pdf (Size: 197.81 KB / Downloads: 37)

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-28-2015, 05:24 PM (This post was last modified: 08-28-2015 05:25 PM by tigger.)
Post: #3
RE: Paragraphs
Let me give you an example:
<< 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>

If I had paragraphs in this program I could understand it in a better way.

<< 2 -
1 5 √ +
2 /
→ N H

Like this; this part means: (stack-2)+ (1+sprt 5)/2

Is this right?


N H might be global values?

How do I know, what belongs together? I do not have too much practice. Which are the comands and which values belongs to the comands?


Do you understand my question?
Find all posts by this user
Quote this message in a reply
08-28-2015, 08:04 PM
Post: #4
RE: Paragraphs
(08-28-2015 05:24 PM)tigger Wrote:  Let me give you an example:
<< 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>

If I had paragraphs in this program I could understand it in a better way.

<< 2 -
1 5 √ +
2 /
→ N H

...

Do you understand my question?

By "paragraphs" do you mean "line breaks"? If so, no, you can't embed line breaks in RPL programs between commands. All unnecessary "white space" and line feeds are removed by the parser. However, you can keep a copy saved under a different name, containing the program in string form, which you can either VIEW or EDIT, and that way whatever line feeds AKA carriage returns / newlines / line breaks / paragraphs (?) you insert would be displayed exactly the way you want.

If you mean something else by "paragraphs" please explain. The dictionary definition of "paragraph" seems unrelated to your question.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
08-28-2015, 10:41 PM
Post: #5
RE: Paragraphs
(08-28-2015 08:04 PM)Joe Horn Wrote:  By "paragraphs" do you mean "line breaks"?... If you mean something else by "paragraphs" please explain. The dictionary definition of "paragraph" seems unrelated to your question.

Good catch.. I scratched my head a few minutes trying to understand the question without the example.. I like your contribution much better!

Thank you!

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-29-2015, 09:18 AM (This post was last modified: 08-29-2015 09:36 AM by tigger.)
Post: #6
RE: line breaks with HP50g
(08-28-2015 08:04 PM)Joe Horn Wrote:  
(08-28-2015 05:24 PM)tigger Wrote:  Let me give you an example:
<< 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>

If I had paragraphs in this program I could understand it in a better way.

<< 2 -
1 5 √ +
2 /
→ N H

...

Do you understand my question?

By "paragraphs" do you mean "line breaks"? If so, no, you can't embed line breaks in RPL programs between commands. All unnecessary "white space" and line feeds are removed by the parser. However, you can keep a copy saved under a different name, containing the program in string form, which you can either VIEW or EDIT, and that way whatever line feeds AKA carriage returns / newlines / line breaks / paragraphs (?) you insert would be displayed exactly the way you want.

If you mean something else by "paragraphs" please explain. The dictionary definition of "paragraph" seems unrelated to your question.

Yes, right, may I say "carriage returns", too.

I guess you explained many steps in one sentence. Could I ask you to explain your solution more detailed?
1. copy the program and save it under a different name
2. edit the program (F1, under TOOL (2.3)) or view the program (F2, under TOOL (2.3))

What happens now? What do I have to do now?
AKA carriage returns / newlines / line breaks / paragraphs ??? (I am beginner. I do not understand this.)


Could we then study my small program? So far my knowledge of programming is small. I was given the program to make it work. I debugged the program. I did not understand the "grammar" of the line.

There might be a link for beginners in the net?

thanks for your help
Find all posts by this user
Quote this message in a reply
08-29-2015, 09:39 AM
Post: #7
RE: line breaks with HP50g
(08-28-2015 10:41 PM)Allen Wrote:  
(08-28-2015 08:04 PM)Joe Horn Wrote:  By "paragraphs" do you mean "line breaks"?... If you mean something else by "paragraphs" please explain. The dictionary definition of "paragraph" seems unrelated to your question.

Good catch.. I scratched my head a few minutes trying to understand the question without the example.. I like your contribution much better!

Thank you!

Next time it might be better if I gave an example, sorry. I do not know how to discribe in a better way.
Find all posts by this user
Quote this message in a reply
08-30-2015, 07:30 AM
Post: #8
RE: line breaks with HP50g
(08-29-2015 09:18 AM)tigger Wrote:  I guess you explained many steps in one sentence. Could I ask you to explain your solution more detailed?
1. copy the program and save it under a different name
2. edit the program (F1, under TOOL (2.3)) or view the program (F2, under TOOL (2.3))

What happens now? What do I have to do now?
AKA carriage returns / newlines / line breaks / paragraphs ??? (I am beginner. I do not understand this.)

Could we then study my small program? So far my knowledge of programming is small. I was given the program to make it work. I debugged the program. I did not understand the "grammar" of the line.

No problem; let's use your program to illustrate. Please actually do the following steps on your 50g (don't just read them). Step Zero puts your 50g in RPN mode with flag -117 set, which is the way all 50g's should be at all times.

Please note: The following is a learning exercise. You will NOT have to go through all this every time you write a program! But please do this at least once, for the sake of learning some useful 50g concepts.

0. Turn on RPN mode (MODE CHOOSE RPN ENTER ENTER) and set flag -117 (-117 ALPHA S ALPHA F ENTER).
1. [right-shift] [×] ENTER (this puts an empty string on the stack).
2. [down-cursor] (this is the same as executing the EDITB command).
3. Key in your program, ending the lines wherever you wish by pressing the NEWLINE key which is [right-shift] [.] If you make a mistake or wish to change anything, just move the cursor around the screen using the cursor keys and edit it any way you wish.
4. When the program is all keyed in (it can be as wide and long as you wish), press the ENTER key to exit the editor. What you typed will be placed on the stack, not as a program object, but as a STRING object (as indicated by the double quotation marks around it).
5. Press the single-quote key ['], turn on ALPHA mode (press ALPHA twice), and type the name in which you wish to save the STRING form of your program, e.g. PROG.S (using .S to remind you that this is a "string" or "source code").
6. Press ENTER. This puts the single-quoted name on level 1 of the stack, and raises your string to level 2.
7. Press STO. Both disappear, as the string gets stored into a variable with the name you typed.
8. Press VAR. You'll see the first 5 characters of your variable above the F1 key. Press F1 to recall the string to the stack.
9. Press [left-shift] [EVAL] [TYPE] [OBJ→]. This converts your string into an actual program object. If an error occurs, then you probably have one or more syntax errors, so press down-cursor to edit the string, fix the syntax errors, press ENTER to exit the editor, and try OBJ→ again.
10. Now save the program under a different name, e.g. 'PROG', the same way you saved the string version. It will appear above the F1 key (after pressing VAR), and the string version will move over to the F2 key.
11. Run the program by pressing its key in the VAR menu. Edit the program by editing the string version (complete with newlines wherever you prefer to place them) and then executing OBJ→ on it to convert the string object into a program object.

In addition to strategic line breaks, you can even include comments in your programs if you use the above method! All you have to remember is that in RPL, comments begin with an "@" character. So, for example:

"<< 1 2 + @ This adds two numbers
3 4 * @ and this multiplies two numbers
/ @ and that divides the sum by the product >>"

is a string with line breaks AND comments. When OBJ→ is executed on that string, the following program is produced:

<< 1 2 + 3 4 * / >>

Cool, huh?

Hope that helps. Feel free to request clarification or ask further questions. Warning: Learning the 50g is an immense undertaking, so be patient with yourself, and try lots of things to see what happens. That's always a good way to learn.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
08-30-2015, 11:46 AM (This post was last modified: 08-30-2015 11:47 AM by tigger.)
Post: #9
RE: line breaks with HP50g
Cool, real great, thanks,...

I keyed the program. My results are:
If I key F1 Prog: error, I have always to key RS F1(Prog) -> I can see the program.
If I key F1 Prog.S: I can see the program imediately.

I understand, what the program is for, but I do not know where to put line breaks and strings because I do not understand the way the HP50g works.
<< 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>

I debugged the program (in exact mode) and I started with A in the stack. To a certain point I had fraction. In the midst of the program the HP switched to appr. mode. (Why?) I got a long answer (with real numbers), which I could neither read on the display nor understand. I got three lines with VIEW -> TEXT.

Could we go through the program.

questions:
1. I do not know. what EDITB does.
2. Is it possible to see long results on the display. Sometimes there is not enough space for the long result on the display and I can only see parts of the result there.
3. Could help me to show the line breaks, or the begin and the end of a command. How do I know where a command starts and ends.
4. Why does the HP switch from exact to appr mode while executing the program. (Probably it was not this program. Before I had problems with other programs.)


5. Every three month I have to change batteries. Is this usual?

PS: Could you recomand a page, which teaches programming in C?
Are you experienced with wolfram alpha (wolframalpha.com)?
Find all posts by this user
Quote this message in a reply
08-30-2015, 12:48 PM
Post: #10
RE: line breaks with HP50g
(08-30-2015 11:46 AM)tigger Wrote:  Cool, real great, thanks,...

I keyed the program. My results are:
If I key F1 Prog: error, I have always to key RS F1(Prog) -> I can see the program.

Pressing F1 *runs* the program. It errors because it expects its input from the stack but you didn't pre-load the input on the stack. Key the input, press ENTER to put it on the stack, and then run the program. That's the spirit of RPN: you key the input first, then execute the function, e.g. to get the square root of 9, you key 9 first and then press the square root button.

As you discovered, RS F1 is a shortcut for ['] [F1] [RCL].

(08-30-2015 11:46 AM)tigger Wrote:  If I key F1 Prog.S: I can see the program imediately.

Executing a string merely puts it on the stack, so executing 'PROG.S' has the same effect as recalling 'PROG.S'.

(08-30-2015 11:46 AM)tigger Wrote:  I understand, what the program is for, but I do not know where to put line breaks and strings because I do not understand the way the HP50g works.

The 50g doesn't care AT ALL where you put line breaks; there are none in the actual program. The whole reason for creating a string version was to enable YOU to put line breaks where YOU wanted them, because you said you wanted them. Put them wherever you wish. The 50g doesn't care, not even a little.

(08-30-2015 11:46 AM)tigger Wrote:  << 2 - 1 5 √ + 2 / → N H
<< H N 2 + ^ 1 H - N 2 + ^ - 5 √ / EVAL >> >>

I debugged the program (in exact mode) and I started with A in the stack. To a certain point I had fraction. In the midst of the program the HP switched to appr. mode. (Why?) I got a long answer (with real numbers), which I could neither read on the display nor understand. I got three lines with VIEW -> TEXT.

Do any of the numbers in the program have a decimal point on them? If so, remove the points by editing the program in exact mode. Decimal points cause the math to flip into approximate mode at that point (no pun intended). The program will only work as intended if all of the numbers in it are exact integers (with no decimal point), AND if the input is an exact integer, AND if the program is run in exact mode.

Three lines?!? Sounds like there's a typo in your program. Please give an example of an input and the resulting output.

(08-30-2015 11:46 AM)tigger Wrote:  questions:
1. I do not know. what EDITB does.

It means "EDIT with the Best editor for the type of object being edited." For example, put the array [ 1 2 3 ] on the stack. Press either down-cursor or TOOL EDIT. You'll see the array get loaded into the MatrixWriter, which is the "best editor" for arrays, because down-cursor and TOOL EDIT both execute the EDITB command (which is also a programmable command). But if instead of pressing down-cursor, you press [left-shift] [down-cursor], or TOOL [either shift] [EDIT], you'll see the array echoed directly into the command line editor, because those key sequences execute the EDIT command (not EDITB). The EDIT command always uses the command line editor... but beware the misleading of the "EDIT" menu key in the TOOL menu! It *says* "EDIT" but it performs EDITB if pressed without pressing shift first.

Other object types have different "best" editors. For example, put the algebraic object '1+2' on the stack and then execute EDITB (by pressing down-cursor or TOOL EDIT). As you see, the EquationWriter is considered the "best" editor for algebraics. I personally prefer the command line editor for algebraics (usually), so I press left-shift before pressing down-cursor to edit algebraics.

(08-30-2015 11:46 AM)tigger Wrote:  2. Is it possible to see long results on the display. Sometimes there is not enough space for the long result on the display and I can only see parts of the result there.

Yes: TOOL VIEW, then scroll using the cursor keys.

Alternative: Large algebraics sometimes don't all fit on the screen at once in Textbook Mode. Turning off Textbook mode makes algebraics ugly, but at least they usually fit on the screen all at once. (Toggling Textbook mode can be done either in the MODE DISP screen, or by setting/clearing flag -79).

(08-30-2015 11:46 AM)tigger Wrote:  3. Could help me to show the line breaks, or the begin and the end of a command. How do I know where a command starts and ends.

Commands are always separated by a space. No command contains a space.

One mistake often made by beginners is typing "→ A" (which means "create a local variable called 'A' and store what's on the stack into it") as "→A" (with no space between the arrow and the "A"). If there is supposed to be a space between the arrow and the variable, then there MUST be a space there. Otherwise the 50g will think you want the →A command, which is a single command, which has nothing to do with local variables and is totally different from "→ A".

(08-30-2015 11:46 AM)tigger Wrote:  4. Why does the HP switch from exact to appr mode while executing the program. (Probably it was not this program. Before I had problems with other programs.)

Already discussed above.

(08-30-2015 11:46 AM)tigger Wrote:  5. Every three month I have to change batteries. Is this usual?

Yes. It depends on how you are using it, of course. If you run a lot of long-running programs, you'll even have to change the batteries every few days. Suggestion: plug it into a live USB outlet via a standard mini USB cable; then your batteries will last forever because the 50g will be powered by the USB instead of by the batteries.

(08-30-2015 11:46 AM)tigger Wrote:  PS: Could you recomand a page, which teaches programming in C?
Are you experienced with wolfram alpha (wolframalpha.com)?

Let's stick to 50g programming in this thread.

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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