[racket] REPL @ Runtime Contract Modification?

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Fri Jun 28 00:08:32 EDT 2013

 In Common Lisp you have to use construction like

(restart-case 
       (/ 1 x) 
    (use-value (value) "" value)) 

or cerror or something like that.

I don't see, what prevents Racket to do the same: restart-case capture continuations and handler-case, handler-bind or debugger choose the continuation.

Something like:

(define (test l) 
  (if (null? l)
      '()
      (cons (let/cc k (with-handlers 
                          ([exn? (λ (v) (raise (cons v k)))]) 
                        (/ 1 (car l))))
            (test (cdr l)))))

Then debugger can catch the continuation and call (k new-value).




Четверг, 27 июня 2013, 13:32 -06:00 от Matthew Flatt <mflatt at cs.utah.edu>:
>At Thu, 27 Jun 2013 12:35:10 -0400, Sean Kanaley wrote:
>> As a more general solution to this kind of interactive debugging issue, 
>> how difficult would implementing a typical Common Lisp REPL be? I'm 
>> thinking of adding the kind of error/condition handler like:
>> 
>> "<error or condition goes here>
>> 
>> enter a number:
>> 
>> 0 - enter new value
>> 1 - exit to top level
>> 2 - exit one level
>> 3 - print stack trace
>> 4 - etc.
>> 
>> I'm not familiar with Racket's internals so I don't know how much this 
>> is a REPL hack vs. rewriting the whole system (the condition system 
>> isn't necessary)... If it's not too impossible I would be happy to make 
>> this contribution...
>
>Racket's implementation (and maybe to some degree, I think, its design)
>does not support restartable exceptions, except in the case of the
>`exn:break' exception. So, option 0 would be difficult or impossible to
>implement as a hook into the run-time system.
>
>A debugger could instrument programs to allow this kind of restart by
>wrapping every expression with a prompt, but I think that would be
>fairly expensive in the current implementation.
>
>____________________
>  Racket Users list:
>   http://lists.racket-lang.org/users


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130628/0821d7ec/attachment-0001.html>

Posted on the users mailing list.