News for hackers. Stuff that matters.

Ask YC: Lisp Compiler

I know Lisp is interpreted (and this is one of its greatest advantages with its eval loop and all it brings), but is there any tool to compile Lisp code? Or to translate it into C++ code to be compiled with a C++ compiler?
( 12 comments | 12 points | on HN )
Re:Ask YC: Lisp Compiler by brlewis on Thursday April 24, 2008 @09:14AM (#172420)
You're confusing "interpreted" and "interactive." A read-eval-print loop can work by compiling the expressions you type in and executing the compiled code.
Re:Ask YC: Lisp Compiler by maw on Thursday April 24, 2008 @08:57AM (#172411)
What you know is wrong. Some lisps are interpreted, some are compiled. SBCL is one of the compiled ones.

If you're interested in scheme, bigloo is an option; there are surely others.

Re:Ask YC: Lisp Compiler by gibsonf1 on Thursday April 24, 2008 @08:45AM (#172406)
Hmm, part of the magic of Lisp comes from compiling the macros. Both Lispworks and SBCL compile Lisp code, and I think SBCL effectively only operates in compiled mode and is very fast. I would guess that most other Lisps compile as well. Being compiled is why Lisp clocks in at speeds roughly the same as C or faster in many cases.
Re:Ask YC: Lisp Compiler by dpapathanasiou on Thursday April 24, 2008 @09:31AM (#172431)
Being compiled is why Lisp clocks in at speeds roughly the same as C or faster in many cases.

While we're on that subject, take a look at "How to make Lisp go faster than C" (http://www.lrde.epita.fr/~didier/research/verna.06.imecs.pdf)

Re:Ask YC: Lisp Compiler by mnemonicsloth on Thursday April 24, 2008 @09:47AM (#172445)
Many (most?) Schemes are compiled.

Chicken Scheme (my favorite) is 'just' an efficient Scheme-to-C compiler, with some optimizations for the "interpreter".

Also, there's Stalin, which is one of the most powerful compilers around, in any language. Wikipedia claims that it usually outperforms hand-coded C (which isn't that hard, since C does arrays with pointers and nothing else), sometimes by a lot.

There's also Bigloo (which is French and unknown to me), and Gambit, and a whole bunch of Scheme-to-Java compilers as well.

Also, I know Scheme48 and PLT Scheme both have compilers, but I don't know much about them. Chicken is so much more hackable.

http://callcc.org

Re:Ask YC: Lisp Compiler by apgwoz on Thursday April 24, 2008 @03:04PM (#172749)
Scheme48 doesn't have a traditional compiler, but does allow you to create bytecode images, that will run in the virtual machine.
Re:Ask YC: Lisp Compiler by apgwoz on Thursday April 24, 2008 @09:45AM (#172444)
Isn't a compiler a required part according to the Common Lisp spec? I'm more of a Scheme guy, so I don't know all 500 pages of the CL doctrine, but I think I remember that...

http://en.wikipedia.org/wiki/Category:Scheme_compilers has a list of Scheme compilers, if you're into that side of things.

Re:Ask YC: Lisp Compiler by watmough on Thursday April 24, 2008 @01:26PM (#172658)
Clojure is a Lisp that compiles to JVM byte-code as you type in to a REPL, or load-file.

Clojure is oriented towards functional style programming and concurrency.

Compiled code uses some reflection under the covers, but most of this can be eliminated by type hinting, which gets you into the ball park with Java.

Re:Ask YC: Lisp Compiler by dpapathanasiou on Thursday April 24, 2008 @09:12AM (#172418)
CMUCL and CLISP both come with compilers; CLISP also has an option to build native executables in addition to bytecode.
Re:Ask YC: Lisp Compiler by tjr on Thursday April 24, 2008 @09:48AM (#172446)
LispWorks can build executables.
Re:Ask YC: Lisp Compiler by Emmjaykay on Thursday April 24, 2008 @11:03PM (#173196)
Like, kernels?
Re:Ask YC: Lisp Compiler by lst on Thursday April 24, 2008 @09:27AM (#172430)
Look at ECL (http://ecls.sourceforge.net/), it compiles to C and can be embedded.