[racket-dev] comments on "comments on learning Racket"
> From: Laurent <laurent.orseau at gmail.com>
> Subject: Re: [racket-dev] comments on "comments on learning Racket"
> Date: April 27, 2014 at 2:39:50 AM MST
> To: Matthias Felleisen <matthias at ccs.neu.edu>
> Cc: "dev at racket-lang.org Devs" <dev at racket-lang.org>
>
>
> On Sun, Apr 27, 2014 at 1:09 AM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> ** tab completion must be faster
>
> ** Do we need to add these to our library?
>
> ;; (X ... -> Y ...) X *-> [List-of Y]
> (define (gather-return-values f . s)
> (call-with-values (lambda () (apply f s)) list))
>
> ;; Nat (X ... -> Y ...) X *-> Y
> (define (nth-return-value i f . s)
> (call-with-values (lambda () (apply f s)) (lambda l (list-ref l i))))
>
> I've been having a need of these functions on several occasions myself too.
> (Although the names are too long, but maybe just omitting `return` would be acceptable to my taste.)
>
Hmmm… except for he name, I think I like that better than my own approach I wrote recently:
(require racket/function)
(define-syntax (values->list stx)
(syntax-case stx ()
[(_ (f args ...))
#'(call-with-values (thunk (f args ...)) list)]))
(define-syntax (values-ref stx)
(syntax-case stx ()
[(_ (f args ...) n)
(if (negative? (syntax->datum #'n))
(raise-argument-error 'values-ref
"exact-nonnegative-integer?"
1
(syntax->datum #'(f args ...))
(syntax->datum #'n))
#'(let ([lst (values->list (f args ...))])
(if (<= 0 n (length lst))
(list-ref lst n)
(raise-arguments-error 'values-ref
"index too large for values list"
"index" n
"in" lst))))]))
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20140428/aa112dea/attachment.html>