austern@ux5.lbl.gov (Matt Austern) (12/15/90)
As far as I can tell, the HP 48 doesn't provide any way to break out of a loop in the middle (in C, break), and doesn't provide any way to return from a function anywhere but the end. (in C, return). Yes, I know that it's always possible to avoid using these if you put in an extra test or flag, but sometimes they are convenient. Am I missing something very basic? Or if there really is no break or return, has anyone out there found a good kludge to simulate them? -- Matthew Austern austern@lbl.bitnet Proverbs for paranoids, 3: If (415) 644-2618 austern@ux5.lbl.gov they can get you asking the wrong austern@lbl.gov questions, they don't have to worry about answers.
lennartb@lne.kth.se (Lennart Boerjeson @ KTH/LNE, The Royal Inst. of Tech.) (12/17/90)
In article <8601@dog.ee.lbl.gov>, austern@ux5.lbl.gov (Matt Austern) writes: >As far as I can tell, the HP 48 doesn't provide any way to break out >of a loop in the middle (in C, break), and doesn't provide any way to >return from a function anywhere but the end. (in C, return). Yes, I >know that it's always possible to avoid using these if you put in an >extra test or flag, but sometimes they are convenient. > >Am I missing something very basic? Or if there really is no break or >return, has anyone out there found a good kludge to simulate them? >-- >Matthew Austern austern@lbl.bitnet Proverbs for paranoids, 3: If >(415) 644-2618 austern@ux5.lbl.gov they can get you asking the wrong > austern@lbl.gov questions, they don't have to worry > about answers. I usually do that by surrounding the code I might want to break out of with an IFERR. Then I can 'break' out with a DOERR call. E.g: IFERR ... DO .... .... .... "BREAK" DOERR .... .... UNTIL ... END THEN IF ERRM "BREAK" SAME NOT THEN @ Was it 'break' ? @ ERRN DOERR @ No, resignal error @ END END !++ ! Lennart Boerjeson, System Manager ! School of Electrical Engineering ! Royal Institute of Technology ! S-100 44 Stockholm, Sweden ! tel: int+46-8-7907814 ! Internet: lennartb@lne.kth.se !--
rrd@hpfcso.HP.COM (Ray Depew) (12/18/90)
> As far as I can tell, the HP 48 doesn't provide any way to break out > of a loop in the middle (in C, break), and doesn't provide any way to > return from a function anywhere but the end. (in C, return). Yes, I > know that it's always possible to avoid using these if you put in an > extra test or flag, but sometimes they are convenient. In his book "HP-41 / HP-48 Translations", Bill Wickes mentions that the command << ... CONT ... >> breaks you out of a subroutine and back into the next level. I would think that you could include a local subroutine that would do your loop for you. For example, the program << . . << a b FOR c . . . IF ... THEN CONT END . . >> . -> loop . . loop EVAL . . >> may do it for you. ----- Regards Ray Depew IC's by Bill and Dave rrd@hpfitst1.hp.com
umapd51@cc.ic.ac.uk (W.A.C. Mier-Jedrzejowicz) (12/19/90)
The author asks - where are BREAK and RETURN on the HP48 - is he missing something very basic? Well, yes Matthew, you are missing something very basic - the designers of the RPL language believe deeply in structured programming where blocks of code have only one entry point and one exit point. This IS the basic point - so there is no method designed to let you break out of a loop or return before the end of a subprogram. Providing such commands would be contrary to the nature of the language. This is not to say there is anything intrinsically wrong with BREAK or RETURN - and being a typical HP hacker, I wondered how these could be achieved - in fact I am writing a series of articles on that very topic right now in DATAFILE (the journal of the British club for users of HP handhelds - available to members regularly 8 times a year). Bill Wickes himself provides some very welcome clues in his book HP41/HP48 Transitions. One example is that an error in an IFERR causes the rest of the IFERR to be skipped - and you can use DOERR to force an error where you wish - this combination lets you BREAK out of a block of code if you want to do that. Other tricks are available too, and are mentioned in passing in Bill's book. You can try causing an error in a subprogram to leave that subprogram prematurely too. Alternatively, you can treat RPL as a language which forces you to learn structured programming with only one entry point and one exit point per block of code - it is quite interesting to learn how this can be done if you are coming from an unstructured language, such as FORTRAN. Best Wishes, Wlodek Mier-Jedrzejowicz, Space & Atmospheric Physics, Imperial College, London.
edp@jareth.enet.dec.com (Eric Postpischil (Always mount a scratch monkey.)) (12/20/90)
In article <7360030@hpfcso.HP.COM>, rrd@hpfcso.HP.COM (Ray Depew) writes: >In his book "HP-41 / HP-48 Translations", Bill Wickes mentions that the >command << ... CONT ... >> breaks you out of a subroutine and back into the >next level. It seems that the "next level" it brings you back to is not just the calling routine. Perhaps it takes you back to an interrupted routine? It seems CONT is not useful as a RETURN/BREAK. -- edp (Eric Postpischil) "Always mount a scratch monkey." edp@jareth.enet.dec.com