On Sat, Dec 8, 2012 at 7:27 PM, Peter Keller <psil...@cs.wisc.edu> wrote:
>
> Is what I'm doing really off base?
>
First, I am not sure whether you really need to translate objects, or
whether you can simply live with the pointers around. If you look at ECL's
FFI, it provides the lisp world with means to access the values in a C
structure, to allocate structures, to modify them and even to call C
functions. This code can be used also in C (arbitrary lisp code can be
evaluated in C as discussed before), so I really do not see why you would
go all the hassle to create lisp structures.
Second, do not use functions prefixed with si_ if you can, for they are
private and to be used by ECL's core library. The exception are those which
carry the si_ prefix but actually denote funcitons that belong to the EXT
package, such as si_safe_eval().
More generally, do not use anything which is not part of the ANSI
Specification. Every function and facility in Common Lisp has an equivalent
form in the C library, learn to use them. If Common Lisp programmers are
happy with what it provides, why should you embedding ECL need anything
else? Of course, in this case you need not restrict yourself to the cl_*
functions, but sometimes also use the ecl_* prefixed ones, which are
usually faster.
Say for instance you need to create structures with two slots
* Evaluate a "(defstruct foo a b)" form at the outer part of your code
(c_string_to_object + cl_eval)
* Store global references to the symbols MAKE-FOO, :A and :B (this is safe,
for symbols in packages are not garbage collected)
* Define a simple C function that uses that symbol to invoke the structure
creation.
const char *defstruct_form = "(defstruct cl-user::foo a b)"
cl_object make_foo = ecl_read_from_cstring("cl-user::make-foo");
cl_object keyword_a = ecl_make_keyword("A");
cl_object keyword_a = ecl_make_keyword("B");
cl_object make_foo(int a, const char *b)
{
return cl_funcall(5, make_foo, keyword_a, ecl_make_fixnum(a), keyword_b,
ecl_make_constant_base_string(b, strlen(b)));
}
int main () {
...
cl_eval(1,ecl_read_from_cstring(defstruct_form));
...
}
I'm willing to write some tutorials or edit the manual and add this
> kind knowledge wherever you'd like.
That would be very much appreciated. There is a lot of information in the
manual, but it can be improved.
Juanjo
--
Instituto de FĂsica Fundamental, CSIC
c/ Serrano, 113b, Madrid 28006 (Spain)
http://juanjose.garciaripoll.googlepages.com
------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Ecls-list mailing list
Ecls-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ecls-list