[gambit-list] c-interface: relaxing type checking on the scheme side

Christian Jaeger christian at pflanze.mine.nu
Tue Feb 5 04:58:18 EST 2008


James Long wrote:
> Is there anyway to specify multiple tags for a type so that, for
> example, I could pass either a float or an int to a c function?  C's
> basic type coercion, in my opinion, is not a bad thing

See the two attached solutions. floatorint.scm is a type-safe variant, 
it lets you pass around the original value (a union type), while 
coerce.scm really coerces the value directly (feel free to add code to 
check whether a float is within the int range yourself ;)).

Christian.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: floatorint.scm
Type: text/x-scheme
Size: 1441 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20080205/122b1152/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coerce.scm
Type: text/x-scheme
Size: 904 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20080205/122b1152/attachment-0001.bin>


More information about the Gambit-list mailing list