this should work for basic list test

(import foreign)

#>
C_word C_listp(C_word p)
{
    if (p == C_SCHEME_END_OF_LIST)
    {
        return C_SCHEME_TRUE;
    }

    // check for non-immidiate object and pair?
    if (!C_immediatep(p) && C_pairp(p) == C_SCHEME_TRUE)
    {
        return C_listp(C_u_i_cdr(p));
    }

    return C_SCHEME_FALSE;
}
<#

(define listp? (foreign-lambda scheme-object "C_listp" scheme-object))

(print (listp? 1))
(print (listp? (cons 1 2)))
(print (listp? (cons (cons 1 2) (cons 3 4))))
(print (listp? 1.0))
(print (listp? '(1)))
(print (listp? '(1 2)))

06/05/13 19:10:41, pluijzer . <[email protected]>:
Hello everybody,

I was planning to use Chicken Scheme in a fashion more similar to Guile and Lua. i.e. passing Scheme Data Objects from Chicken to C and back using the C interface.

I am a little confused though as how to have a C function return a Scheme List that is seen by the garbage collector.

For example, is the code below correct, will the list be seen by the garbage collector? And if not, is there correct way to do this.

#>
C_word give_12()
{
  C_word *mem  = C_alloc(C_SIZEOF_LIST(2));
  C_word  list = C_list(&mem, 2, C_fix(1), C_fix(2));
  return list;
}
<#
(print ((foreign-lambda scheme-object "give_12")))

Also there doesn't seem to be a C_listp predicate. Is this a concious omission?

thank you in advance,
Richard
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to