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 _______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
