Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REPL for Objective-C

Tags:

Is there a REPL for Objective-C?

I am learning Objective-C and am sorely missing a REPL, coming from a Python background.

like image 549
agiliq Avatar asked Feb 02 '11 10:02

agiliq


People also ask

Can you use REPL as an IDE?

Repl.it is a free IDE (integrated development environment) that allows users to write their own programs and code in dozens of different languages.

Are REPL IT projects public?

By default, the repl will be public if the "privacy" switch is not set. You can toggle between "private" and "public" from inside a repl, as many times as you want, by clicking on the repl name in the top left of your screen.

Can REPL it be used offline?

Our most requested feature has come: an offline IDE!


4 Answers

F-Script provides a Smalltalk-inspired REPL for Cocoa development, and Nu provides a Lisp-based one. F-Script seems a bit more polished and offers an object browser.

They both seem to be targeting OS X, rather than iOS development. There are scattered forum and blog posts with people describing using Nu for developing iOS apps, but they all seem to be from about two years ago. There's also a YouTube video, "Using a Scheme REPL to debug iPhone apps real-time" with a screencast of a fellow using Scheme to debug an iPhone app.

I haven't experimented with any of these technologies, but I would love to hear from anyone who has.


I just realized there's a simpler answer to all this. If you're coming from Python, and want to experiment with Cocoa in a REPL, you should just use the Python REPL. OS X ships with a Python to Objective-C bridge. Just run Python, do import objc, and you're off. There are also bridges for Ruby and Common Lisp, among others.

Of course, all these REPLs only let you write dynamic code to interact with Cocoa, but they don't let you write actual Objective-C code, and interpret it or compile it on the fly to interact with it dynamically. So none truly meets your original requirement.

like image 134
algal Avatar answered Sep 21 '22 15:09

algal


When a breakpoint is triggered the debugger should pop open. When in the debugger, you can type whatever you want into gdb. You can use p [someObj someMethod] to print things out that are in scope to your breakpoint. gdb is a powerful utility well documented all over the web.

That's going to be as close as you get to what I think you are after. This is just a much clunkier thing to do in compiled languages, as there isn't any eval in Objective-C.

like image 34
Alex Wayne Avatar answered Sep 20 '22 15:09

Alex Wayne


As far as I know, the closest you can get to a REPL at the moment is indeed through debuggers (i.e. GDB or the LLVM debugger LLDB).

For pure C, there is CCons.

Most things in Apple's Objective-C APIs (particularly Foundation) also have direct C equivalents (e.g. CFRelease(obj); is the same as [obj release];), which you can use in CCons.

CCons is built on top of LLVM and Clang, which also support Objective-C. It is probably possible to extend CCons for to also support Objective-C.

like image 44
mrueg Avatar answered Sep 21 '22 15:09

mrueg


The 'trial' of CoderPad gives a public facing self-only REPL for zillions of languages including objc!!! I just used it and it's really a good sales tool for them (I'm not affiliated; they make tools for people interviewing coders). https://coderpad.io/

like image 21
AnneTheAgile Avatar answered Sep 20 '22 15:09

AnneTheAgile