[plt-scheme] keywords with C API

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Sat Aug 8 10:36:49 EDT 2009

I would suggest to do it in two steps, i.e., to use a Scheme function as 
a wrap that takes keyword arguments, which pass everything to the actual 
C function (with no keyword arguments).

Chongkai

gabor papp wrote:
> Hi all,
>
> I'm trying to write a 3m function that can take keyword arguments, but 
> I'm not sure how to do it.
>
> I create the function like this:
>
> scheme_add_global("test-function", 
> scheme_make_prim_w_arity(test_function, "test-function", 0, -1), env);
>
> trying to get the keyword as a string:
>
> Scheme_Object *test_function(int argc, Scheme_Object **argv)
> {
>     MZ_GC_DECL_REG(1);
>     MZ_GC_VAR_IN_REG(0, argv);
>     MZ_GC_REG();
>
>     char *keyword = SCHEME_KEYWORD_VAL(argv[0]);
>     MZ_GC_UNREG();
>     return scheme_void;
> }
>
> when I try to call the function from scheme by typing (test-function 
> #:test 0), I receive the following error:
> test-function: does not accept keyword arguments; arguments were: 
> #:test 0
>
> Is there another way to register these kind of funtions?
>
> Thanks,
> Gabor
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.