News for hackers. Stuff that matters.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by wtbob on Thursday September 25, 2014 @11:52AM (#8367764)
This is extremely exciting, particularly if it can be made to work with emscripten. Common Lisp in the browser, here we come!
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by aidenn0 on Thursday September 25, 2014 @12:44PM (#8368095)
Almost certainly can't. The closest you can get is using clicc or ECL or something similar to generate C code, and then compile that with emscripten.

This invokes llvm at runtime, and AFAIK emscripten isn't ported to emscripten.

FWIW, I've tried other lisps under emscripten:

Most lisps generate machine code, store them in RAM, and then execute that RAM. This is not possible under emscripten.

Clisp is a good candidate, since it's byte-code interpreted rather than generating machine code, but clisp makes so many assumptions about how the machine works (in particular it strongly wants a C style stack and does manual stack-pointer manipulation). I actually got fairly far into the bootstrap process under emscripten, but the minimal lisp interpreter it compiles generated bizarre errors.

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by drmeister on Thursday September 25, 2014 @05:01PM (#8369723)
I disagree. Clasp could do this because it compiles Common Lisp to LLVM-IR bitcode files (using COMPILE-FILE) as well as directly to native code using LLVM's MCJIT engine (using COMPILE). emscripten (https://github.com/kripken/emscripten) says that it compiles LLVM-IR to JavaScript. I haven't used emscripten, but I believe everything I read on the internet :-) and thus Common Lisp --[Clasp]--> LLVM-IR bitcode files --[emscripten]--> run within browsers.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by eudox on Thursday September 25, 2014 @05:12PM (#8369768)
I'm not an expert in Common Lisp internals, but there are some things that don't look like they could be entirely put in an executable without bringing the compiler and runtime along. I'm not just talking about things like a library that outright uses eval, but the more high-level things like macros that call compiled functions and reader macros.

Then again, you might be able to compile the compiler to LLVM IR -> emscripten -> JavaScript, and use that to compile CL code.

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by drmeister on Thursday September 25, 2014 @10:29PM (#8371026)
Agreed, but it's more of a "tree-shaking problem" than anything else. Clasp is written in C++ and Common Lisp. Clasp compiles Common Lisp to LLVM-IR and Clang compiles C++ to LLVM-IR. So theoretically you could compile everything to LLVM-IR and feed that to emscripten. Granted, it's going to be a _huge_ LLVM-IR file. Then you shake out the functions and globals that aren't needed. If the compiler isn't needed then it will shake out (or not be compiled in in the first place). The question for me is "what problem does it solve". I assume there are problems that I'm not aware of that it would solve, otherwise why would someone develop emscripten? Common Lisp is a fantastic language that is really underutilized, it's fun and so expressive. I fell in love with Common Lisp three years ago so deeply that I wrote a new Common Lisp to solve my scientific programming challenges while still being able to make use of powerful C++ libraries. I think everyone should use it everywhere - it's awesome.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by aidenn0 on Thursday September 25, 2014 @06:59PM (#8370297)
If you can generate standalone bitcode that doesn't ever generate more bitcode at runtime, then yes emscripten becomes a possibility.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by Igglyboo on Thursday September 25, 2014 @06:34PM (#8370183)
Sorry to go offtopic but since the you mentioned emscripten I though I'd ask.

Can you explain what emscripten is used for? I'm fully aware of what it does, just not why someone would want to use it. How do you use things like jQuery or access window or document from C and then compile it to js? Or is emscripten specifically for js that doesn't interact with the DOM?

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by aidenn0 on Thursday September 25, 2014 @07:00PM (#8370305)
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by corysama on Thursday September 25, 2014 @08:33PM (#8370634)
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by S4M on Thursday September 25, 2014 @12:53PM (#8368148)
> Common Lisp in the browser, here we come!

You have Parenscript for that: http://common-lisp.net/project/parenscript/

(I haven't used it yer though.)

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by agentultra on Thursday September 25, 2014 @01:19PM (#8368299)
It works really well. It's a subset of CL that it can compile though so you'll miss out on CLOS, restarts, etc. However the subset does include macros so it's serviceable.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by malisper on Thursday September 25, 2014 @01:46PM (#8368449)
It looks like there is an extension to Parenscript called PSOS[0], which provides conditions/restarts and something similar to CLOS.

[0] https://github.com/gonzojive/paren-psos

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by arvid on Friday September 26, 2014 @08:50AM (#8372438)
unfortunately PSOS does not use the current version of parenscript. It is based on an older and modified version.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by drmeister on Thursday September 25, 2014 @04:55PM (#8369694)
I don't see why we couldn't do this. emscripten (https://github.com/kripken/emscripten) says it takes LLVM-IR to JavaScript. The Clasp (Common Lisp) function COMPILE-FILE compiles to LLVM-IR bitcode files. If you have some time and you would like to do this - hit me up with an email - I'd love to make this happen.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by phs2501 on Friday September 26, 2014 @11:10AM (#8373019)
You'll probably run into all the same problems other Common Lisps run in to when they try to shake out the compiler from their runtime, namely that often you really do want to create and run new code at runtime (i.e. EVAL but much more often (compile nil '(lambda () ...)). A common example in CL is creating CLOS dispatch functions with specialized parameters to speed up generic dispatch, which I believe most CLOS implementations do at runtime (certainly SBCL/CMUCL's PCL does). You'll wind up needing to include your compiler, Emscripten itself, and all of their dependencies (LLVM libraries?) which will be quite a huge pile of JavaScript. The alternative is to include a CL interpreter but that has obvious speed problems.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by mateuszf on Thursday September 25, 2014 @01:29PM (#8368345)
ClojureScript already exists, and even if it's not Common Lisp, its still Lisp with homoiconity, macros and what not.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by mateuszf on Thursday September 25, 2014 @03:03PM (#8369026)
Ok. Anyone can explain what do I get the downvotes for?
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by nabla9 on Thursday September 25, 2014 @04:05PM (#8369430)
I did not downvote you, but I find your suggestion very amusing because it's so casually out of context.

Being Lisp does not make one Lisp family language replacement for other. Language feature list is not sufficient for comparing the similarity of languages. Clojure and CL are very different languages with very different programming styles. You might have suggested Javascript just as easily.

Re:Clasp – A Common Lisp with LLVM back end and interoperati... by reedlaw on Thursday September 25, 2014 @08:52PM (#8370704)
I still don't understand comparing Javascript to Clojurescript in terms of closeness to Common Lisp. Could someone explain what makes CL and Clojure so radically different?
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by eudox on Thursday September 25, 2014 @09:20PM (#8370808)
They are about as similar as Python and Ruby. Everything from the names of operators to the stance on mutability, to the more obscure corners (Compiler macros, reader macros, etc).
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by mateuszf on Thursday September 25, 2014 @05:07PM (#8369746)
For a person who played with lot of programming languages, but not many Lisps it makes sense. Thanks.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by wtbob on Thursday September 25, 2014 @03:26PM (#8369179)
I didn't downvote you, but I'm honestly not interested in a non-Common Lisp in the browser. I suppose some zealot(s) downvoted you.
Re:Clasp – A Common Lisp with LLVM back end and interoperati... by arvid on Friday September 26, 2014 @09:16AM (#8372513)