John Harper writes:
> Jesse Marlin writes:
> |I want to pass a lisp list to a C function using librep. The list will be
> |the equivalent of ORing a number of options together, and I was just
> |wondering how this will be represented in C land. An indexed array,
> |a linked list? Thanks.
>
> I'm not sure I fully understand the question. But if you pass any lisp
> object to a C function it's passed as a `repv' value -- this is just a
> piece of (typed) lisp data.
>
> As you know, lists are built from cons cells, you can use the macros
> rep_CONSP, rep_CAR and rep_CDR to access the values of the list from C,
> as you would do in lisp. E.g.
>
> void
> my_function (repv list)
> {
> repv first, second;
>
> if (rep_CONSP (list))
> {
> /* `list' is a cons, so can safely refer to the first object */
> first = rep_CAR (list);
>
> if (rep_CONSP (rep_CDR (list)))
> {
> /* the cdr of `list' is also a cons */
> second = rep_CAR (rep_CDR (list));
> }
> else
> error handling;
> }
> else
> error handling;
>
> do something with `first' and `second'...
> }
Thanks, that's what I was looking for, not the code, but how to traverse
the list in C.
>
> if you find that you're doing too much list manipulation in C code, it
> usually means that your design may need rethinking, so that more of the
> code can be written in lisp!
I was just looking for way to pass options via a list so that I could
OR them together in C land.
my_function (OPTION1 | OPTION2 | OPTION3)
>
> John
>
> _______________________________________________
> librep-list mailing list
> librep-list@...
> http://lists.sourceforge.net/mailman/listinfo/librep-list
|