mit-scheme-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MIT-Scheme-devel] guarantors and restartability


From: Taylor Campbell
Subject: [MIT-Scheme-devel] guarantors and restartability
Date: Fri, 9 Dec 2005 03:47:58 +0000 (UTC)
User-agent: IMAIL/1.21; Edwin/3.116; MIT-Scheme/7.7.90.+

One feature of T that I've always found useful is the ability to
continue from errors signalled by the ENFORCE procedure, which can be
used to check arguments in a convenient way:

 (let ((x (enforce foo? x)))
   ...)

If X does not satisfy FOO?, ENFORCE signals an error and lets someone
at the REPL return a new value, which it loops with, until it gets a
value satisfying FOO?.  ENFORCE then returns the first valid datum.
Is there a reason that the guarantor procedures don't work similarly,
or don't have variants that work similarly?  If not, I'll implement
it: I think it would greatly simplify a lot of debugging in running
programs.

(define-integrable (guarantee-integer* value #!optional caller)
  (if (not (integer? value))
      (error:not-integer value caller)
      value))

(define (error:not-integer* value #!optional caller)
  (let loop ((value value))
    (call-with-current-continuation
     (lambda (continuation)
       (with-restart 'USE-VALUE "Specify a value to use in its place."
           (lambda (value)
             (within-continuation continuation
               (lambda ()
                 (if (integer? value)
                     value
                     (loop value)))))
           (lambda ()
             (values (prompt-for-evaluated-expression "New value")))
         (lambda ()
           (error:wrong-type-argument value "integer"
                                      (if (default-object? caller)
                                          #f
                                          caller))))))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]