[Ecls-list] Accessing cons values in C

2015-07-29 Thread Chris Osborne
Hi,
I’ve spent a good while looking through the project’s documentation (and 
finding useful apparently undocumented functions such as 
`ecl_base_string_pointer_safe`) but I cannot for the life of me work out how to 
access the values of a list stored in cons cells.
If I have a function that calls back into C with an argument passed as such: 
(foo ‘(1 2 3)) what’s the best way to access the values of the cells in that 
list?

The best I’ve found so far is either using cl_nth or cl_cdr and friends and 
then converting to a C number type, this seems a bit silly when I can access 
the value of a string by following the pointer tree. The documentation points 
to a type t_cons in the enum for ecl_t_of, but I can’t find it, or the cons 
value in the lispunion.

Am I missing something obvious here or do I just have to use the cl functions 
in C to access elements of what is essentially lisp’s simplest data type?

Cheers,
Chris
--
___
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list


Re: [Ecls-list] Accessing cons values in C

2015-07-29 Thread Pascal J. Bourguignon
Chris Osborne  writes:

> Am I missing something obvious here or do I just have to use the cl
> functions in C to access elements of what is essentially lisp’s
> simplest data type?

You wouldn't want random C code to fuck with your data structures, would
you?

Don't write C code!

-- 
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


--
___
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list


Re: [Ecls-list] Accessing cons values in C

2015-07-29 Thread Chris Osborne
Well, I can understand the sentiment, but whilst I said C, it’s actually modern 
C++ which is approaching lisp with every new standard IMO. I’m using ECL in an 
*extremely* overkill capacity to to act as “smart” config files and to run a 
simple REPL for the user to play around with configuring the application’s 
output how they want (rather than being yet another application that defines a 
new language lacking in logic for its interactive interface), thus all major 
computations are passed back to C++, so I’d rather be able to rapidly traverse 
the trees to extract the commands input by the user.

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).

Cheers!

> On 30 Jul 2015, at 00:11, Pascal J. Bourguignon  
> wrote:
> 
> Chris Osborne  writes:
> 
>> Am I missing something obvious here or do I just have to use the cl
>> functions in C to access elements of what is essentially lisp’s
>> simplest data type?
> 
> You wouldn't want random C code to fuck with your data structures, would
> you?
> 
> Don't write C code!
> 
> -- 
> __Pascal Bourguignon__ http://www.informatimago.com/
> “The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
> 
> 
> --
> ___
> Ecls-list mailing list
> Ecls-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list


--
___
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list


Re: [Ecls-list] Accessing cons values in C

2015-07-29 Thread Nils Bruin

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--
___
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list