Guile Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Jim's wish list: gd library interface
Todd Larason <jtl@molehill.org> writes:
[ snip ]
> R5RS features: We use R5RS multi-value return forms: VALUES,
> CALL-WITH-VALUES, and RECEIVE.
>
> I can't find RECEIVE in r5rs;
It's not there.
> Guile's (ice-9 syncase) has call-with-values and values procedures defined
> that look like they might do the right thing; what I don't understand is
> how to use them. They're (define)d, not (define-public)d, so as far as
> I understand, they can only be used from the syncase module; they're not
> used there though, so I expect I'm missing something in the guile
> module system. Anyone have some pointers?
There really should be one definition of the VALUES stuff, and (for now at least)
it should be in ice-9 or somesuch.
I suggest the following code. It's by Will Clinger, and extended by me to
redefine call-with-current-continuation in R5RS-compatible way (so that
escape procedures take any number of parameters).
------------------->8 cut cut 8<----------------------------
(define values #f)
(define call-with-values #f)
(let* ((apply apply)
(*multiple-values* (list '*multiple-values*))
(*values0* (list *multiple-values*))
(call/cc call-with-current-continuation))
(set! values
(lambda vals
(cond ((null? vals) *values0*)
((null? (cdr vals)) (car vals))
(else (cons *multiple-values* vals)))))
(set! call-with-values
(lambda (producer consumer)
(let ((vals (producer)))
(if (and (pair? vals)
(eq? (car vals) *multiple-values*))
(apply consumer (cdr vals))
(consumer vals)))))
(set! call-with-current-continuation
(lambda (f)
(call/cc
(lambda (c)
(f (lambda args (c (apply values args)))))))))
(provide 'values)
------------------->8 cut cut 8<----------------------------
Guile Home |
Main Index |
Thread Index