[r6rs-discuss] Compile-time detection of contract violations

From: Abdulaziz Ghuloum <aghuloum>
Date: Thu Oct 26 15:17:37 2006

On Oct 26, 2006, at 12:32 PM, AndrevanTonder wrote:

> On Thu, 26 Oct 2006, William D Clinger wrote:
>
>> It is, I think. Section 9.22 of the R5.91RS draft says:
>>
>> Most implementations are able to recognize some violations
>> when parsing, expanding macros, or compiling a definition
>> or expression whose evaluation has not yet commenced in
>> the usual sense. Implementations are allowed to use
>> nonstandard exception handlers at those times, and are
>> encouraged to raise &syntax exceptions for violations
>> detected at those times,
>
> Given this, it is unclear to me if the intent is that the expressions
>
> (with-exception-handler (lambda (condition) 1) (cons 1 2 3))
>
> (with-exception-handler (lambda (condition) 1) (/ 0))
>
> (with-exception-handler (lambda (condition) 1)
> (length (let ((ones (cons 1 #f)))
> (set-cdr! ones ones)))
>
> should be portably valid Scheme.

Good question. I think you intended:
   (with-exception-handler (lambda (condition) 1) (lambda () (cons 1 2
3)))
   (with-exception-handler (lambda (condition) 1) (lambda () (/ 0)))
   (with-exception-handler (lambda (condition) 1) ---)
since with-exception-handler takes a thunk as the second argument.

> I.e., should the fact that there is a custom runtime exception handler
> override any compile-time type checking, thus making these expressions
> valid?

You cannot, in general, detect at compile time whether a custom
exception handler is installed or not. For example, f may install a
custom handler in (f (lambda () (cons))). So, I think the issue of
whether (cons) is a valid expression stands, regardless of the
existence of custom exception handlers.

Aziz,,,
Received on Thu Oct 26 2006 - 15:17:40 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC