Thanks! Your answer led me to find keyword-apply, so I just wrote (I use 
def as abbreviation for define):

(def (parse-args xs)
  (def (fn ks kvs vs xs)
    (cond [(empty? xs)  (map reverse (list ks kvs vs))]
          [(keyword? (car xs))
           (fn (cons (car xs) ks) (cons (cadr xs) kvs) vs (drop xs 2))]
          [else (fn ks kvs (cons (car xs) vs) (cdr xs))]))
  (fn '[] '[] '[] xs))

(def (func-args func args)
  (apply keyword-apply func (parse-args args)))

And now I can do 
:
(def (suma a b #:c [c 0]) (+ a b c))
(func-args suma (list 1 2 #:c 3))

and it works fine.

Thanks again!
On Thursday, 26 November 2020 at 10:06:26 UTC+1 [email protected] wrote:

> If you are OK with preprocessing the argument list into a dictionary, then 
> you can use keyword-apply/dict 
> <https://docs.racket-lang.org/reference/dicts.html?q=keyword%2Fapply#%28def._%28%28lib._racket%2Fdict..rkt%29._keyword-apply%2Fdict%29%29>
> .
>
> For example:
>
> #lang racket
>
> (require racket/dict)
>
> (define proc (lambda (#:color color #:size size) (display (cons color size))))
> (define args '(#:color "red" #:size 3))
> (define args*
>   (for/hash ([chunk (in-slice 2 args)])
>     (values (first chunk) (second chunk))))
>
> (keyword-apply/dict proc args* '())
>
>
> On Thu, Nov 26, 2020 at 12:53 AM Dimaugh Silvestris <[email protected]> 
> wrote:
>
>> Is it possible to reproduce this behavior
>> ((lambda (#:color color #:size size) (display (cons color size))) #:color 
>> "red" #:size 3)
>> when what I have is a list such as '(#:color "red" #:size 3) ?
>> How can I feed keyword arguments stored in a list as symbols in a way 
>> that doesn't involve parsing manually?
>>
>> -- 
>> 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 [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/06a1b45b-77ca-4595-b5b6-0b4ce01fe026n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/racket-users/06a1b45b-77ca-4595-b5b6-0b4ce01fe026n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/413ea474-0eac-4c7a-97a4-0c4ee711eb60n%40googlegroups.com.

Reply via email to