3 ms·
One of the most powerful uses of Clojure's macro system has been in the core.async library. This has enabled the construction of a library with operators simila
by juliangamble 13y ago
One of the most powerful uses of Clojure's macro system has been in the core.async library. This has enabled the construction of a library with operators similar to Go's Communicating Sequential Processes [Hoare 1978].
What is different about Clojure's implementation is that no changes to the compiler were required - 'deep walking macros' (http://blog.fogus.me/2013/07/17/an-introduction-to-deep-code-walking-macros-with-clojure/ http://blog.fogus.me/2013/07/17/an-introduction-to-deep-code...) were used - that actually restructure the code.
The benefit of this in the library is that when a process is blocked, the wait is converted to data and the thread is freed up and returned to the pool. You can have multiple processes talking to each other with a thread-pool size of one. (And still reason about the code in a neat way).
The benefit of this comes in the JavaScript environment, (via ClojureScript) where you can compile code that you would ordinarily coordinate with threads using CSP. (With Go-lang style operators)
You can see an example of this on David Nolen's pages here:
* 10,000 processes http://swannodette.github.io/2013/08/02/100000-processes/ http://swannodette.github.io/2013/08/02/100000-processes/
* 100,000 updates
http://swannodette.github.io/2013/08/02/100000-dom-updates/ http://swannodette.github.io/2013/08/02/100000-dom-updates/
This is the power of macros in Clojure - things that would require a compiler extension in another language, are a library in Clojure.
- gnaritas 13y agoThat last sentence should more aptly be "This is the power of macros in a Lisp - things that would require a compiler extension in another language, are a library in a Lisp." as all the other Lisp's have the same advantage; Clojure is not special in this regard.
- cbp 13y agoClojure has other advantages which other lisps and go don't have such as immutable values and a prevalence of expressions (as opposed to statements), both of which give core.async certain features that go's implementation lacks.
- carterschonwald 13y agoFalse. Please go read up on modern scheme. particularly racket lang. In many respects, Clojure is Racket, but on the JVM rather than native.
- rsanders 13y agoRacket is one other good example but he was responding to the "all other lisps" claim. Racket pretty unusual in many regards, so I think the Dwightian "False" was unnecessary here. Or anywhere, really.
- brudgers 13y agoRacket is a Scheme: Racket is still a dialect of Lisp and a descendant of Scheme. The tools developed by PLT will continue to support R5RS, R6RS, the old mzscheme environment, Typed Scheme, and more. At the same time, instead of having to say “PLT's main variant of Scheme,” programmers can now simply say “Racket” to refer to the specific descendant of Scheme that powers PLT's languages and libraries. http://racket-lang.org/new-name.html http://racket-lang.org/new-name.html
- rsanders 13y agoIndeed. Now name all the other Lisps and Schemes in wide use that are based on immutable data structures.
- chongli 13y agoClojure is a more opinionated language. It has a BDFL who has really stamped his mark on it. This is very much reflected in the standard library and the built-in syntax for the standard collections. Sure, nothing is stopping Racket from doing everything Clojure does, however defaults do matter. Once a language reaches critical mass, it becomes very difficult to change without breaking everything.
- carterschonwald 13y ago
- billsix 13y agoyou may enjoy On Lisp. http://www.paulgraham.com/onlisp.html http://www.paulgraham.com/onlisp.html