Hello everyone,
I am writing some MIT-Scheme specific code for flonum operations. I want
to have my procedures be restartable if one inserts the wrong arguments,
like what you get when you write (car 3). What is the most idiomatic way
to do that?
Currently I have something like
(define (assert-flonum! who x)
(let* ((arguments (call/cc (lambda (return)
(cons return x))))
(return (car arguments))
(x (cdr arguments)))
(with-restart
'use-value
"Retry with a flonum."
(lambda (new-value) (retry (cons return new-value)))
values
(lambda ()
(unless (flonum? x)
(error:wrong-type-argument x
"flonum"
who))))))
but when I insert a bad value into it, I get the following
1 ]=> (assert-flonum! 'asdf 1)
;The object 1, passed as an argument to asdf, is not a flonum.
;To continue, call RESTART with an option number:
; (RESTART 2) => Retry with a flonum.
; (RESTART 1) => Return to read-eval-print level 1.
2 error> (restart 2)
;The procedure #[compound-procedure 13] has been called with 0
arguments; it requires exactly 1 argument.
;To continue, call RESTART with an option number:
; (RESTART 2) => Return to read-eval-print level 2.
; (RESTART 1) => Return to read-eval-print level 1.
How would I get something like the restart for the built-ins?
-- Peter McGoron