ferret icon indicating copy to clipboard operation
ferret copied to clipboard

REPL in ferret

Open arichiardi opened this issue 8 years ago • 7 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!).

arichiardi avatar Jan 15 '18 18:01 arichiardi

a very nice feature ,support

mxx avatar Apr 12 '18 10:04 mxx

Any updates on the REPL?

divs1210 avatar Jun 03 '18 03:06 divs1210

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.

nakkaya avatar Aug 02 '18 09:08 nakkaya

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

nakkaya avatar Aug 07 '18 22:08 nakkaya

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.

[1] https://root.cern.ch/download/cling/

nakkaya avatar Aug 07 '18 23:08 nakkaya

Looks like we will need stuff like var bindings and defonce.

divs1210 avatar Aug 10 '18 08:08 divs1210

Another example to consider is Dale. This is a Lisp that targets C and has a REPL. https://github.com/tomhrr/dale

asimjalis avatar Sep 20 '18 16:09 asimjalis