nakkaya / ferret

Ferret is a free software lisp implementation for real time embedded control systems.
https://ferret-lang.org
BSD 2-Clause "Simplified" License
1.08k stars 48 forks source link

REPL in ferret #13

Open arichiardi opened 6 years ago

arichiardi commented 6 years ago

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!).

mxx commented 6 years ago

a very nice feature ,support

divs1210 commented 6 years ago

Any updates on the REPL?

nakkaya commented 6 years ago

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 commented 6 years ago

C++ Interpreters

nakkaya commented 6 years ago

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/

divs1210 commented 6 years ago

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

asimjalis commented 6 years ago

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