Can Scheme and C Communicate? 
Author Message
 Can Scheme and C Communicate?

Hello out there.  I am trying to get a C program to call a Scheme
function which in turn needs to call a different C procedure.  The
results of these calls must be returned.  I am actually only writing the
Scheme code in the middle -- the C stuff is being written by a third
party.  If it were up to me, I'd rewrite the whole thing in Scheme, but
it's not up to me.  I am also restricted to MIT Scheme (ironically also
known as c-scheme).

Can anyone help me with this mess?  Please!

Thanks.

John Snider



Tue, 29 Sep 1998 03:00:00 GMT  
 Can Scheme and C Communicate?

   Hello out there.  I am trying to get a C program to call a Scheme
   function which in turn needs to call a different C procedure.  The
   results of these calls must be returned.  I am actually only writing the
   Scheme code in the middle -- the C stuff is being written by a third
   party.  If it were up to me, I'd rewrite the whole thing in Scheme, but
   it's not up to me.  I am also restricted to MIT Scheme (ironically also
   known as c-scheme).

   Can anyone help me with this mess?  Please!

The Bigloo compiler has an extended foreign interface. It allows
the call of C functions, the usage of C global variables from
Scheme and the call of Scheme functions, the usage of Scheme
global variables from C. In addition Scheme programs can
manipulate complexe C data structures (such as C structs, C
arrays, ...) from Scheme without the need of any hand-written
stubb code. Bigloo is available at:

ftp.inria.fr:/INRIA/Projects/icsla/Implementations/bigloo1.8.tar.gz

--Manuel Serrano--



Tue, 29 Sep 1998 03:00:00 GMT  
 Can Scheme and C Communicate?

:...I am trying to get a C program to call a Scheme function which in
: turn needs to call a different C procedure.  The results of these
: calls must be returned.
: ...snip...
: I am also restricted to MIT Scheme.....

I can't help you with the MIT Scheme part, but just to let you know
that what you ask for is possible.....

Our N!Power software has a built-in Scheme interpreter.  In addition
to normal interactive mode, with several GUI choices, there is a
"Server Mode", which provides an engine that runs as a background
process that your own client program talks to through sockets.
You can send it Scheme scripts and data.  It executes the scripts and
provides graphics and I/O support too.  It can send things back to
the client program.  In addition you can "bind" in your own code to
create new Scheme extensions, executable from the server, just like its
own native commands, thus they can be invoked by the client.

See  http://www.signal.com/~stilarry  for more info.

Larry Pfeifer                     !         N!POWER
Signal Technology, Inc.           ! Object oriented software
104 W. Anapamu St.                ! for signal analysis, data
Santa Barbara, CA  93101-3126     ! analysis, simulation, data
TEL: 805-899-8300 x350            ! acquisition, & visualization.
FAX: 805-899-4344                 ! Visual programming, C coding,



Tue, 29 Sep 1998 03:00:00 GMT  
 Can Scheme and C Communicate?

Quote:
> Hello out there.  I am trying to get a C program to call a Scheme
> function which in turn needs to call a different C procedure.  The
> results of these calls must be returned.  I am actually only writing the
> Scheme code in the middle -- the C stuff is being written by a third
> party.  If it were up to me, I'd rewrite the whole thing in Scheme, but
> it's not up to me.  I am also restricted to MIT Scheme (ironically also
> known as c-scheme).

> John Snider


John,

The way I understand it, The MIT-Scheme (c-scheme) implementation does
support back-end C code. Taken directly from the release notes section of
the MIT-scheme version 7.3 user manual,

   * The compiler produces C code that works in the context of the MIT
   Scheme runtime library.  It is not stand-alone code, and there is
   currently no way to generate stand-alone executables.

and

   * Support for dynamic loading of compiled C code on several operating
   systems, including HP-UX, OSF/1, SunOS 4, and AIX.

The person who pointed you at bigloo, I think, did not understand that you
are restriced to MIT-scheme. In any event, Scheme and C, in general, can
communicate, however, one must build an intelligent compiler to enable
this particular facility. What one of the longest threads on this
newsgroup has been is a discussion about a portable way to do this.

In addition, this may not solve your problem in full, or even in part. Are
you planning on running the entire program in a Scheme environment? So
that you need to call C code from within Scheme? Or are you hoping for a
stand-alone application? Answers to these question may necessitate
changing your interperter of choice.

Anyway, I hope that this information helps.

--brian



Fri, 02 Oct 1998 03:00:00 GMT  
 Can Scheme and C Communicate?

Quote:

>>> M. Moore) said:

jsnider> Hello out there.  I am trying to get a C program to call a
jsnider> Scheme function which in turn needs to call a different C
jsnider> procedure.  The results of these calls must be returned.  I am
jsnider> actually only writing the Scheme code in the middle -- the C
jsnider> stuff is being written by a third party.  If it were up to me,
jsnider> I'd rewrite the whole thing in Scheme, but it's not up to me.
jsnider> I am also restricted to MIT Scheme (ironically also known as
jsnider> c-scheme).

mooreb> The way I understand it, The MIT-Scheme (c-scheme)
mooreb> implementation does support back-end C code. Taken directly from
mooreb> the release notes section of the MIT-scheme version 7.3 user
mooreb> manual,

mooreb>    * The compiler produces C code that works in the context of the MIT
mooreb>    Scheme runtime library.  It is not stand-alone code, and there is
mooreb>    currently no way to generate stand-alone executables.

mooreb> and

mooreb>    * Support for dynamic loading of compiled C code on several
mooreb>      operating systems, including HP-UX, OSF/1, SunOS 4, and
mooreb>      AIX.

mooreb> The person who pointed you at bigloo, I think, did not
mooreb> understand that you are restriced to MIT-scheme.

Indeed. Apart from that there are smaller/leaner alternatives to bigloo,
such as SIOD.

mooreb> In addition, this may not solve your problem in full, or even in
mooreb> part. Are you planning on running the entire program in a Scheme
mooreb> environment? So that you need to call C code from within Scheme?
mooreb> Or are you hoping for a stand-alone application? Answers to
mooreb> these question may necessitate changing your interperter of
mooreb> choice.

From what I understand John wants a way to compile not just a Scheme
application, but a Scheme _object module_ that can be linked inside a C
application as an intermediate layer.

This is quite different from being able to call C inside a Scheme
workarea.

jsnider> Can anyone help me with this mess?  Please!

Shortly put, not really. CScheme is a sophisticated *environment*, and
you cannot really invoke a CScheme function from a program running
outside CScheme.

In effect _very few_ workarea-oriented languages have implementation
that allow you to invoke functions from another language. Only a few
more allow you to invoke functions written in another language.

The difficulty with what you want is that as stated by the CScheme
manual a CScheme objects comes with a requirement for the support of the
complete CScheme environment, which has been designed as a self
contained workarea system.

jsnider> Please!

Perhaps you could be content with a client-server model: the calling C
function sends a message, a standalone running CScheme system processes
it and send back another message.

Alternatively you could use another Scheme implementation, some of which
either produce C code that can be called from other C code, or like SIOD
can freely mingle with C code. Hey, there is even a common lisp
implementation that you could use, Embeddable Common Lisp (there is an
implementation of Scheme for Common Lisp).



Mon, 05 Oct 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. please unscribe dinh@cs.ucla.edu from the scheme mailing list

2. Wanted: references on using Scheme for Intro CS courses

3. to CS: or not to CS: in F-PC assembler

4. CA Cans VO ?

5. It's not bad canned meat...

6. It's not bad canned meat...

7. It's not bad canned meat...

8. Using CGI module with 'canned queries'

9. It's not bad canned meat...

10. still more on communicating APL

11. 32 bit ST communicating with 16 bit VB

12. Communicating between Smalltalk and EJBs in Websphere

 

 
Powered by phpBB® Forum Software