Francogrex <······@grex.org> writes:
> I'm using ECL a lot but have yet to see posted a comprehensive example
> on how to embed CL functions. I see bits and pieces but nothing
> complete from A to Z. Documentation is not the strongest point of this
> implementation (but sure everything else is, it's an awesome CL
> implementation). Say I have this horrible toy lisp function in file
> toy.lisp:
>
> (defun random-10 () (loop repeat 10 collect (random 1.0) into rndtemp
> finally (return (values (setf rnd rndtemp)))))
>
> and I want to refer to it from within this test.c:
>
> int main ()
> {
> ...
> bla bla bla;
> ...(random-10)...;
> bla bla;
> ...
> }
>
> How to do it and also how to compile it? (what gcc instructions and
> arguments need to be supplied? against which library it needs to be
> linked? on what is it dependent etc?) Either Linux or Win32. Thanks
The following is not tested, I gathered it from an old web page.
That's what I'd try first:
#include "ecl/ecl.h"
int main(int narg, char **argv)
{
cl_boot(narg, argv);
cl_object read_from_string = c_string_to_object("READ_FROM_STRING");
cl_object form=cl_list(2, read_from_string, MAKE_STRING("(random-10)"));
cl_eval(form);
return 0;
}
I'd try: gcc -o example example.c -lecl
to compile it.
--
__Pascal Bourguignon__
···@informatimago.com (Pascal J. Bourguignon) writes:
> Francogrex <······@grex.org> writes:
>
>> I'm using ECL a lot but have yet to see posted a comprehensive example
>> on how to embed CL functions. I see bits and pieces but nothing
>> complete from A to Z. Documentation is not the strongest point of this
>> implementation (but sure everything else is, it's an awesome CL
>> implementation). Say I have this horrible toy lisp function in file
>> toy.lisp:
>>
>> (defun random-10 () (loop repeat 10 collect (random 1.0) into rndtemp
>> finally (return (values (setf rnd rndtemp)))))
>>
>> and I want to refer to it from within this test.c:
>>
>> int main ()
>> {
>> ...
>> bla bla bla;
>> ...(random-10)...;
>> bla bla;
>> ...
>> }
>>
>> How to do it and also how to compile it? (what gcc instructions and
>> arguments need to be supplied? against which library it needs to be
>> linked? on what is it dependent etc?) Either Linux or Win32. Thanks
>
> The following is not tested, I gathered it from an old web page.
> That's what I'd try first:
And here is what works once debugged:
#include "ecl/ecl.h"
int main(int narg, char **argv)
{
cl_boot(narg, argv);
cl_object form=cl_list(2,
c_string_to_object("PRINT"),
cl_list(2,
c_string_to_object("READ-FROM-STRING"),
c_string_to_object("\"(a \\\"b\\\" #xc)\"")));
cl_eval(form);
cl_eval(cl_list(1,c_string_to_object("TERPRI")));
return 0;
}
/*
gcc -I/opt/local/include -I/opt/local/lib/ecl/ -L/opt/local/lib/ecl/ \
-o ecl-test ecl-test.c -lecl \
&& ./ecl-test
*/
(adjust the paths for your system). This program prints:
% ./ecl-test
(A "b" 12)
--
__Pascal Bourguignon__
On Feb 24, 1:33 am, Francogrex <······@grex.org> wrote:
> I don't think any element in this list can be used with C functions.
> For example would you be able to take the (nth 1 rnd) and do a C
> printf on it or use it in other C arithmetic operations? -like (nth 1
> rnd)+7 - I doesn'ty seem to be.
void randtest (int index) {
cl_object list;
list = cl_eval(READCL((loop repeat 10 collect (random 1.0))));
cl_print(1, list);
cl_terpri(0);
printf("random: %f\n", ecl_to_float(cl_nth(MAKE_FIXNUM(index),
list)));
}
Added to that ecl-examples repo.
Francogrex <······@grex.org> writes:
> On Feb 24, 10:35�am, ·······@gmail.com wrote:
>> void randtest (int index) {
>> � cl_object list;
>> � list = cl_eval(READCL((loop repeat 10 collect (random 1.0))));
>> � cl_print(1, list);
>> � cl_terpri(0);
>> � printf("random: %f\n", ecl_to_float(cl_nth(MAKE_FIXNUM(index),
>> list)));
>>
>> }
>
> May I ask where did you learn those, where did you get the
> information? Because on the ecl sourceforge site the current manual is
> very laconic with minimal details and it doesn't show satisfactory
> examples like those above?
Have a look at ecl.h and its brother files.
It may be installed in /usr/include/ecl/ecl.h
or /usr/lib/ecl/ecl/ecl.h
or somewhere else.
--
__Pascal Bourguignon__