home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / misc / 2772 < prev    next >
Encoding:
Internet Message Format  |  1992-08-23  |  4.6 KB

  1. Path: sparky!uunet!mcsun!uknet!gdt!aber!aberfa!pcg
  2. From: pcg@aber.ac.uk (Piercarlo Grandi)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: PL/1 non-local goto versus setjmp/longjmp
  5. Message-ID: <PCG.92Aug23182804@aberdb.aber.ac.uk>
  6. Date: 23 Aug 92 18:28:04 GMT
  7. References: <1992Aug12.073130.1@zodiac.rutgers.edu> <id.VJBS.0DK@ferranti.com>
  8.     <mwm.1jk3@contessa.palo-alto.ca.us> <id.KTGS.0N5@ferranti.com>
  9.     <1992Aug20.074423.4841@cs.rug.nl>
  10. Sender: news@aber.ac.uk (USENET news service)
  11. Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
  12. Organization: Prifysgol Cymru, Aberystwyth
  13. Lines: 98
  14. In-Reply-To: laverman@cs.rug.nl's message of 20 Aug 92 07: 44:23 GMT
  15. Nntp-Posting-Host: aberdb
  16.  
  17. On 20 Aug 92 07:44:23 GMT, laverman@cs.rug.nl (Bert Laverman) said:
  18.  
  19.     [ ... non local control transfer ... ]
  20.  
  21. laverman> [Impressive demonstration by Peter removed] I'm sorry, but
  22. laverman> aren't you just implementing Exceptions here?
  23.  
  24. Ah, one of my pet peeves! To bad for you! :-)
  25.  
  26.  
  27. There is *absolutely no way* to implement exceptions. There is no such
  28. thing as an exception that can be implemented. Virtually all the
  29. research (includig voluminous Ph.D. thesises, proceedings, books, ...)
  30. on exception is misguided and pointless.
  31.  
  32. There have been even incredibly ridicolous attempts to have exceptions
  33. as language entities, and the ensuing and toally pointless discussions
  34. (should they be a first class data type? should they be statically or
  35. dynamically scoped? and son on...) have provided cannon fodder for many
  36. a silly debate.
  37.  
  38.  
  39. On the other hand there is some relationship between 'exception
  40. handling' and non nested control transfers, and maybe it will be useful
  41. if I make it clear.
  42.  
  43. First of all, let's talk of what an 'exception' is: it is a *fact*,
  44. not a language construct, or value, it is the fact that the state of the
  45. computation has become undefined.
  46.  
  47. This happens iff a procedure implements a non total function, and the
  48. procedure is applied outside that function's codomain.
  49.  
  50. This happens iff the precondition of a branching construct is weaker
  51. than the union of the preconditions of the branches. For example,
  52. computing
  53.  
  54.     3 / 0
  55.  
  56. is undefined because in the implementation of the / procedure (whether
  57. it be microcode, hardwired, macrocode) there is something like:
  58.  
  59.   if
  60.     divisor == 1 ->      quotient = dividend;
  61.   | powerof2(divisor) ->  quotient = shiftright(divident,log2(divisor));
  62.   | not powerof2(divisor)
  63.     and divisor <> 1
  64.     and divisor <> 0 ->      quotient = newt_raph_div(divisor,dividend);
  65.   fi
  66.  
  67. So, 'exception handling' is just making all procedures implement total
  68. functions. Unfortunately this is in general cannot be done at procedure
  69. definition time, because extending certain functions so that they become
  70. total can be done in several different ways, and there cannot be
  71. previous agreement as to how.
  72.  
  73. For example in some cases division by zero should return a token for
  74. 'infinite', in some case it should return zero, and so on.
  75.  
  76. Therefore, 'exception handling' should normally consist in completing
  77. all branching statements so that their precondition is never weaker than
  78. the unions of those for their branches, and each new branch should be a
  79. call to a *dynamically* scoped procedure name.
  80.  
  81.  
  82. for example:
  83.  
  84.   if
  85.   | divisor == 0 ->      quotient = div_by_zero(divisor,dividend);
  86.     divisor == 1 ->      quotient = dividend;
  87.   | powerof2(divisor) ->  quotient = shiftright(divident,log2(divisor));
  88.   | not powerof2(divisor)
  89.     and divisor <> 1
  90.     and divisor <> 0 ->      quotient = newt_raph_div(divisor,dividend);
  91.   fi
  92.  
  93. The body of div_by_zero may then contain any arbitrary logic that the
  94. programmer of the upper levels of the program wishes.
  95.  
  96. In particular two choices seem to be common for the body of such a
  97. procedure, and they are returning a 'default' value, or doing a non
  98. local control transfer to higher level handling code. In the latter case
  99. the dynamically scoped procedure does not just substitute for the
  100. "missing" branch, but also for a number of intervening abstraction levels
  101. that depend on the outcome of that branch.
  102.  
  103. It is only in the second case that non local control transfers enter the
  104. 'exception' handling picture at all; in such a case they are required,
  105. but they are useful for many other reasons.
  106.  
  107. Unfortunately there is some silly tradition by which even relatively
  108. serious authors pretend that exceptions are 'objects' or language
  109. 'entities', or exception handling is made to coincide with non local
  110. control transfers, or other entirely inappropriate perversions.
  111. --
  112. Piercarlo Grandi                   | JNET: pcg@uk.ac.aber
  113. Dept of CS, University of Wales    | UUCP: ...!mcsun!ukc!aber-cs!pcg
  114. Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@aber.ac.uk
  115.