> On Aug 22, 2019, at 1:33 PM, Kevin Forchione <lyss...@gmail.com> wrote:
>
> Hi guys,
> Suppose I have something like the following:
>
> (define (f g . args)
> (apply g args))
>
> How would I be able to pass keyword arguments to g?
After racking my brains for the common lisp &allow-other-keys and googling for
the scheme/Racket equivalent, stumbling through mzlib/kw and finally a bit of
digging through racket procedure documentation I cobbled together an approach
that seems to do what I’m after. So I thought I’d share. Here’s an example:
#lang racket
(define (foo #:a (a 0) #:b (b 1) c (d 3) . rst) (list a b c d rst))
(define show
(make-keyword-procedure (λ (kws kw-args f . args) (keyword-apply f kws
kw-args args))))
(show foo #:a 10 2 3 4 5 6 7)
=> '(10 1 2 3 (4 5 6 7))
Now apparently any keywords defined for show itself are captured in the kWh and
kw-args lists and would need to be filtered out of those lists before tasing
them on to f, but that shouldn’t be too difficult.
Kevin
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/395CF1DB-3B85-4FFA-9C1B-5566EB2CC60F%40gmail.com.