Run Common Lisp in Browser?
norvig opened this issue · comments
Is it possible that each code fragment could be runnable and editable, right in the browser?
One way to get there is to create a docker container with the book, the code, a Common Lisp compiler, and an IDE.
Another way is to run code on a server and embed links to it. Some tools for this:
- rextester Gnu clisp
- tutorialspoint Gnu clisp
More attractive is to run right in the browser. But I couldn't find any tool that translates a big enough subset of Common Lisp to javascript; they were all too limited. It would be great if someone finds one that works. Here are some that will not work for various reasons:
- Slip: missing
&key
etc. - Parenscript: statement/expression issues.
This is not exactly what you were asking: https://github.com/next-browser/next but related.
JSCL is a start and still under development.
JSCL looks promising! But not currently very active.
Looks like there's at least one common lisp jupyter kernel for common lisp.
It'd still probably be a good idea to dockerize it though.
Does anybody have experience with cl-Jupyter
? https://github.com/fredokun/cl-jupyter/blob/master/about-cl-jupyter.ipynb
Don't like the idea of JSCL, I'd expect Common Lisp compiles to WebAssembly rather than interpreted in js. I think it's possible to compile embedded common lisp or clasp with emscripten. The https://repl.it use emscripten to create client side REPL for many languages (unfortunately no CL). I'll give a try this weekend. If it doesn't work well I'll try cl-Jupyter.
No comments about the notebook idea ? It maybe worth to try ...
I am jscl author. I could give it a try to run examples in it. If some fragment doesn't work it is actually a good reason to activate the development a bit :-)
@davazp it would nice to compare the jscl approach with jupyter notebooks . The Lean Theorem Prover is using a nice tool for produzing all their documentations too
https://leanprover.github.io/theorem_proving_in_lean/
Can we adapt it to run CL?
@davazp, that would be great -- I'm looking forward to seeing what you can do.
Slip: missing &key etc.
@norvig support for &key
arguments could be achieved by redefining DEFUN
and LAMBDA
as macros on top of DESTRUCTURING-BIND
, for which there is a fairly complete implementation. The reason I didn't do it is that (as I mentioned) it was really slow — but it could still be okay for didactical usage. More notably, however, SLip is missing LOOP
, VALUES
and CLOS (there's a TinyCLOS-based object system, but I wouldn't expect any real CLOS examples to work with it).
BTW I meant to say that SLip started out as a playground based on chapter 23 "Compiling Lisp" from this very book. While it remained just a playground, it was still a mind-blowing experience for me to work on it. Thank you for that chapter, and for the whole book!
I wonder how practical it'd be to compile an interpreted Common Lisp to WebAssembly. As a preliminary, I just built CLISP for x86/Linux, and it looks like the stripped native binary and the memory image add up to a bit over 6MB:
$ ls -l lisp.run lispinit.mem
-rw-r--r-- 1 parallels parallels 3140504 Apr 5 16:33 lispinit.mem
-rwxr-xr-x 1 parallels parallels 3195288 Apr 5 16:44 lisp.run
I tried to look up typical relative sizes for x86 binaries vs. WebAssembly, but didn't find it online.
That seems like too much to download over a slow connection.
Could cl-notebook
be useful in this context? It's not fully browser-based, but I think it'd be possible to deploy a sandboxed instance somewhere (or even a set of on-demand instances).
I have long held that Javascript is an abomination. I think that browsers should have en embedded lisp interpreter, not necessarily Common LIsp.
I have used cl-jupyter and it worked fine for me.
I'm making a programmable blog (thinking Medium.com + Jupyter Notebook ), aiming to become a platform for interactive e-textbooks. I recently added support for Clojure Script
https://epiphany.pub/@shi-yan/Test-ClojureScript
(purely browser based, no backend)
Hello there, Hacker News!