REPL in ferret
arichiardi opened this issue · comments
Hi!
I have discovered this project while looking for a way to build a parser targeting C, exposing therefore a C libray.
The plan I have read on HN about the REPL is to emit C++ directly to https://root.cern.ch/cling. Sounds nice. For me the REPL is the biggest (or maybe second, after persistent data structures) innovation Lisp introduced and I would love to have one in ferret
.
I cannot commit any time but I will look into it, any hint/update on this can go in this issue.
Thanks for working on this, it is super awesome (and the literate file is super!).
a very nice feature ,support
Any updates on the REPL?
I've been researching this. I've found a bunch of projects that promises a C++ REPL. But I did not have time to check them one by one and see which one would work best yet. I am gonna organize the links and dump it over here for reference.
C++ Interpreters
- cling - https://github.com/root-project/cling
- nbind - https://github.com/charto/nbind/blob/master/README.md
- Easy::jit - https://www.reddit.com/r/cpp/comments/8xyv3n/easyjit_justintime_compilation_for_c/
- https://github.com/RuntimeCompiledCPlusPlus/RuntimeCompiledCPlusPlus/wiki/Alternatives
- https://github.com/BitFunnel/NativeJIT
Notes on Cling
Prebuilt versions are available from [1]. Generated code is compatible. Ferret generated C++ code be loaded and called.
;;core.clj
(defn adder [x] (fn [y] (+ x y)))
Once compiled to C++ generated code can be loaded into cling
,
src/(master) $ cling
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$ .L core.cpp
[cling]$ using namespace ferret;
[cling]$ var fn = run(core::adder(), obj<number>(1));
[cling]$ var res = run(fn, obj<number>(5));
[cling]$ number::to<number_t>(res)
(int) 6
Only problem I've noticed so far is that you can not redifine vars.
Looks like we will need stuff like var bindings and defonce.
Another example to consider is Dale. This is a Lisp that targets C and has a REPL.
https://github.com/tomhrr/dale