Hacker News new | ask | show | jobs
by unclebunkers 4279 days ago
I'm a little unclear, does this hook into your code, or is it just a REPL? If it doesn't hook, what would be the use case for this?
4 comments

Well, it hooks into your code in the sense that you can expose classes and libraries to it.

One use is for C++ "scripts". Clang replaces the older "C interpreter CINT" in ROOT (which is mainly a data analysis framework for particle physics). CINT was horrible because it was "not quite C++", and encouraged bad behavior. You could swap . and -> for example; objects that were saved to a file you loaded appear automatically in scope (without prior assignment), templates were a bit iffy and so on. You could run many .cpp files as CINT scripts, but not the other way around. So current best practice is to avoid the"interpreter" and write proper programs that link to libROOT. Cling seems to be much more sane.

I don't know if you need something like that, but one thing Cling/CINT gives you is reflection/introspection, which is pretty neat. I think it's also somehow used to get generate bindings for other languages. Oh, and having a Repl is pretty nice. I use it e.g. for quick plots:

    $ root filename.root
    [0] tree->Draw("mass")
(where "tree" is a data structure automatically loaded from filename.root containing data points, and the command makes a histogram of "mass")
Great answer, thank you.
I can definitely see myself just using a simple REPL. I don't use C/C++ that often, so being able to start an interpreter and executing just of few line of code would be great. A use case would be checking the exception semantics of C++, or which element boost::bissect returns when you have several equal values.
I don't know what you mean by 'hook into', but I presume you can simply #include any existing source code.
I think that he's asking if you can do something like the 'debugger' statement in Chrome/FF when debugging JS.
Ah yes, that's a great idea!
If you're that much into hooking and stuff, LLDB is your tool. And it's also based on Clang, in pretty much the same way as Cling does.