home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / arch / 10455 < prev    next >
Encoding:
Internet Message Format  |  1992-11-07  |  3.0 KB

  1. Xref: sparky comp.arch:10455 comp.lang.misc:3522
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!doc.ic.ac.uk!uknet!yorkohm!minster!mjl-b
  3. From: mjl-b@minster.york.ac.uk
  4. Newsgroups: comp.arch,comp.lang.misc
  5. Subject: Re: CLU break and continue (Was: Re: A challenge to the anti-goto)
  6. Message-ID: <721054332.26680@minster.york.ac.uk>
  7. Date: 6 Nov 92 12:52:14 GMT
  8. References: <1cvoctINNmhs@agate.berkeley.edu> <PSM.92Nov3165530@soma.sics.se> <1992Nov3.165005.18037@midway.uchicago.edu> <184123@pyramid.pyramid.com>
  9. Reply-To: mjl-b@minster.york.ac.uk (Mathew Lodge)
  10. Organization: Department of Computer Science, University of York, England
  11. Lines: 63
  12.  
  13. In article <184123@pyramid.pyramid.com> moliver@pyramid.com (Mike Oliver) writes:
  14. >In article <1992Nov3.165005.18037@midway.uchicago.edu> dave@alex.uchicago.edu (Dave Griffith) writes:
  15. >>It should be noted that Ada and CLU have named loops and named breaks.
  16. >
  17. >I can't comment on Ada, but `break' in CLU (at least the version
  18. >described in Liskov and Guttag's 1986 "Abstraction and Specification in
  19. >Program Development") only has the ordinary single-level behaviour,
  20. >which lets you escape from the smallest enclosing loop.
  21.  
  22. In Ada you can escape to any level using a named loop. For example:
  23.  
  24. OUTER_LOOP: -- Named outer loop
  25. loop
  26.    loop
  27.       loop
  28.       -- some code
  29.      exit OUTER_LOOP; -- exit the outer loop
  30.       end loop;
  31.       -- ...
  32.    end loop;
  33.    -- ...
  34. end loop;
  35.  
  36. >You're probably thinking of the `exit'/`except' mechanism, which allows
  37. >you to escape from multiple loops (or from within a `proc', with the
  38. >`signal' statement) by raising a condition which transfers control to
  39. >the nearest enclosing handler for that condition.
  40.  
  41. This sounds a lot like the Ada exception mechanism. Briefly, when an
  42. exception is raised, the run-time starts looking for a handler for that
  43. particular exception. If there isn't one for that exception in the current
  44. block, the call stack is wound back until one is found, or the top-level
  45. subprogram is reached (when the program stops).
  46.  
  47. It gets to be more complicated than this, particularly if you use tasks.
  48.  
  49. >>           Named continues, to use C terminology, are an obvious corrollary,
  50. >>but I don't believe that either Ada or CLU implements them (or even normal
  51. >>continues, for that matter.)  
  52. >
  53. >CLU (again, the 1986 version) has the normal `continue', which
  54. >terminates execution of the smallest enclosing loop and begins the next
  55. >cycle, if one is required.
  56.  
  57. This sounds like normal use of the Ada exit statement, which exits the
  58. enclosing loop.
  59.  
  60. >BTW, anti-goto purists will be happy to learn that CLU doesn't have a
  61. >`goto' statement.
  62.  
  63. Ada does, but the labels are surrounded by << and >>, which makes them very
  64. obvious during code review :-)
  65.  
  66. >Cheers, Mike.
  67. >
  68. >moliver@pyramid.com
  69. >{allegra,decwrl,hplabs,munnari,sun,utai,uunet}!pyramid!moliver
  70.  
  71. Mat
  72.  
  73. | Mathew Lodge                      | "I don't care how many times they go    |
  74. | mjl-b@minster.york.ac.uk          |  up-tiddly-up-up. They're still gits."  |
  75. | Langwith College, Uni of York, UK |  -- Blackadder Goes Forth               |
  76.