It's not naive. This is called self-hosting and it is very common in
programming language implementation. To be safe one often retains a
stub compiler for some subset of the language written in another
language, and then implements the rest of the language in the stub
version. This is what GHC does for Haskell with Core and PyPy does
with RPython for Python (though GHC ultimately converts all Haskell
into core before compiling it). GCC works similarly, first building
xgcc which is a simple C compiler to compile itself, and then it
recompiles itself with itself, which is why it's such a time consuming
process.
Another approach is to go whole-hog and depend on a previous version
of the language to build the language. This is what CMU Common Lisp
has been doing (not sure if they've changed this recently or not). I
think Erlang is in a similar situation (the original host language was
Prolog, believe it or not).
Other languages retain a C or Java implementation forever. This is the
approach of the scripting languages, such as Python and Ruby et al.
There's nothing wrong with that either.
IMO, the principal advantages of self-hosting are that it forces you
to optimize in places you might not want to and that it gives you a
nice language to write your language in. :) It's also a good exercise
in general and it makes it easier for someone who only knows the
language the ability to work on the language.
—
Daniel Lyons
I just finished watching the Bay Area Clojure Meetup video, and Rich
spent a few minutes talking about the possibility of Clojure in
Clojure. The prospect of having Clojure self-hosted is incredibly
cool, but it brought a few questions to mind. For one, Rich mentions
that it would potentially open up additional target platforms for the
language citing Objective C, Actionscript, and Javascript as potential
host languages. As awesome as this sounds, wouldn't it first require a
native implementation to be created for each language prior to Clojure
in Clojure running on the platform? Perhaps there's some magic
bootstrapping stuff that can be done to avoid a full port? I'm also
wondering if Clojure would take a big performance hit as a result of
being self-hosted? Either way, this seems like a really neat idea.
I don't think Clojure will be abandoning the JVM any time
soon. There's not been a lot of specifics anywhere about
what Clojure-in-Clojure actually is, so I wrote up what
I think I know. I hope it helps:
--Chouser