If it was just passing keyword arguments to your function, you might be
able to do it like this:

; https://docs.racket-lang.org/guide/lambda.html
; https://docs.racket-lang.org/reference/procedures.html

(define greet
  (lambda (given #:last surname)
    (string-append "Hello, " given " " surname)))

; 'apply' allows you to specify a keyword argument ...
(define (test f . args)
  (apply f args #:last "Doe"))

(test greet "John") ; => "Hello, John Doe"

On Thu, Aug 22, 2019 at 3:32 PM Kevin Forchione <lyss...@gmail.com> wrote:

>
>
> > 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
> .
>

-- 
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/CACgrOxJ%3DAadxH4_9a2u%2B0XZhVpyT2gA-qLtRrhWAy3w2JLRtmw%40mail.gmail.com.

Reply via email to