8 ms·
ClojureScript 1.7: ClojureScript can compile itself
- krat0sprakhar 11y ago> We grabbed a string out of CodeMirror, read it via tools.reader into persistent data structures, passed it into the ClojureScript analyzer, constructed an immutable AST, passed that AST to the compiler, and generated JavaScript source with inline source maps and eval'ed the result. All of this happened inside of your web browser. This is just fantastic! As David himself mentions - this might not be extremely pragmatic but it sure as hell as cool. For me it means that I can get back to writing my web-based Clojure book without being dependent on Himera[0], which although great, is really hard to work with. Awesome work by @swannodette and team! [0] - https://himera.herokuapp.com/index.html https://himera.herokuapp.com/index.html
- fogus 11y ago> without being dependent on Himera It horrifies me that anyone would have been dependent on Himera to do real work. While I'm proud that it filled a gap for a few years and consider it a successful experiment, I'm happy to know that it's effectively unnecessary now.
- krat0sprakhar 11y ago> horrifies me that anyone would have been dependent on Himera to do real work. Haha! Well, it was not real work - just a fun experiment[0]. Thanks for Himera, though. It was great while it lasted :) [0] - https://github.com/prakhar1989/gitbook-plugin-clojurescript https://github.com/prakhar1989/gitbook-plugin-clojurescript
- escherize 11y agoIs your book up anywhere? Would be awesome to see it in action. Even if not, can you plug your book a bit?
- eggy 11y agoI don't pretend to know front end dev too much; I don't program for a living, but it seems the 'bazaar' model of layering, patching and piling things up is making that world unnecessarily complex. If I understand this thread correctly, you lose Google's Closure optimizations(?), you go round about AST->compiler->JavaScript and you can eval the result. Is the eval equivalent to Scheme or Common Lisp? What are its limitations? I like what I see of ClojureScript as a language syntax and some of the underlying concepts. I am playing with PicoLisp and PilOS (PicoLisp running on a VM - not really a Lisp Machine), and the simplicity and directness of it is refreshing. The layer of abstractions are minimal. I guess that's the same reason I like the J programming language. I am astounded by the amount of work and the accomplishment here, but I have to wonder if we can't see the forest for the trees any longer in computer science. Currently reading 'The Architecture of Symbolic Computers', studying Shen, PicoLisp, Racket and the J programming language. Perhaps my naivete of not having to work in this field, and the luxury of being able to dabble across languages and systems has shifted my perspective? EDIT: How do you debug your work? What traces do you get back? Can you still do REPL (like Emacs/Slime) this way?
- ballpark 11y agoOne thing that's great about Clojure and Clojurescript is that they run on Java and Javascript platforms respectively, and are easy to interoperate with those platforms. For a business that wants to crank out some code, being able to use the libraries that others have created for those platforms makes the decision to use them for production systems much easier.
- delluminatus 11y agoClojureScript is probably not the best language to use if you want few layers of abstraction. I personally love it, though. The best way to think about this development is that it is a client-side compiler for ClojureScript. In client-side development, you are constrained by the limitation that all code must be in JavaScript to be executed by the Web browser, which is why this compiler "compiles to" JavaScript instead of machine code. JavaScript is the assembly of the Web, right now (until things like WebAssembly get more useful and popular). Once the ClojureScript is compiled to JavaScript, the JS can be executed by the browser (which of course involves an additional JIT compilation step). This might sound "dirty" if you are used to thinking about non-Javascript development, because it involves two separate compilation steps, but it is unavoidable, once again until something like WebAssembly becomes popular. So, this is a client-side compiler for ClojureScript. A server-side compiler already exists, which is what you would use if you wanted Emacs/Slime support, or if you were developing a "real" Web application for deployment, because in that case you would want to pre-compile to JavaScript on the server, and distribute the compiled JS to the client. It doesn't really make sense to talk about Emacs/Slime running on the client, until someone makes Web app for it. You could use a socket-based REPL to communicate from the client to the server but I don't really see the benefit, when you could just use the server-side compilation model and avoid the network overhead.
- tbatchelli 11y agoThis also means that we can use clojurescript as a scripting language. Will make some systems automation much more fun!
- Turing_Machine 11y agoSure. There are a lot of scenarios where the 300k overhead hit isn't going to matter all that much. Not that 300K should be considered a huge amount by today's standards anyway.
- reitzensteinm 11y agoWell, that's 300k of gzipped code, so while the bandwidth isn't huge (300k is barely a large image these days), that's a ton of code to be parsed, and might be too much of a CPU hit for anything mobile.
- mfikes 11y agoIt is actually pretty good for mobile and startup time isn't an issue. We have variants that run on iOS https://itunes.apple.com/us/app/replete/id1013465639?mt=8 https://itunes.apple.com/us/app/replete/id1013465639?mt=8 and Android is in the works http://tahmid.me/posts/2015-07-15-bootstrapped-cljs-repl-for-android.html http://tahmid.me/posts/2015-07-15-bootstrapped-cljs-repl-for...
- reitzensteinm 11y agoOh, my comment wasn't at all clear, but I was talking about inclusion on web pages, where you'd be flicking forward and back between them. In which case even 50ms on top of the rest of a page load would be hurting you. I'm sure it's fine for a SPA, and for a mobile app it's a total non issue. Actually I'm planning to use it for one with React Native myself. Luckily, people will probably not be including the full compiler lightly; I just wanted to point out that it's not as cheap as a jpg of the same size would be, an impression I thought the parent comment was giving.
- Turing_Machine 11y agoThis is fantastic. It will be a lot easier for noobs to get their feet wet if they can use use the full language without having to fool around with installing a Java toolchain.
- robohamburger 11y agoThe most interesting case for me will be fast starting clojurescripts as the author points out. The one area I have not been happy with is clojure's startup times so hopefully this fixes that going forward.
- mfikes 11y agoIt can be very fast to get things running. Here is an example using "desktop" JavaScriptCore on OS X: https://twitter.com/mfikes/status/626884586392453120 https://twitter.com/mfikes/status/626884586392453120
- hencq 11y agoWow, this is quite amazing! Does this also mean that we will be able to write macros in Clojurescript? Are there any plans to use mostly the same backend for Clojure and Clojurescript? It seems that since the languages are almost the same, it's only the code generation part that would be different?
- mfikes 11y agoYes and no. You can write macros for which the source is ClojureScript, but they need to be kept separate. Here is a stab I took at explaining that subject: http://blog.fikesfarm.com/posts/2015-06-19-portable-macro-musing.html http://blog.fikesfarm.com/posts/2015-06-19-portable-macro-mu... There are no plans for the same backend AFAIK.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]
- sbensu 11y agoUsing the same code for the backend is not realistic since Clojure leverages JVM libraries. A new ClojureScript backend ecosystem would need to start wrapping Node libraris to reach Clojure parity
- maehwasu 11y agoI did this late last year for a traffic analytics backend. As you said, I had to wrap a lot of Node.js libraries, and then wire them up with core.async. It was a fun project, and I learned a lot, but I ended up reimplementing the whole thing in Clojure+Java because performance and DB access was so much better in this use case. Having only a single event thread kills Node relative to the top JVM servers.
- nextos 11y agoI wonder if one of my favorite libraries for Clojure, Anglican [1] a probabilistic programming language, can be ported to ClojureScript without much effort. One could do amazing things with this. Keep up the good work. Clojure & ClojureScript are awesome. [1] http://www.robots.ox.ac.uk/~fwood/anglican/ http://www.robots.ox.ac.uk/~fwood/anglican/
- rymndhng 11y agoIf your library is written in pure Clojure (no reliance on Java) it's fairly trivial with Clojure 1.7's Conditional Readers. Here's an example of a repository that I've repurposed to compile both Clojure + Clojurescript. https://github.com/rymndhng/clj-diff/commits/add-cljc-redo https://github.com/rymndhng/clj-diff/commits/add-cljc-redo
- jeletonskelly 11y agoI swear David Nolan does not sleep.
- marpstar 11y agoThis is one of those things that people imply when they talk about "rockstar developers". Those who get so much stuff (of relatively significant achievement) done and have time to blog about it, and have time to speak publicly about it, and have time to further engage the community around them. ...and eat and sleep, of course.
- marcofiset 11y agoAnd most of the time also work at a day job! And take care of their kids! I'm simply amazed.
- jacquesm 11y agoYou can do that for about 25 years or so and then you're going to slow down no matter what.
- deleted 11y ago[deleted]
- swannodette 11y agoI do in fact enjoy sleeping immensely. As alluded to in the post while I tend to do a lot of "driving" - this release was the result of a broader effort by the growing Clojure & ClojureScript communities.
- DanielRibeiro 11y agoAnd we are very thankful for all your contributions David. Thank you so much.
- jeletonskelly 11y agoTake it as a compliment man. I just think you do great work. Hopefully I'll see you at the bar again at the next conj.
- bmillare 11y agoI think an article outlining the details behind the non-trivial example, specifically on configuring how library names are resolved and how it can be modified dynamically, would be instructive.
- derek 11y agoThe source code for the post is available[1], as is the macro[2] which is loaded via XHR. The short of it is that a load function is passed to `cljs/compile-str`, which provides the mapping. In this case, it doesn't bother to do any mapping because it knows that it is loading `bar.core`. However, `bar-url` could instead be in a map from the namespace to the URL. Surprisingly simple, actually! 1. https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/cljs_next/core.cljs#L138 https://github.com/swannodette/swannodette.github.com/blob/m... 2. http://swannodette.github.io/assets/cljs/bar/core.cljs http://swannodette.github.io/assets/cljs/bar/core.cljs
- pacomerh 11y agoI've been wanting to get into ClojureScript (to clean my development practices, etc) but I'm wondering if I need to be a Clojure user. Does it make sense for a Javascript developer to just jump straight to ClojureScript?. I've seen PureScript also.
- stijlist 11y agoShort answer: yes, jump right in! Check out David's other blog posts, ClojureScript synonyms[1], and http://clojurescriptmadeeasy.com http://clojurescriptmadeeasy.com. http://himera.herokuapp.com/synonym.html http://himera.herokuapp.com/synonym.html
- mfikes 11y agoClojure and ClojureScript are practically the same language. Both are "hosted", relying on Java and JavaScript for low-level things and providing clean interop for those things. So, I see no problem with learning either. Especially when you first jump in you are concerned more with the language "proper".
- freshhawk 11y agoAs has been said, they are basically the same language. In terms of learning, it's probably easier to learn Clojure at the very beginning. It's simpler to get repl working and get a project building with Clojure right now. Not much simpler, but simpler. And at the very beginning, when the toolchain is magic to you, that matters. As early as you like you can switch to Clojurescript, learn the handful of small differences and go from there.
- netcraft 11y agoDoes this mean I could use compile and then require clojurescript modules in node? Today I use babel to "transpile" es2015 to es5 and then load those in, could I do something similar with clojurescript?
- mfikes 11y agoNone of this recent work facilitates compiling ClojureScript into CommonJS modules for use with Node. But, the opposite is in flight: ClojureScript now has support for depending on libraries that are packaged using the CommonJS system.
- klibertp 11y ago> None of this recent work facilitates compiling ClojureScript into CommonJS modules for use with Node. http://www.matthewstump.com/misc/2012/06/04/writing-nodejs-modules-in-clojurescript/ http://www.matthewstump.com/misc/2012/06/04/writing-nodejs-m... Should be really very easy to do, you only need to study what cljs compiler emits and the docs for Google Closure Compiler JS libs.
- raju 11y agoCan someone this to me? It seems that mfikes (parent) comment, and klibertp's comment seem to contradict each other. Not to mention the examples that glenjamin highlighted. I have heard similar comments in other places, in that it's not possible to package ClojureScript as a NPM module. Is it because of the size of the module, or something else?
- glenjamin 11y agoThis was already possible, see https://github.com/swannodette/mori https://github.com/swannodette/mori or https://github.com/glenjamin/checkers https://github.com/glenjamin/checkers for examples.
- dominotw 11y agoI have been looking at functional languages for frontend. But, I guess I am one of those people who just can't unsee the parentheses in lisp languages . How does clojurescript compare to elm/purescript ?
- mateuszf 11y agoYou have to use it for some time, and then the parenthesis will just disappear.
- mbillie1 11y agoThis is really true. I've recently moved to CLJS from Ruby/vanilla JS, and it took a couple weeks to be able to make sense of it. Now I don't notice it at all. It's just an exposure / getting-used-to-it thing.
- mfikes 11y agoYep, and within a few months you will find yourself accidentally typing `(if` instead of `if (` in a C-based language.
- lgas 11y agoAnd then when you go back to a language not based on S-expressions you'll really miss them.
- akilism 11y agoplus an editor with a nice paredit mode.
- gizmo385 11y agoHaving paredit makes me miss LISP when I'm not writing it. It just makes moving around and restructuring code so much easier than it is an a C-based language.
- KingMob 11y agoIf you learned to unsee the angle brackets in HTML, rest assured, the same would happen in Lisps after a couple weeks.
- DAddYE 11y agoAwesome!!! Now we want Clojure in Clojure :)
- braythwayt 11y agoDoesn’t this imply the development of a JVM written in Clojure?
- truncate 11y agoI'm curious if ClojureScript uses the original clojure library code (eg, drop, take, map...) or re-implements them? I tried to find something in codebase, seems like it uses original.
- swannodette 11y agoA non-trivial portion of Clojure (data structures, compiler) are written in Java. In ClojureScript these are written in Clojure or ClojureScript so there's really not as much to share as it would seem.
- edem 11y agoFor some reason I feel like ClojureScript starts to transform into a new Clojure dialect (which runs on node.js and not on a JVM). Am I correct?
- swannodette 11y agoClojureScript will always run on the JVM. It's just that from now on it will also always run on JavaScript.
- mfikes 11y agoHere is some good exposition on that matter: https://github.com/clojure/clojurescript/wiki/Bootstrapped-ClojureScript-FAQ https://github.com/clojure/clojurescript/wiki/Bootstrapped-C...
- jimmcslim 11y agoWhen will the module support be released? Soon I hope! Thanks for the great work on all this.
- swannodette 11y agoModule support is already in 1.7.28 however it requires a corresponding release of the Google Closure Compiler.
- lipenliu 11y agoWho gives a shit?!
- lipenliu 11y agoWho gives a fuck?!
- lipenliu 11y agoWho Gives A Monkeys Flayin Arse?!
- lipenliu 11y agoWho cares?!
- jbeja 11y agoYou, apparently.
- lipenliu 11y agoMy granny don't care!
- intellectable 11y agoThanks, for all the fish ( by fish I mean awesome code ) @swannodette and team! Can't wait to use Om Next. Also looking forward to seeing some code examples of Demand-Driven Architecture[0]. Does anyone know of any edifying clojure code examples? [0] http://www.infoq.com/presentations/domain-driven-architecture http://www.infoq.com/presentations/domain-driven-architectur...
- MrBra 11y agoAt least it doesn't try to sell itself as a beautiful programming language, aesthetics wise.
- jbeja 11y agoThe irony.
- MrBra 11y agoThe touchiness.
- gizmo385 11y agoI can't tell if you're being sarcastic or not...
- MrBra 11y agoSame here.
- fnordsensei 11y agoSince aesthetics are subjective, trying to sell the merits of a language on beauty rather than capability wouldn't mean a whole lot. As with "easy" vs "simple".
- MrBra 11y agoWe are not machines or not all of us want to mimic their functioning.
- retrogradeorbit 11y agoThis is a huge milestone! I had a problem I was solving with Clojurescript six months ago and having access to the reader would have solved it perfectly, with lisp elegance. Instead I had to make a mess. I think this opens huge computer science educational opportunities. Imagine a LOGO DSL inside your browser. With all the power of cljs. I am very excited!
- sharash2 11y agoMa penis self compiles!
- dgreensp 11y agoHow does the output of the ClojureScript-compiler-in-ClojureScript compare to the real thing? Do you lose the Google Closure optimizations, and if so, does that mean it isn't a good idea to compile your web app using the ClojureScript compiler running in Node (for example)? It's nice if you can compile ClojureScript on a machine without Java.
- gw 11y agoCorrect; you do not get the benefit of Google Closure when using the bootstrapped compiler. The JVM-based compiler will continue to be the best way to compile ClojureScript projects for production.
- agumonkey 11y agoHow far clojurescript is to be clojure/js. By that I mean how close the JVM and JS are semantically. There were discussions about that few months ago, because of differences deep down between platforms builtin types (js integers, etc). Swannodette also explained that cljs and clj don't share as much code as the team would like. How much clojure code would run correctly as-is on cljs ? Without having to use specific reader conditionals.
- likeclockwork 11y agoHm. This allows putting functions into edn that gets sent to the browser now, then doesn't it? Since ClojureScript can eval now?
- mfikes 11y agoIf you put the function source into edn and the function doesn't depend on anything but core constructs, it would be nearly trivial to eval using the new cljs.js. If those functions need to call into other ClojureScript namespaces that you've already compiled into your code then the analysis cache would need to be populated so that eval can operate properly. For reference, here is cljs.js/eval: https://github.com/clojure/clojurescript/blob/v1.7/src/main/cljs/cljs/js.cljs#L497 https://github.com/clojure/clojurescript/blob/v1.7/src/main/...
- avodonosov 11y agoFinally, thanks god