Robert Dodier wrote:
> On Mon, May 3, 2010 at 3:00 PM, Carter, Nathan <NCARTER at bentley.edu> wrote:
>
>> On May 3, 2010, at 4:09 PM, Richard Fateman wrote:
>>
>>
>>> Unless you are passing trivial data structures like small integers to
>>> maxima, how do you propose to encode arguments to lisp functions when you
>>> call a subroutine in maxima?
>>>
>> Well, since I'm asking a "how do I" question, I don't think I'm proposing anything. :)
>> So I guess I should read your reply as specifically addressing my
>> can-I-call-Maxima-as-a-library question, and you're essentially saying that
>> there is no API available for constructing LISP data structures in C/C++,
>> making the whole library idea impossible from the get-go.
>> Do I have that correct?
>>
>
> RJF may or may not be claiming that the library idea is impossible;
> it's probably not worth the trouble to figure out which.
>
I'm not claiming it is impossible; as I responded to Nathan Carter
directly, it definitely is possible, but it has to
be done for a particular lisp, and some lisps might not be helpful.
See for example, SWIG
http://www.swig.org/
> I glanced at the patches linked by Mike Hansen and it appears that
> the general approach is to construct Lisp objects in a C program
> (via ECL's C functions) and call Lisp functions on those objects.
>
If you are creating objects in C that are Lisp symbolic expressions
(cons cells, etc.) then it is rather difficult
to do so without the superstructure of the Lisp run-time memory
allocator etc. But it is entirely possible
to load up a whole lisp system and also some other code (maybe even
Nathan Carter's code) in the same address space,
which in my opinion is the right way to do things. It has not, notably,
been used in the Maxima
source code I think for two reasons: because GCL was not supportive of
it, and using such an interface
requires a level of uniformity amongst Common Lisps that has not
happened. I gather that UFFI supports
one direction of API, but maybe has not solved all the problem
The usual interface, useful but not as general, exchanges character
strings. I think this is what Sage has been
using, and probably is still using, and similarly for the more elaborate
Maxima front ends.
If you are interested in a particular lisp, you can certainly solve the
problem better than if you have to solve
the problem for all lisps.
I have used foreign functions calls from Lisp to code originally written
in C, Fortran, or Assembler. Having
a C function call BACK into Lisp is certainly supported in some
circumstances; indeed it is extremely widely
used as when an interactive graphics package calls a lisp routine to
handle a mouse button click, etc.
RJF