MarsHut Page 1/4

quarterceladonΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 8 μήνες)

56 εμφανίσεις

Clojure on top of ObjC?
Asked by
Steven Degutis
on 2013-04-23T15:38:12-04:00
Currently Clojure exists on the JVM, the CLR, and the JSVM.

Why not put it on top of ObjC too?

Then we could create stand-alone executables written in Clojure! Or it
could be used as an embedded scripting language. The ObjC runtime and
Foundation.framework are close enough to Java that it shouldn't be too
hard to port.

Rather than compiling to bytecode, it would be interpreted at runtime
(like Python/Ruby). All dynamic class/method lookups and such would
have to be done via
and libffi.

And there's the obvious downside that this would really only be
beneficial for Mac OS X users (or people willing to put up with
GNUStep). But there are plenty of us to make this worth it.

What do you all think of this specific idea?

I'm willing to work on such a project in my spare time, since I have a
fair bit of knowledge about the ObjC runtime. But I have to admit I'm
not a Clojure expert, so it would be helpful if more Clojure people
were interested in helping out with such a project.

Note: I've already looked into running ClojureScript via JS inside
JSCocoa, it's not feasible for many reasons that are out of the scope
of this topic; this post is specifically about porting Clojure to
ObjC.

-Steven
Archives
Programming
Clojure
Apr 23, 2013
Week 17, 2013
April, 2013
Year 2013
All Answers
Answer by
Gary Trakhman
on 2013-04-23T15:50:55-04:00
It's already possible via https://github.com/takeoutweight/clojure-scheme

Gambit scheme provides objective-C interop. The author demonstrated this
stuff at Clojure/West this year. One difference between your proposed
approach is it's both compiled and highly optimized.
MarsHut
Page 1/4
Clojure on top of ObjC?
Answer by
Steven Degutis
on 2013-04-23T16:24:14-04:00
It would be neat, if only I could figure out how to use it. Thanks though.

-Steven
Answer by
Steven Degutis
on 2013-04-23T16:26:05-04:00
Never mind, count me dumb. Just forgot to do ./script/bootstrap
Answer by
Steven Degutis
on 2013-04-23T16:37:59-04:00
While this is certainly neat, it doesn't allow Clojure to be used as
an embedded scripting language inside an ObjC app.
Answer by
Andy Fingerhut
on 2013-04-23T16:38:44-04:00
There may be more relevant or up-to-date links, but do a Google search for
"clojure objective c", and you will see this has been discussed a little
bit in this group:

https://groups.google.com/forum/?fromgroups=#!topic/clojure/6i9D5QOq7Cc

Also, one person started a couple of projects on Github, one written in
Haskell, then rewrote in Clojure, called objective-clojure:

https://github.com/jspahrsummers/objective-clojure

Andy
Answer by
Gary Trakhman
on 2013-04-23T16:57:58-04:00
There's lots of ways to 'eval' a script. One way is to embed something
like LLVM, a compiler within the app, compile something, get back a
function pointer and run it. This is what Cloudera Impala does to run
real-time HiveQL queries.
http://blog.cloudera.com/blog/2013/02/inside-cloudera-impala-runtime-code-generation/

You could also implement a clojure interpreter, which sounds interesting,
too.

What's the best bang for the buck?
Answer by
Rich Morin
on 2013-04-23T17:39:33-04:00
+1

I'd be delighted to have such a port. It could extend Clojure's span to
include OSX (including OpenStep) and iOS (in a somewhat diminished form).
See below for some information on related efforts in Ruby.

-r

While at Apple, Laurent Sansonetti developed MacRuby, a open-source port
of Ruby that uses LLVM and runs on OSX. Like Clojure, MacRuby "embraces"
its platform (in this case, the Mac's OS, frameworks, and ObjC's runtime.
MarsHut
Page 2/4
Clojure on top of ObjC?
Conveniently, MacRuby also retains access to Rubyish resources (eg, Gems
and a wealth of Unixish commands, functions, and system calls).

I suspect that there is no really good way to map ObjC method names into
more conventional languages. MacRuby uses a parameter hash for this, so
parts of ObjC method names become hash keys.

Unlike JRuby, MacRuby makes no strong effort to make its code look like
idiomatic Ruby. However, the (related) HotCocoa project did some nifty
experimentation in this area.

MacRuby doesn't run on iOS, either. As I understand it, the main problem
is a lack of memory management. However, I'd also expect some Unixish
features to be missing.

So, Laurent has produced _another_ port of Ruby as a closed-source (though
inexpensive) effort. I haven't played with it (http://www.rubymotion.com),
but I'd expect RubyMotion to be very solid.

Because RubyMotion is closed source, you can't simply inspect the way that
Laurent solves similar problems. However, he gives talks regularly, chats
online, and may well be willing to explain how he solved specific issues.

Getting copies of MacRuby and/or RubyMotion might also be worthwhile as a
way to see how Laurent's decisions have worked out in practice. It might
also push you in the direction of interoperability. It's all good...

Software system design, development, and documentation
Answer by
Steven Degutis
on 2013-04-23T18:02:09-04:00
I have used MacRuby in the past with good success. I like its technique of
using ObjC as the underlying "VM", using pure ObjC objects.

Unfortunately, it's impractical to write the majority of a Mac or iOS app
using anything other than Xcode + ObjC, especially the UI. So the goal of
this endeavor would mainly be to write command line utilities in Clojure or
embed scripting capabilities into your app that understands Clojure.

-Steven
Answer by
Brian Marick
on 2013-04-24T03:10:03-04:00
I wrote a smallish but nontrivial commercial Mac app using mostly RubyCocoa (predecessor to
MacRuby) and emacs. It included things like a custom view, quick look, use of bindings, etc. I only
used Xcode/IB for building, creating new files, and GUI layout. I only had to drop out of Ruby to work
with the OSX crypto libraries (which only had a C interface).

This was three years ago, though.

Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo
MarsHut
Page 3/4
Clojure on top of ObjC?
Answer by
Steven Degutis
on 2013-04-24T06:49:19-04:00
I'm sure it can be done, but lately the auto-completion integration,
the Interface Builder integration, and all sorts of other things I
can't remember right now, are all so tightly integrated into Xcode
that I'm confident I would code at least half as quickly if I was in
emacs.

-Steven
Answer by
Nathan Sorenson
on 2013-05-06T01:15:34-04:00
Since the Clojure/West talk I've been busy trying to get clojure-scheme
self-hosted. I've been a week or so away from this working for a few weeks
now :) But Clojure macros, the analysis pass, and the compiler are all
self-hosted. There's a little bit more to do on the reader's interaction
with syntax-quote, but once that's done we should have a real Clojure repl
running on the iPhone.
Answer by
PublicFarley
on 2013-05-07T06:49:43-04:00
"...but once that's done we should have a real Clojure repl running on the iPhone."

Wow. This is awesome news Nathan.
Tagged
Clojure Exists
Clojure Expert
Clojure People
Dynamic Class
Embedded Scripting Language
Related
Clearley
Tips for a Clojure workshop, for people who don't use emacs?
LambdaNext Clojure Workshop - London May 20-22 2013
Hacker News, Clojure, and GSOC
Clojure Cup 2013
Learning resource
Clojure for Beginners eBook
ANN: ClojureScript release 0.0-1798
Meta-eX: Hacking Overtone on the Stubnitz - Thurs 16th May
Clojure generates unnecessary and slow type-checks
View Online
http://www.marshut.com/khryv/clojure-on-top-of-objc.html
MarsHut
Page 4/4