Create an account on the HP Community to personalize your profile and ask a question
05-26-2020 07:43 AM
I know how to use "IF THEN ELSE" in the HP prime calculator to test whether a condition, such as a>b, is true, and then execute some command entered just after the "THEN", such as multiplying c by 4, if the condition is true, and executing some different command entered just after the "ELSE", such as multiplying c by 3, if it is false, but I don't know how to do branching to other, maybe far distant, parts of the program depending on whether it is true or false. The latter is the main type of branching available and used in most programming languages, such as FORTRAN (an old but still used language) and even the HP 42 calculator programming language. This latter type of branching is much more flexible than the Prime type, which can only branch to the commands that are specially entered into the area of the "IF THEN ELSE". Is there some way of doing the more flexible type of branching in the Prime? If there were a way in the Prime to identify program lines by, say, line number N, and there were a "GO TO N" command to enter after the "THEN" and/or "ELSE" in the Prime, that would do it, but there doesn't seem to be either of these.
05-26-2020 11:03 PM
The short answer (sorry, it is not the one you wanted) is: There is no GOTO on Prime.
I could write at length about the reasons, but the geist of it is: Prime is using a structured programming language, and in structured programming languages, GOTO are considered "bad".
Starting with the last part of this statement. GOTO, as a tool can very easily be mis-used and create bad/very unreadable/buggy code. This is one of the main reason why it was removed (or at least hidden) in "3rd generation languages". See this article by Dijkstra, one of the "computer sciences heroes" talking about GOTO https://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
Although it is not the GOTO itself which is bad, but what people make of it, GOTO makes it VERY easy to do bad stuff...
Structured languages, with their IF THEN ELSE, WHILE, DO UNTIL and FOR are just "hiding" the goto behind various constructs. But by doing so, they explicit what the GOTO is used for (intend) and block you from doing "bad things"...
The other reason why such languages do NOT have goto is that a GOTO statement is actually prety hard to implement in such a language!
Now, there is one case where GOTO are concidered OK to use in C or similar languages, it is to exit from an innerloop..
if test for something is true goto done;
BUT, such GOTO are not needed on prime as you can do a BREAK(2)...
I hope that this helps explain what is happening and why there is no goto..
Note that GOSUB does exist, it is a sub-function call as in:
if test then
function2(some other params)
05-27-2020 12:06 PM
Thank you for your answer. I read the Dijkstra article. I found its point to be a little obscure, but as far as I could tell, it was that when using a GO TO, the programmer needs to be aware of the current values of the programs parameters, and this may sometimes be difficult. Of course one may need to be aware of some of them, depending on the program and the action one wants to accomplish, but this is always true even if you aren't using a GO TO statement. Without a GO TO statement but with only the IF THEN ELSE, you have to enter again all the parts of the program you could have gotten just by using a GO TO statement, and you still have to be aware of the values of the relevant parameters. Do current programming languages have such a silly limitation as no GO TO? I intended to learn Python and to some extent the Wolfram (Mathematica's creator) language, but if they have no GO TO statement or equivalent, I may not bother. I have used, years ago, GO TO statements, to a considerable extent, in FORTRAN, and never ran into trouble because of their use. I wish HP would put GO TO and place identifiers such as line numbers or LBL (Label) identifiers into an update of the Prime programming language, unless that would be extremely difficult. I have a TI nspire CX CAS calculator which has them in its programming language, so it can be done. I would prefer to use the Prime rather than the nspire for calculator programs because the Prime is faster, has more memory, and is easier to use. (I don't have the latest nspire, the II, & don't know much about it, but it appears to be not much different from the one I have, except maybe faster, & with one other seemingly unimportant feature.)
05-28-2020 12:45 AM
The geist of Dijkstra's article is that, when you look at a program that does NOT have gotos, all you need to know to understand the current state of a program is the current "program position" and the function call stack. He calls that a "coordinate system" for the program.
In a program with goto, you need to know much much more, which makes reading/understanding a program much much harder.
Now, most modern programming languages DO have gotos, BUT they have limitations. To get started, you can only GOTO in the current function. (java and python does not have them!).
Using goto, with the exception of exiting inner loops, and jumping to cleanup and exit code at end of functions is usually very frowned upon...
I have done a lot of ASM programming AND old, 1.0 type basic, which are all 100% goto based, so I do understand where you are coming from, but I doubt that Prime will ever include gotos (unless another programming language is introduced in it).
I wish I could help more, sorry.
05-28-2020 09:47 AM
Thank you for your discussion of GOTO in programs, but I don't really understand why in a program with GOTO, to understand the current state of a program, you need to understand much much more than you need in a program without GOTO. Can you give me a reference to something that will explain this in language without much computer jargon (unless you can & will briefly explain it yourself)?
05-28-2020 11:39 PM - edited 05-29-2020 06:44 AM
But, what would be the fun of NOT using Jargon 🙂
Joke aside, properly used GOTO are not problems, after all, all high level constructs (IF THEN ELSE, DO WHILE, FOR, BREAK and CONTINUE) are all implemented with GOTO underneath. The problem is that GOTO can be very easily used in ways that are not considered "clean"...
Tet us take an hypothetical example.
You are working on something.
Your boss calls and says: Can you please do something else quick for me?, you interrupt what you were doing to do what your boss asks.
Then, the REAL boss (your spouse) asks you to do something. So, immediately, you interrupt what you were doing an execute.
While doing so, the dog asks to go out. You know that, should you not let it, you will end up with something nasty to clean! so you jump on that.
At that time, the bell rings! It is a most expected package (your HP Prime is being delivered!) so you close the door behind the dog, go deal with the package.
Now, that you have your package, things are clear, you need to go get the dog back in, then complete the task for the spouse, then the task for the boss, and then return to your job....
This is a "proper" programming structure.
Now, imagine that after closing the door on the delivery guy, you get back (GOTO) to dealing with your boss' request. how much do you want to bet that you will quickly forget the dog and the spouse (with all the consequences!)
This is a GOTO case.
Allowing the GOTO allowed you to do something that will, ultimately cause troubles.
This is of course a very imaged description, GOTO has caused a lot of ink to be splattered over the years. It is, in some ways a philosophical question, and the consensus is that with the exception of some rare cases (when the languages does not have a construct to avoid it, which is not the case in PPL thanks to BREAK(n) ), the only good reason to use goto is to exit from inner loops.
Removing GOTO from a language forces GOTO user to change the way they think about program construction, BUT the end result is better programs and the ability to scale up (ie: create bigger maintainable, readable programs).
And, as I hinted before, adding GOTO in a high level language can be a quite complex task, so it is easier for the language developer to NOT have the GOTO! and developers tend not to like to do extra work 🙂
I hope that this helps explaining the situation (which is not limited to HP Prime, as I said earlier a LOT of languages do not have GOTO, and a large number of those that do have lots of limitations in the GOTOs)...
Have a good day,
06-01-2020 12:50 AM
I guess they are different types of Jargon.
There is the Jargon of someone who knows nothing (or not much) and tries to make himself sound good by using weird words for the sound they make or because it makes himself sound/look good.
Then there is the jargon that actually has a very precise, specific meaning, used in the right way, at the right time to convey in one word some complex concept by someone who does know and understand what he is saying...
(note that the words might be the same in case 1 and 2!!!!, which makes it harder for a 3rd party to know which case he is facing:-)
Anyhow, in the case at hand here, we are talking about the philosophy of programming, or discussion about the way we think of programs programmers and programming.
So they are going to be a lot of meta concepts and even meta-meta-concepts.
ie: the concept is the program structures. The talk about meta concept is a talk about how we think/use the program structures and the meta-meta-discussion would be about how the way we "we think/use the program structures" affect our programs/programming abilities...
So, yes, it does make it complex, and some jargon does help avoid long drawn out sentences/explanations... But is harder to get in for the non initiated... kind of like philosophy!