[gambit-list] Returning a symbol to scheme from C

Alex Young alex at blackkettle.org
Tue Feb 19 05:42:50 EST 2013

On 18/02/2013 17:39, Jeff Read wrote:
> On Feb 18, 2013 11:21 AM, "Alex Young" <alex at blackkettle.org
> <mailto:alex at blackkettle.org>> wrote:
>  > I've got a C function behind a c-lambda which needs to do some grubbing
>  > around with a select(2) call and decide on a scheme symbol to return as
>  > an indication of what it did, and whether an error condition occurred.
>  > Basically I want to use that symbol as a signal to drive a transition in
>  > a state machine.
>  >
>  > How one gets hold of a named symbol as a ___SCMOBJ (or anything more
>  > appropriate) from C isn't explained in the docs, and the wiki seems to
>  > have fallen over. It's also not immediately obvious from gambit.h
>  > whether there's a macro for this purpose.
>  >
> I think there are a couple of ways you can do this:
> 1) c-define a Scheme procedure that returns the symbols you're
> interested in based on some parameter. In the most general case it could
> be just a wrapper around string->symbol.

I had thought of that.  I was rather hoping there'd be something a 
little cleaner though.  I'll give it a try, though - it's worth 
benchmarking to see if it's going to cause problems.

> 2) you're returning symbols so I think you want your C function to
> return to Scheme. Have your C function return a result code and wrap it
> in a Scheme procedure that maps the result code onto a symbol. You can
> look at Gamsock on the dumping ground for examples of how to wrap a
> low-level C function in a Scheme procedure that handles the Scheme objects.

Yeah, I was trying to avoid having to do this.  I'd be defining the 
return codes twice - once as ints (or whatever) and once as symbols.  I 
guess that's all macroable away, but still... not particularly elegant.

Thanks for the suggestions :-)


More information about the Gambit-list mailing list