[ANN] clojure-scheme - Compiling Clojure to Scheme to C

1,156 views
Skip to first unread message

Nathan Sorenson

unread,
Mar 14, 2012, 5:08:02 PM3/14/12
to clo...@googlegroups.com
I've modified the output of the ClojureScript compiler to emit Scheme code. At this point the core library is successfully compiled by Gambit Scheme. A nice advantage of this is that Gambit compiles code via C, meaning that stand-alone Clojure executables are now available for any platform with a suitable gcc compiler!

Gambit, notably, also compiles to iOS. Just recently I've confirmed that Clojure's core library runs on the iPad simulator.

There is a ton of yak-shaving required at this point---compilation consists of a combination of shell commands, Clojure-interpreted commands and Gambit-interpreted commands. Hopefully this will soon be streamlined.

https://github.com/takeoutweight/clojure-scheme

David Nolen

unread,
Mar 14, 2012, 5:08:59 PM3/14/12
to clo...@googlegroups.com
Excellent work!


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Herwig Hochleitner

unread,
Mar 14, 2012, 9:04:34 PM3/14/12
to clo...@googlegroups.com
That's mighty!

Chip Collier

unread,
Mar 14, 2012, 6:53:55 PM3/14/12
to clo...@googlegroups.com
Holy excellent development Batman!

signature.asc

Ambrose Bonnaire-Sergeant

unread,
Mar 15, 2012, 10:13:40 PM3/15/12
to clo...@googlegroups.com
Wow, nice work Nathan!

Ambrose


--

Paulo Pinto

unread,
Mar 18, 2012, 8:28:03 AM3/18/12
to Clojure
Great work!

Just a question, why Clojure->Scheme->C, instead of Clojure->Clozure?

That way there would no be any C compiler dependency.

--
Paulo

Nathan Sorenson

unread,
Mar 21, 2012, 3:46:13 AM3/21/12
to clo...@googlegroups.com
I see the C code generation as an advantage, in that it becomes possible to target any platform with a C compiler.

Can Clozure compile to iOS?

Patrick Logan

unread,
Mar 22, 2012, 5:19:20 PM3/22/12
to clo...@googlegroups.com
Gambit Scheme especially has a great interface to C/C++/Objective-C. I've been happily using Gambit quite a bit for 20+ years, when it originated as gambit-68k for the Motorola 68000.

Gambit-C's been ported to iOS, Nintendo DS, etc.

In addition to the great C interface, it also has a great Unix/Posix interface, a great threads and message passing library (in the neighborhood of Erlang's performance for numbers of threads and messages per second), etc. It comes with Termite which is an Erlang-like programming model with mobile continuations.

So porting to Gambit provides some good avenues to explore.

-Patrick

Devin Walters

unread,
Mar 26, 2012, 5:19:55 PM3/26/12
to clo...@googlegroups.com
I've been itching to try this out. I pulled down the repo, grabbed gambit-scheme, and started to look around, but I'm a little lost as to how I can get it working. Could you provide the magic required to make one pass from cljs to scm to c? I would be happy to contribute to the project, but I'm in need of a bit of hand-holding to get started.

Thanks in advance,
'(Devin Walters)

--

Nathan Sorenson

unread,
Mar 28, 2012, 2:41:39 AM3/28/12
to clo...@googlegroups.com
ClojureScript has plenty of sharp edges, and this project is a bit rougher than even ClojureScript at the moment so you'll have to pardon the mess.

The magic happens in the cljs.compiler namespace. Load up a clojure repl and do something along the lines of:

(do (require 'cljs.compiler) (require 'cljs.core) (in-ns 'cljs.compiler) )

after that, you'll be able to compile .cljs files to .scm files via (compile-file "/Users/nathansorenson/src/c-clojure/src/cljs/cljs/core.cljs")

Note how I'm having to be real obvious about the filename right now. You should get an .scm file in the same directory. At that point you can compile it to an .o file with gambit, or just load it in the interpreter to play with

$ gsc
gsc-repl> (load "core.scm" ;interpreted

$ gsc core.scm   ;outputs core.o
gsc-repl> (load "core") ; loads the compiled .o

Dry Jin

unread,
May 24, 2014, 11:01:08 AM5/24/14
to clo...@googlegroups.com
Great work! Many thanks.

Dry Jin

unread,
Jul 9, 2014, 6:07:22 AM7/9/14
to clo...@googlegroups.com
By the way, how does Clojure-Scheme hand the Clojures's libraries over to Gambit-C?

2012년 3월 15일 목요일 오전 6시 8분 2초 UTC+9, Nathan Sorenson 님의 말:
Reply all
Reply to author
Forward
0 new messages