Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!in1.uu.net!EU.net!peer-news.britain.eu.net!newsfeed.ed.ac.uk!edcogsci!jeff
From: jeff@cogsci.ed.ac.uk (Jeff Dalton)
Subject: Re: C -> Lisp
Message-ID: <DL4p47.79J.0.macbeth@cogsci.ed.ac.uk>
Organization: Centre for Cognitive Science, Edinburgh, UK
References: <19960111T202920Z@arcana.naggum.no> <4d61kh$tj@camelot.ccs.neu.edu> <4d646o$gfr@nz12.rz.uni-karlsruhe.de>
Date: Sat, 13 Jan 1996 16:43:19 GMT
Lines: 62

In article <4d646o$gfr@nz12.rz.uni-karlsruhe.de> vhansen@ipfy.bau-verm.uni-karlsruhe.de (Wolfgang von Hansen) writes:
>I just had a look at the FAQ. Some implementations of Lisp convert the Lisp
>source into a C source for compilation.
>
>Are there programs that do the reverse (translating an arbitrary C source
>into a set of Lisp functions)? If not, what is the main reason against such
>a program?

To answer this, it's necessary to consider two cases.

Lisp-to-C compilers use C as a kind of portable assembly language.
Rather than compile to native code, they compile to C and let the C
compiler worry about the native code.  The C code they emit might
be somewhat readable, but you wouldn't want to treat it as a C
program that you could develop and modify in C.  It may use
different calling conventions than C (passing args on a different
stack), and it tends to be full of low-level, rather cryptic-looking
stuff.

You don't see C-to-Lisp compilers of this sort, because C is
generally lower-level than Lisp and because on most machines C
compilers are available before Lisp compilers.  It might make
sense for a C compiler on a Lisp machine to compile to Lisp.
I don't know whether any actual Lisp machine C compiler worked
that way.

The other case is what's usually called a Lisp-to-C "translator".
Such systems may try to produce C that you could then treat as an
ordinary C program.  The code will tend to be more readable, at least.
So if you wanted to move your development work from Lisp to C, this
might be one way to get started.  Lisp-to-C translators may also try
to let you combine Lisp and C more easily.  (For instance, you usually
have to load compiled C into a Lisp system to use Lisp and C together,
rather than just link together Lisp and C object files.  A translator
might aim for the "link together" case.)

Both of the reasons against C-to-Lisp compilers also apply here.
For instance, C often works with pointers, which aren't easily
expressed in Lisp; and C expresses type information in more
cases than Lisp.  So writing a good translator might be difficult.
You'd probably have to choose between natural-looking Lisp that
was less efficient than the C version and C-like Lisp that was
cluttered with low-level stuff.

Now, the compiler case depends almost entirely on practical
issues.  Lisp implementors may want to take advantage of C
compilers that already exist; C implementors generally aren't
in that position.  The translator case adds another element.
Lisp is seen as maybe good for development but poor for
delivery.  So, for that and other reasons, moving from Lisp
to C is more popular than moving from C to Lisp.

However, there aren't many Lisp-to-C translators, so far as I know.  
There are more (though still not very many) Lisp-to-C compilers.
So we should be careful about drawing strong conclusions.

Still, there are programs that translate at least some C 
data structure definitions into Lisp or into something
Lisp-implementation-specific that lets C objects be 
manipulated from Lisp.

-- jeff
