is it possible to convert LISP to C?

F

FSX

Hello everyone,

I would like to convert some Common LISP into C language. Is there a
consolidated way to do that?
I am not an experienced programmer in both languages, but I know more C
than LISP.
Thanks in advance

FSX

Posted using www.webuse.net
 
G

Guest

I would like to convert some Common LISP into C language. Is there a
consolidated way to do that?

well in theory, yes you can convert Lisp to C but it may be pretty
hard in some places. You may be better off asking in comp.lang.lisp
(I've x-posted it there). The first thing they may ask is "why do
you want to do this?". I think (but am not sure) there are Lisp->C
compilers. I doubt the resulting C is very readable tho'
I am not an experienced programmer in both languages, but I know more C
than LISP.


--
Nick Keighley

Meanwhile Steele famously claims Java is halfway to Lisp.
Perhaps he meant starting from the stone axe?
-- Ken Tilton
 
S

Spiros Bousbouras

Hello everyone,

I would like to convert some Common LISP into C language. Is there a
consolidated way to do that?
I am not an experienced programmer in both languages, but I know more C
than LISP.
Thanks in advance

You'll have more luck asking this on comp.lang.lisp
rather than comp.lang.c Therefore crossposting
and setting follow-ups for the former.
 
P

Piotr Chamera

(e-mail address removed) pisze:
You can look at ECL, it is Common Lisp implementation
which compiles to C as intermediate step in compilation.
 
G

Gene

(e-mail address removed) pisze:


You can look at ECL, it is Common Lisp implementation
which compiles to C as intermediate step in compilation.

Also GNU Common Lisp.
 
M

Mark Tarver

well in theory, yes you can convert Lisp to C but it may be pretty
hard in some places. You may be better off asking in comp.lang.lisp
(I've x-posted it there). The first thing they may ask is "why do
you want to do this?". I think (but am not sure) there are Lisp->C
compilers. I doubt the resulting C is very readable tho'


--
Nick Keighley

 Meanwhile Steele famously claims Java is halfway to Lisp.
 Perhaps he meant starting from the stone axe?
        -- Ken Tilton

Look at CLiCC: http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/impl/clicc/0.html

I've never used this btw.

Mark
 
F

Francogrex

(e-mail address removed) pisze:


You can look at ECL, it is Common Lisp implementation
which compiles to C as intermediate step in compilation.

True, but forget about having a readable C code, you won't even have a
"standalone" C code (meaning you wouldn't be able to compile and run
on any PC, unless you have some lispy dll sand libraries to use)
 
C

Chun Tian (binghe)

True, but forget about having a readable C code, you won't even have a
"standalone" C code (meaning you wouldn't be able to compile and run
on any PC, unless you have some lispy dll sand libraries to use)

If there's still some people who remember it, the "Chestnut Lisp->C
translator" is the best here. It can translate ANSI Common Lisp
(included CLOS) source code into human readable C code. However, these
translated C code would reference some CL functions which exist in a C-
based runtime (source code supplied). The Lisp->C translation progress
itself is all done by Common Lisp code (running in other modern CL
platform). Here is a trivial example:

(in-package :tcl-user)

(defun triangle (n)
(labels ((iter (i acc)
(if (zerop i) acc
(iter (1- i) (+ acc i)))))
(iter n 0)))

Translation results:

#include "user.h"
#include "triangle.h"


/* ITER */
static Object triangle_iter(i,acc)
Object i, acc;
{
Object temp = UNBOUND, temp_1;
Declare_stack_pointer;
Object result;

SAVE_STACK();
PROTECT_3(temp,acc,i);
if (zerop(i)) {
RESTORE_STACK();
return VALUES_1(acc);
}
else {
temp = sub1(i);
temp_1 = add(acc,i);
RESTORE_STACK();
return VALUES_1(triangle_iter(temp,temp_1));
}
}

/* TRIANGLE */
Object triangle(n_1)
Object n_1;
{
return VALUES_1(triangle_iter(n_1,FIX(0)));
}

void triangle_INIT()
{
Object Qtriangle;

SET_PACKAGE("TCL-USER");
Qtriangle = STATIC_SYMBOL("TRIANGLE",Pcl_user);
SET_SYMBOL_FUNCTION(Qtriangle,STATIC_FUNCTION(triangle,NIL,FALSE,
1,1));
}

The C version is readable, but not for manually maintain. It can be
compiled with other C source code in real applications. Unfortunately
it's not a public software any more. Oracle acquired it in 1995, and
several companies still have right to use it. For it's history, see
this post:

http://groups.google.com/group/comp.lang.lisp/browse_thread/thread/9d83095a6a644e86/b0f989d317d7eea5

I'm still in maintaining Chestnut (as part of a job in one of those
"several companies") and adding some modern features to it. Maybe
there will be one day it goes public again. You can just wait.

--binghe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top