[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Chicken C interface
From: |
Peter Bex |
Subject: |
Re: [Chicken-users] Chicken C interface |
Date: |
Wed, 5 Jun 2013 19:50:38 +0200 |
User-agent: |
Mutt/1.4.2.3i |
On Wed, Jun 05, 2013 at 08:47:45AM -0700, Dan Leslie wrote:
> I do this a fair bit in the Allegro egg.
>
> Here's an example:
> https://github.com/dleslie/allegro-egg/blob/985ca2ceef0f5b4028af3f97729f13cba2976fe5/color.scm
>
> Basically, use C_alloc to allocate the memory required to host both the
> List structure and the data it is to contain, then use the C_list macro
> to patch it all together.
>
> >Also there doesn't seem to be a C_listp predicate. Is this a concious
> >omission?
There is no C_listp predicate because you can't directly check an
object for being a list; you must check whether it's
C_SCHEME_END_OF_LIST (then it is a list). Otherwise, if it's a pair
you take its cdr and loop. If it's something else, it's not a list.
Because this is a potentially heavy operation (and cyclic lists may
even cause an endless loop), I guess it's been decided not to provide
a predicate procedure for this, because it's too tricky to get right,
and usually you want to avoid traversing the list twice anyway, so the
operation itself is often embedded in the CDRing logic.
Cheers,
Peter
--
http://www.more-magic.net
Re: [Chicken-users] Chicken C interface, Felix, 2013/06/05
Re: [Chicken-users] Chicken C interface, Thomas Chust, 2013/06/06
Re: [Chicken-users] Chicken C interface, Kristian Lein-Mathisen, 2013/06/06
Re: [Chicken-users] Chicken C interface, Thomas Chust, 2013/06/06