[Ecls-list] Accessing cons values in C

Nils Bruin nbruin at cecm.sfu.ca
Wed Jul 29 23:06:22 UTC 2015


On Thu, 30 Jul 2015, Chris Osborne wrote:

> Anyhow, here’s the solution:
> I just found that enable-smallcons is on by default (for some major performance gains when I looked into it). In this scenario, there’s a set of macros ECL_CONS_PTR, ECL_CONS_CAR etc. defined in object.h to access the cons pointers directly, not sure how I missed this earlier, but at least I’ve found it now (hopefully the info will also show up in the mailing list archive in a web search if anyone else needs it).

I think the recommended interface lives in cons.h, where CAR and CDR are 
defined as macros that, if ECL_CAN_INLINE is true, resolve to essentially 
inlined functions that call the macros ECL_CONS_CAR and ECL_CONS_CDR. The 
only thing they do extra is test if the argument is NIL and do the 
appropriate thing in those cases (where ECL_CONS_* would probably fail).

You might want to check if for your application the tiny overhead of 
checking for NIL is so troublesome that you're willing to sacrifice 
robustness against NIL arguments and readability (it doesn't get much 
better than CAR and CDR for asking of the car and the cdr of a cons)

Kind regards,

Nils


More information about the ecl-devel mailing list