[CM] R7RS support

Rudolf Adamkovič salutis at me.com
Tue Jan 18 08:48:07 PST 2022


bil at ccrma.Stanford.EDU writes:

> The with-exception definition in r7rs.scm probably should be
>
> (define (with-exception-handler handler thunk)
>    (catch #t thunk (lambda args (apply handler args))))

It still fails with the 101 example from the R7RS standard:

;; λ (with-exception-handler
;;     (lambda (x)
;;       (display "something went wrong\n"))
;;   (lambda ()
;;     (+ 1 (raise 'an-error))))

I get the error:

;; (apply handler args): too many arguments: ((lambda (x) ...)
;;   unbound-variable ("unbound variable ~S in ~S"
;;   raise (+ 1 (raise 'an-error))))
;;     (apply handler args)
;;     *stdout*, line 1, position: 92
;;  (apply handler args)

I came up with the following, which seems to work:

;; λ (define (with-exception-handler handler thunk)
;;    (catch #t thunk (lambda args (apply handler args))))

As a beginner, I ask: Do you approve?

> The define-library code dates from the days (years ago)
> when s7's define-macro returned the symbol rather than
> the value.  Also, I apparently missed the built-in library
> for r5rs names.  For the latter add
>
> […]
>
> That is, symbol->value is probably not needed anymore.

This helped me tremendously.

*** Thank you so much, Bill! ***

(It also made me scared to use the R7RS features!)

To finish the job, I made the libraries load *implicitly* with …

;; (define-macro (import . libs)
;;   (begin
;; 
;;     (let recur ((libs libs))
;;       (if (null? libs) #t
;;           (begin
;;             (load (library-file (car libs)))
;;             (recur (cdr libs)))))
;; 
;;     `(varlet <…snip…>

… where the 'library-file' procedure converts, for example, '(foo-bar
baz)' to 'foo-bar-baz.scm'.  Now, a simple 'import' call loads the
library and every works right away, like in the big Schemes.

I would like to thank you again, Bill. Your expert advice helped me.

P.S. We now have two screens in one of our games powered by s7, and
everything seems good.  Onward and upward!

Rudy
-- 
"'Contrariwise,' continued Tweedledee, 'if it was so, it might be; and
if it were so, it would be; but as it isn't, it ain't. That's logic.'"
-- Lewis Carroll, Through the Looking Glass

Rudolf Adamkovič <salutis at me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia



More information about the Cmdist mailing list