home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.arch:10542 comp.lang.misc:3548
- Newsgroups: comp.arch,comp.lang.misc
- Path: sparky!uunet!elroy.jpl.nasa.gov!decwrl!pa.dec.com!rdg.dec.com!jch
- From: jch@rdg.dec.com (John Haxby)
- Subject: Re: CLU break and continue (Was: Re: A challenge to the anti-goto)
- Message-ID: <1992Nov9.114323.22688@rdg.dec.com>
- Sender: news@rdg.dec.com (Mr News)
- Organization: Digital Equipment Corporation
- References: <1cvoctINNmhs@agate.berkeley.edu> <PSM.92Nov3165530@soma.sics.se> <1992Nov3.165005.18037@midway.uchicago.edu> <184123@pyramid.pyramid.com> <721054332.26680@minster.york.ac.uk>
- Date: Mon, 9 Nov 1992 11:43:23 GMT
- Lines: 58
-
- In article <721054332.26680@minster.york.ac.uk>, mjl-b@minster.york.ac.uk writes:
- |> >You're probably thinking of the `exit'/`except' mechanism, which allows
- |> >you to escape from multiple loops (or from within a `proc', with the
- |> >`signal' statement) by raising a condition which transfers control to
- |> >the nearest enclosing handler for that condition.
- |>
- |> This sounds a lot like the Ada exception mechanism. Briefly, when an
- |> exception is raised, the run-time starts looking for a handler for that
- |> particular exception. If there isn't one for that exception in the current
- |> block, the call stack is wound back until one is found, or the top-level
- |> subprogram is reached (when the program stops).
-
- It's not surprising that the Ada exception mechanism is similar to CLU's
- since CLU is one of Ada's ancestors.
-
- CLU has two exception mechanisms for slightly different purposes. One
- mechanism is for returning an exception from a procedure call: a procedure
- can signal an exception to be caught by its caller (the exception is not propagated
- up the procedure call stack) or by a generic handler for unhandled exceptions. The
- other mechanism is a local form that allows a block (eg in a loop or if-statement) to
- exit to an enclosing block. Apart from the local/procedure-call difference the two
- mechanisms are identical, although `signal' tends to be expensive and `exit' is simply
- an unconditional branch. For example:
-
- ...
- x := sum (n)
- except when negative: x := 0 end
- ....
-
- sumOfInts = proc (n: int) signals (negative)
- if n < 0 then
- signal negative
- end
- sum: int := 0
- while true do
- sum := sum + n
- n := n - 1
- if n <= 0 then
- exit done end
- end except when done: return (sum) end
- end sumOfInts
-
- The example is a little contrived I'm afraid. Both sorts of exception can be
- parameterized. For example, procedures that map on to system calls often signal
- not_possible(string) -- the string is the string representation of the error code
- from the routine when it fails.
-
- Liskov and Guttag's "Abstraction and Specification in Program Design",
- already cited, is much better at explaining this than I am on a Monday
- morning.
-
- --
- John Haxby, Definitively Wrong.
- Digital <jch@rdg.dec.com>
- Reading, England <...!uknet!wessex!jch>
-
- ----------------------------------------------------------------
- The opinions expressed herein are my own, not my employers.
-