Message #15 Posted by C.Ret on 27 Nov 2009, 3:50 a.m.,
in response to message #14 by Pal G.
You are right in your programming philosophy and nothing is wrong with your code or style.
Allocated all the variables at beginning of the program/function makes sense to me too. I use to make it systematically in the old style BASIC line program such as the one on my Commodore C128D computer, this greatly help organize data and memory. It si also sparing running -time or the bad behavior when "out of memory error" runs, which is quite easy to occur on simplest 8-bits computer.
It is true that the IF…THEN…ELSE...END statements are not as Reverse Polish notation as the IFT or IFTE are. These two last are much more real post-pone operators like the majority of RPL instructions.
Egan points out similarity between UserRPL and FORTH which indeed have IF/ELSE/THEN/ whith a much more “Reverse Polisch” behaviour.
@ Egan Ford
Thank you for our interesting input and thoughts. I was not aware that userRPL and FORTH have so much in common. Again, you indicate me a good subject of studies and I will certainly past my for-coming weekend in learning a lot of new stuff by reading and experimenting of few bits in FORTH.
At first, the IF/ELSE.THEN syntax in FORTH pulzze me. FORTH have so much common syntax and stack operation (i.e. DUP DROP, etc…) . That’s perhaps why the syntax of IF/ELSE/THEN misleads me at first before I realize that the END statement was “missing”. It is fact it is not a lack in FORTH, it is RPL which have one extra statement, making the IF statement useless.
DUP 6 < IF DROP 5 ELSE 1 - THEN ;
IF DUP 6 < THEN DROP 5 ELSE 1 – END
These two lines have the same effet on the top value in the stack. Oppositely to FORTH the IF statement in RPL have no effect and the following variation of the code are equivalent: (changing position of IF/ELSE/THEN statements in FORTH will lead to a catastrophe)
IF DUP 6 < THEN DROP 5 ELSE 1 - END
DUP IF 6 < THEN DROP 5 ELSE 1 - END
DUP 6 IF < THEN DROP 5 ELSE 1 - END
DUP 6 < IF THEN DROP 5 ELSE 1 - END
Amazing ! I never realize that.
@ Pal G.
Exactly, I generally first wrote first version of code using local variable or algebraic expression or what ever format is convenient depending of source of information. It this first phase, the function/programs are generally like prototypes and the first effort is to avoid any mistake or wrong transcription from the sources.
Then after playing with it and using this ‘first generation’ of code, I sometime rewrite most useful section of code in a more compact manner.
This is not systematic the great majority of code stay in the ‘easy to write it’ format. Only portion of code I use often will be ‘compilated’ into more ‘compact’ format. It is also copy to another part of the memory (I greatly use sub-directory to organize multiple project on my HP28S and share code have to be move to the top of the sub-directory tree.
Since HP28S lacks any export/import capabilities with external PC, printing and saving ‘compact code’ documentation will help re-typing it into the calculator. This appends time to time.
As far as I know, there is no “stack manipulation” decompiler on the HP28S, perhaps it may be one develop by the HP48/49/50 active community on these calculators or PC (since these are much more connected than old style HP28C/S).