chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Type conversion in the FFI


From: Daniel B. Faken
Subject: Re: [Chicken-users] Type conversion in the FFI
Date: Tue, 13 Apr 2004 09:12:44 -0400 (EDT)

On Tue, 13 Apr 2004, felix wrote:
>  [...]
> ; Converters:
> 
> (define (uchar->my-bool x) (not (eq? 0 (char->integer x))))
> (define (my-bool->uchar x) (integer->char (if x 1 0)))
> 
> ; Define a foreign type that uses the converters:
> 
> (define-foreign-type my-bool unsigned-char my-bool->uchar uchar->my-bool)
> 
> ; Just for trying it out:
> 
> #>
> unsigned char foo(unsigned char x) { return !x; }
> <#
> 
> (define foo
>    (foreign-lambda my-bool "foo" my-bool) )
> 
> (print (foo #t))
> (print (foo #f))

  OK, thank you.
  I was basically trying to avoid the double-definition of functions (as 
of 'foo' above) in scheme, just using the chicken-parsed C interface, but
I guess the FFI can't handle the use of scheme-types inside C code
- e.g. "my-bool foo(my bool x) { return !x; }".
  In my actual code I have in C 'typedef unsigned char BOOL', and I was 
hoping I could somehow convince the FFI parser that the 'BOOL' type should 
be treated as an unsigned-char-to-be-converted-to/from-boolean.  I tried
not letting chicken see the typedef above, but it gets confused.

> >   On an unrelated note, where can I find out more about "properties", as 
> > mentioned in the hash-table docs?  These seem to be a common feature of 
> > LISP/scheme, but I couldn't find anything in R5RS..
> 
> R5RS doesn't have anything like LISPs property lists. Chicken has something
> similar to CLs "disembodied" property lists, that is, property lists that are
> not attached to symbols (as in LISP).
> Essentially, those p-lists are just hashtables containing association lists.

thanks!

regards,
Daniel Faken






reply via email to

[Prev in Thread] Current Thread [Next in Thread]