Example for using the REPL?

87 views
Skip to first unread message

Axel Katerbau

unread,
Jun 14, 2014, 11:03:14 AM6/14/14
to clojure-ob...@googlegroups.com
Hi!

I saw that the REPL is working now. I'm very exited. Is there an example for how to use it? Can't wait... :-)

- Axel

Gal Dolber

unread,
Jun 14, 2014, 12:46:35 PM6/14/14
to Axel Katerbau, clojure-ob...@googlegroups.com
Hi Alex,

It's still very alpha, but here is how to use it:

1) Start a REPL on the JVM. Call (remote-repl)

2) On your xcode project startup clojure and connect to the remote repl:

#import "ReplClient.h"

#import "clojure/lang/ObjC.h"

....

        [ClojureLangObjC setObjC];

        [ClojureLangRT load__WithNSString:@"clojure/core"];

        [ReplClient connect:@"localhost"]; // Localhost for the simulator, your IP if you're running on a device

3) Do stuff

Here's how it works: 

Everything runs on the JVM, less when you call an objc interop function. That's sent to the objc runtime and executed there. There's a remote references system that allows objc to handle jvm instances and backwards. The tricky part was that when you call an objc selector, I need to do a synchronous call, and all UI selectors have to run on the main thread, so it's really easy to get into permanent blocks.

Right now I'm using dispatch_async to run the calls on the main thread without blocking the socket, and that adds a delay to every call, making the whole thing very slow. The new design uses 2 sockets and a sync dispatch, it should be many times faster.

The other problem I need to fix is memory usage. The ObjC side of the REPL is not releasing any memory for remote references now, but thats not something hard to fix.

The REPL is the last thing stopping the next release. The project is much more stable, my startup goes live next week with 2 iOS apps fully written in clojure :)



--
You received this message because you are subscribed to the Google Groups "clojure-objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-objc-dis...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages