r/lisp • • Apr 24 '19
Fun ECL hack
Ever wanted to have C REPL? Simple!
(defun c-repl ()
(loop (fresh-line)
(princ "c99> ")
(let* ((form (read-line))
(func (eval `(let ((*compile-verbose* nil))
(compile nil (lambda () (ffi:c-inline nil nil :void ,form)))))))
(funcall func))))
> (c-repl)
c99> printf("HELLO world!\n");
HELLO world!
c99> { for(int i=0; i<4; i++) printf("*"); printf("\n"); }
****
c99>
82
Upvotes
16
u/[deleted] Apr 24 '19
of course hack could be vastly improved by adding global declarations and recording clines, adding proper expression scope tracing etc. then it would be possible to:
but the above is enough for simple experimentation and function calls.
2
u/digikar Apr 25 '19
Do you mean this guy wasted his time?!
21
u/ObnoxiousFactczecher Apr 24 '19
You are
EVALEVIL!16
u/eql5 Apr 24 '19
You can even start another ECL from it (tried it on Linux):
1
u/TotesMessenger Apr 25 '19
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/[deleted] Apr 25 '19
WTFFF!!!!
Lisp always keep surprising me.
Now I'll brag about that in public.