Objective-C 的 REPL
Objective-C 有 REPL 吗?
我正在学习 Objective-C,并且非常缺少 REPL,因为我有 Python 背景。
Is there a REPL for Objective-C?
I am learning Objective-C and am sorely missing a REPL, coming from a Python background.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
F-Script 为 Cocoa 开发提供了受 Smalltalk 启发的 REPL,并且 Nu 提供了一个基于 Lisp 的。 F-Script 看起来更加精致,并提供了一个对象浏览器。
他们似乎都针对 OS X,而不是 iOS 开发。有零星的论坛和博客文章,其中有人描述使用 Nu 开发 iOS 应用程序,但它们似乎都是大约两年前的。还有一个 YouTube 视频“使用Scheme REPL 实时调试iPhone 应用程序”,其中包含一个使用Scheme 调试iPhone 应用程序的截屏视频。
我还没有尝试过任何这些技术,但我很想听听尝试过的人的意见。
我刚刚意识到这一切有一个更简单的答案。如果您来自 Python,并且想要在 REPL 中试验 Cocoa,那么您应该使用 Python REPL。 OS X 附带了一个从 Python 到 Objective-C 的桥梁。只需运行 Python,执行
import objc
即可。还有用于 Ruby 和 Common Lisp 等的桥梁。当然,所有这些 REPL 只允许您编写动态代码来与 Cocoa 交互,但它们不允许您编写实际的 Objective-C 代码,并即时解释或编译它以与其动态交互。所以没有一个能真正满足你最初的要求。
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.
当触发断点时,调试器应该弹出打开。在调试器中,您可以在 gdb 中输入您想要的任何内容。您可以使用
p [someObj someMethod]
打印断点范围内的内容。 gdb 是一个功能强大的实用程序,在网络上有详细的记录。这将是你最接近我认为你所追求的目标。这在编译语言中是一件比较笨拙的事情,因为 Objective-C 中没有任何
eval
。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.据我所知,目前最接近 REPL 的方法确实是通过调试器(即 GDB 或 LLVM 调试器 LLDB)。
对于纯 C,有 CCons。
Apple 的 Objective-C API(特别是 Foundation)中的大多数内容也有直接的 C 等效项(例如
CFRelease(obj);
与[obj release];
相同),这您可以在 CCons 中使用。CCons 构建在 LLVM 和 Clang 之上,它们也支持 Objective-C。或许可以扩展 CCon 来支持 Objective-C。
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.
CoderPad 的“试用”为包括 objc 在内的无数语言提供了面向公众的仅自我 REPL!我刚刚使用了它,这对他们来说确实是一个很好的销售工具(我没有隶属关系;他们为面试程序员的人制作工具)。 https://coderpad.io/
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/
在 Gambit Objective-C 项目中,似乎试图创建一个基于Scheme的REPL。
Ruby Motion 中的 REPL 也应该适合探索性目的(我自己还没有尝试过,尽管)。
In the Gambit Objective-C project there seems to be an attempt to create a Scheme based REPL.
The REPL in Ruby Motion is also supposed to be good for exploratory purposes (I haven't tried it myself, though).
是的,REPL 在输出窗口中。
“打印对象”
,但也执行作为应用程序代码运行的命令
阅读这个有趣的 完整的调试文章了解更多信息。
Yes, the REPL is in the output window.
"print object"
but also execute commands which are running as app code with
Read this interesting full debugging article for more information.