Prev: Why Perl is better than Lisp
Next: Which is the best implementation of LISP family of languagesfor real world programming ?
From: bolega on 12 Jun 2010 15:08 Here is a link to a thread that discusses this topic but there is no complete example. http://objectmix.com/lisp/362409-howto-use-lisp-scripting-language-within-c.html Lars Lune has a good section on code by searching this string "On Tue, 18 Mar 2008 01:16:00 -0700, Blackguester wrote:" but his code is replaced with smileys and even source shows it. I could not muster the confidence as a newbie to go into it by myself. Unless a guru can guide and explain. http://common-lisp.net/project/cffi/ http://common-lisp.net/project/cffi/manual/html_node/Tutorial.html http://www.sbcl.org/manual/Foreign-Function-Interface.html Should I pick SBCL or ECL ? I have a long term view.
From: Tamas K Papp on 12 Jun 2010 15:42 On Sat, 12 Jun 2010 12:08:17 -0700, bolega wrote: > Here is a link to a thread that discusses this topic but there is no > complete example. > > http://objectmix.com/lisp/362409-howto-use-lisp-scripting-language- within-c.html > > Lars Lune has a good section on code by searching this string > > "On Tue, 18 Mar 2008 01:16:00 -0700, Blackguester wrote:" > > but his code is replaced with smileys and even source shows it. I could > not muster the confidence as a newbie to go into it by myself. Unless a > guru can guide and explain. > > http://common-lisp.net/project/cffi/ > http://common-lisp.net/project/cffi/manual/html_node/Tutorial.html > http://www.sbcl.org/manual/Foreign-Function-Interface.html > > Should I pick SBCL or ECL ? I have a long term view. Even though the two issues are related, I would treat them separately. Calling C functions from CL is best done using CFFI. This library provides a unified, portable interface across different implementations. It will not require that you commit yourself to either one. The CFFI manual has a step-by-step tutorial, and CFFI has a mailing list where nice people will answer your questions. For embedding, I would go for ECL. See their FAQ (Section 2) and reference manual. What is it precisely that you are trying to do? Also, why are you cross-posting to so many different newsgroups? Please familiarize yourself with usenet netiquette, otherwise you might end up on ignore lists very quickly. Tamas
From: bolega on 12 Jun 2010 15:50 On Jun 12, 12:08 pm, bolega <gnuist...(a)gmail.com> wrote: > Here is a link to a thread that discusses this topic but there is no > complete example. > > http://objectmix.com/lisp/362409-howto-use-lisp-scripting-language-wi... > > Lars Lune has a good section on code by searching this string > > "On Tue, 18 Mar 2008 01:16:00 -0700, Blackguester wrote:" > > but his code is replaced with smileys and even source shows it. I > could not muster the confidence as a newbie to go into it by myself. > Unless a guru can guide and explain. > > http://common-lisp.net/project/cffi/http://common-lisp.net/project/cffi/manual/html_node/Tutorial.htmlhttp://www.sbcl.org/manual/Foreign-Function-Interface.html > > Should I pick SBCL or ECL ? I have a long term view. http://www.sbcl.org/manual/Calling-Lisp-From-C.html#Calling-Lisp-From-C 8.7.4 Calling Lisp From C Calling Lisp functions from C is sometimes possible, but is extremely hackish and poorly supported as of SBCL 0.7.5. See funcall0 ... funcall3 in the runtime system. The arguments must be valid SBCL object descriptors (so that e.g. fixnums must be left-shifted by 2.) As of SBCL 0.7.5, the format of object descriptors is documented only by the source code and, in parts, by the old CMUCL INTERNALS documentation. Note that the garbage collector moves objects, and won't be able to fix up any references in C variables. There are three mechanisms for coping with this: 1. The sb-ext:purify moves all live Lisp data into static or read- only areas such that it will never be moved (or freed) again in the life of the Lisp session 2. sb-sys:with-pinned-objects is a macro which arranges for some set of objects to be pinned in memory for the dynamic extent of its body forms. On ports which use the generational garbage collector (as of SBCL 0.8.3, only the x86) this has a page granularity - i.e. the entire 4k page or pages containing the objects will be locked down. On other ports it is implemented by turning off GC for the duration (so could be said to have a whole-world granularity). 3. Disable GC, using the without-gcing macro. [Q] How easy is it to call ECL http://sourceforge.net/projects/ecls/ from C ? Any toy example of doing this ? what type of problem set would advise us that we embed C in LISP and where lisp in C ? Some toy examples ? send me email if you will share thru private correspondance only.
From: Pascal J. Bourguignon on 12 Jun 2010 16:10 bolega <gnuist006(a)gmail.com> writes: > Here is a link to a thread that discusses this topic but there is no > complete example. > > http://objectmix.com/lisp/362409-howto-use-lisp-scripting-language-within-c.html > > Lars Lune has a good section on code by searching this string > > "On Tue, 18 Mar 2008 01:16:00 -0700, Blackguester wrote:" > > but his code is replaced with smileys and even source shows it. I > could not muster the confidence as a newbie to go into it by myself. > Unless a guru can guide and explain. > > http://common-lisp.net/project/cffi/ > http://common-lisp.net/project/cffi/manual/html_node/Tutorial.html > http://www.sbcl.org/manual/Foreign-Function-Interface.html > > Should I pick SBCL or ECL ? I have a long term view. In the long term, we're all dead. The point of a STANDARD, is that you can write programs that will work equally on any implementation. You are not asking yourself whether in the long term, you should buy today an Intel or an AMD process. That's because in the long term, it doesn't matter since they both implement the same stadanrd virtual machine. Guess what? It's the same for all the CL implementations: they all implement the same virtual machine! The portable Common Lisp Virtual Machine. So just write your program in portable Common Lisp, and in the long term they will run on any CL implementation. Actually, in the long term you could even use some extensions or divergent Lisp stuff, since it's Lisp, it's easy to write compatibility layers. For example, here is how you could in the long term run code written 50 years ago, today in any Common Lisp implementation: http://www.informatimago.com/develop/lisp/small-cl-pgms/wang.html That is, homoiconicity and easy meta-programming is essential to long term perenity of code. Now if your problem is to mix C code and Lisp code, the only question you may have to ask yourself is in what language the entry point will be written. If in Lisp, you can use any CL implementation that has FFI (or CFFI for the portability), and call any C code put in a library. If in C, then you will have to use ECL, which can be used embedded in a C program as a C library. Frankly, this is really a question of no relevance, since you can always s/int main/extern int my_application_main/ in your C sources and link it into a library instead of a program, to be loaded in SBCL or any other CL. Perhaps you could start to learn a use Common Lisp, so that you would provide us with more interesting questions? -- __Pascal Bourguignon__ http://www.informatimago.com/
From: bolega on 12 Jun 2010 16:47
On Jun 12, 1:10 pm, p...(a)informatimago.com (Pascal J. Bourguignon) wrote: > Now if your problem is to mix C code and Lisp code, the only question > you may have to ask yourself is in what language the entry point will > be written. > > If in Lisp, you can use any CL implementation that has FFI (or CFFI > for the portability), and call any C code put in a library. > > If in C, then you will have to use ECL, which can be used embedded in > a C program as a C library. > > Frankly, this is really a question of no relevance, since you can > always s/int main/extern int my_application_main/ in your C sources > and link it into a library instead of a program, to be loaded in SBCL > or any other CL. > > Perhaps you could start to learn a use Common Lisp, so that you would > provide us with more interesting questions? Thats why I was asking for a toy example from someone who has done it. I can download the programs ECL and Allegro. One toy example of each paradigm, including the third one of the libraries you mention. Most likely, it would be including some C/Python library for efficiency and availability and reuse in Lisp code to avoid rewrite. |