August 14, 2014

Clojure Weekly, August 14th, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy! - Clojure Documentation For the unknown pearls in the standard library, this week I’d like to introduce you to This namespace seems dedicated to diff because the other functions seem to be internal implementation details. This is a polymorphic diff that based on the input params is doing its best to return the diff as seen from both sides and the actual difference as the third part of the results. It can be used for all sort of useful stuff related to comparing data structures with a result that is easy to process.

Functional Geekery Episode 13 – Martin J. LoganFunctional Geekery | Functional Geekery This FG episode is about Erlang, sorry to file it under Clojure stuff. But it is an interesting and entertaining episode with Martin Logan, an Erlang veteran, illustrating a bit of history of the language and its community. Although Clojure doesn’t embrace the actor model as a fundamental concurrency construct, there is certainly inspiration coming from that with agents in Clojure and they both share immutability as their core principle. Also consider a quick look at Elixir, a modern take to Erlang with a more Ruby-like syntax.

Promise - Clojure Documentation Promises is another Clojure construct to help in creating powerful concurrency models. It doesn’t contain behaviour for a computation (like futures) but it is just delivered results with deliver. Promises are often found in conjunction with futures since the behave like single-entry blocking queues. The future can deliver to a promise that is passed in when the future is created and the main thread can at some point block while deref the promise. The advantage is that you don’t need to code any nasty “wait” semantic (like futures). There is also another important aspect of combining futures and promises this way: the callback fn can be generic and the result handled to the promise in-situ, creating the semantic of a synchronous call. The same happens as well in core.async, but the thread where the computation is running is non-blocking.

Dissecting Reducers - Skills Matter If you’re struggling understanding the new transducers primitives that Clojure 1.7 will be introducing, I strongly suggest you get your self familiar with Reducers first, because the implementation of the transforming reducers (map, filter etc) is exactly the same. This is also a very nice example of functional abstraction or “pattern” approach to functional programming that is worth understanding deeply. What I’ve linked here is a talk (30’) I gave last year about reducers from the point of view of functional abstractions (more than the parallelism they introduce with fold).

Some trivial examples of using Clojure Transducers - An Ostler in IT Of all the transducers buzz I’ve found around I’ve selected the following post because it’s mainly examples. Like the author of the post, I’ve also found transducers a natural evolution of reducers and after I went beyond the new lingo I felt myself home again. One important difference that you can clearly see here, is that reducers are not able to apply a pipeline of transformations without actually “reduce” the collection. The only way to achieve that effect is with “into” that uses reduce internally completely throwing away laziness. Transducers effectively abandons the intimate relationship with reduce (and fold).

Comments (View)
August 6, 2014

Clojure Weekly, August 6th, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

Recommended Reading : Microservices Architectures and Clojure (A Quick Survey of Resources) | Architecting Beyond Twenty Twenty In this post you can find a list of micro services related material (presentations, videos, articles) with a specific focus on Clojure solutions. Why all this interest about micro or nano services? Because it adds quite a bit of freedom in terms of composability and scalability of a system. Micro services are also easier to deploy compared to a monolith application, where keeping track of what is going live isn’t an easy task at all. Clojure is perfect platform for micro services, because it’s dynamic (quicker feedback loop), run on the JVM (widespread) and contains mature deploy tooling and monitoring (including everything that was developed for Java already).

Prismatic/eng-practices Thanks for sharing Prismatic! These are interesting and detailed readings about the engineering practices Prismatic has been implementing and evolving on the field. This is the main reason they are concise and to the point. You can find here at the moment some elaborate discussion about Clojure type of polymorphism, namespace organisation and testing. Not strictly related to Clojure but definitely worth a reading as well: Prismatic git workflow and iOS profiling.

bellkev/dacom A Datomic, Compojure, Chors, core.async, Om stack ready to hack with. If you resist the temptation to update the dependencies to the latest and greatest (please do yourself a favour and don’t touch them until you’re missing a feature) this project works out of the box and contains a working stack with the above technology nicely integrated and automated. It uses Bower, Boostrap and LessCss to automate the client side and it also contains lein tasks to prepare and initialise the Datomic instance and Austin integration for ClojureScript. If you don’t like the idea of cloning it, just go for the “lein new dacom” template and the app will get your name. Well done.

johnwayner/lein-datomic If you prefer just Datomic automation, this small plugin contains a few useful tasks integrated with leiningen. Given an existing project it adds commands like the Datomic instance start or re-initialisation with the schema configured in project.clj. Documentation is essential but clear. Also easy to fork and extend.

Anna Pawlicka | Common mistakes to avoid when creating an Om component. Part 1. Nice collection of Om pitfalls, things that are easy to not understand correctly and (usually) silently fail. At least, this is also my initial experience with Om and ClojureScript. One part of the “fragile” impression is definitely the learning curve, which includes something that is similar to a new programming paradigm (reactive programming is a little bit, especially if you add lifecycle events to deal with state changes). But the other part is more about the fact that the technology is really young and tooling around it fails if you use a different minor version.

Comments (View)
July 23, 2014

Clojure Weekly, July 23rd, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

clojure.core/gen-class · Grimoire gen-class creates a Java class and spits that to disk. It can be instructed with all sort of Java goodies, like implemented interfaces, methods, ctor plus some goodies like a post-init constructor. One of the main reasons of gen-class is Java interoperability, where it is important that the class is not generated on the fly in a deeply nested classloader and is reachable through normal class path lookup such as Class/forName calls. gen-class has only value during AOT compilation and does nothing at the REPL.

Transit – A format for conveying values between different languages | Hacker News Transit is a new data transfer format from the Cognitect crew. What it offers and what adds to the plate of an already rich horizon of data transfer format was not clear to me after reading the official presentation page. As usual HN does a great job comparing with the existing stuff and hence my link to it. Rich, Fogus and Swanndonnette are all in the thread, so you can see that the competitive advantage of Transit over other formats seems to be about the compression mechanism, pluggable human-readability, json interoperability and the extension mechanism. EDN isn’t deprecated or anything like that, but it sounds like for future work you better look at Transit instead.

cemerick/austin Austin is the glue between the lein building process of a ClojureScript based project and the browser. With Austin things like evaluation of ClojureScript in the repl is possible, with several options, headless or fully integrated with Chrome for example. I think the most compelling use case during development is making a change and have the browser to automatically update the changes, no refresh required. Other compelling reason is full access to the dom at the repl for debugging and experimentation.

One Div Zero: A Brief, Incomplete, and Mostly Wrong History of Programming Languages Totally cracked up by this humorous history of programming languages :) All the stereotypes are there. Probably the one I liked the most is Perl. I think ARC got mentioned instead of Clojure because in 2009-ish it was still considered the new Lisp. History turned out to be different.

CLiki: Naming conventions These are the naming convention guidelines you were all waiting for! It’s common lisp, but hey, it is not that different from the same kind of naming conventions of Clojure sources. Of course they are not all applicable, but they help a lot giving just a bit of semantic to a function name in case Clojure doesn’t.

Okasaki: Ten Years of Purely Functional Data Structures A blog post from Okasaki, author of Purely Functional Data Structures, describing the history behind the book that is still popular these days. Okasaki also answers a few frequently asked questions. StandardML was selected for specific reasons related to its control of lazy VS strict evaluation but it won’t be the same choice today: the book would likely be re-written in OCaml. Why not a dynamically typed language? Because Okasaki thinks that functional data structures are better explained when types are explicit. Just in case you don’t know, Clojure is implementing and extending some of the persistent data structures described there (in Java). If you want a preview of the book before buying, keep in mind that Okasaki’s thesis is available online with a very similar content. Worth learning SML just to follow this book! Unfortunately, no 2nd edition is in sight.

How to write a dissoc-in command for clojure? - Stack Overflow There is no dissoc-in in the standard library. There used to be one in clojure.contrib that got dispersed when libraries entered their own repos. But it is also simple to replicate with an update-in as suggested in this SO answer. You just need to stop one key before in the list of inner keys and add it to a dissoc invocation for the corresponding map: (update-in {:a {:b 0 :c 1}} [:a] dissoc :b)

Comments (View)
July 15, 2014

Clojure Weekly, Jul 15th, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

Functional Geekery Episode 12 – Adi BolboacaFunctional Geekery | Functional Geekery Controversial (in a good sense) Functional Geekery episode. When speaking about style and idiomatic Clojure, I tend to be inspired by one of the most popular source of Clojure wisdom: clojure/core.clj. The style there leans toward essentiality, where variable names are just a few letters and they tend to follow an implicit convention (f, g are function names, xs is a collection of x and so on). But uncle Bob clean-code style is much more verbose in that respect, suggesting more speaking names. I agree with all the rest of the discussion, in term of SOLID principles applied to FP and the overall idea to dedicate a code-retreat format to FP style programming. But I’m not sure about naming. What determines understandability in a language is also the culture and conventions that are stratified into it. Clojure is inspired by CL in many ways, including naming and it looks unproductive to me to try to change 50+ years of conventional wisdom to another convention.

rseq · clojure.core For the “standard library in small pills” series, here’s the mostly unknown rseq. It works like seq, transforming something sortable into a sequence but at the same time it is reversing its order. Use cases? None at hand, but consider that it is doing it O(1). How can it be? Little trickeries: the PersistentVector underneath is unchanged, but is wrapped in an RSeq object that is counting backward when next() is required, starting from the end! Good luck garbage collector when I unroll 1M of these :)

protocols - How does clojure’s defrecord method name resolution work? - Stack Overflow Enlightening quick SO answer from Christophe Grand about potential name clashing in protocol definitions. defprotocol and defrecord are a powerful tool provided by Clojure to replicate some object oriented runtime polymorphism. They’ve got rough edges as soon as you start pushing too far with them, something you can experience if you try to port a complex object model from Java “literally”. defprotocol for instance, creates the function definitions inside the namespace they are declared in, with the consequence that there shouldn’t be other “normal” functions with the same name and no other protocols definitions with the same name, let alone using function names from clojure.core. At the same time if you define protocols in different namespaces you can incur in weird require+import constrains to use them in other places. Add the fact that other than the basic examples, there is no throughout guide to “build yourself a CLOS in Clojure”. We can certainly discuss if this is needed at all…

lein test-refresh If only I knew about this a couple months ago… I wouldn’t have ported the test suite to Midje with autotest, my favourite unit test framework. Or maybe not, because I’m quite fluent with the Midje API and got used to the expressiveness it can provide. Anyway, if you are on clojure.test, this lein plugin is an automatic runner that runs in the background and send you notifications about the status of the tests while you are typing in the editor. It is my favourite workflow at the moment, which includes the REPL running for experimentation and solutions while the overall functional interface is driven by tests. I don’t use the same for legacy code, where somebody else wrote it, although I tend to cover “after” with test the part I don’t understand.

L(λ)THW Learn Lisp The Hard Way Interesting initiative that could be ported to Clojure and has already been ported many times to many languages. Zed Shaw started it all (I think it was Learn C The Hard Way) and then produced another bunch of them. The template to write books using the same style is publicly available and Zed Shaw is encouraging others to write their own. This is the “brave” Lisp attempt, considering the amount of top quality books around about programming in Lisp. The author explained the effort behind this achievement on HackerNews. This is not a couple of days project and it is coming out nicely. Remember the following rule of thumb: learning Lisp is providing you the all principle (and often nomenclature and conventions) behind Clojure.

clojure.core/cycle Cycle is similar to clojure.core/repeat, but it operates on a sequence by recursively merging it to a copy of itself, ad infinitum. Cycle is your friend on things that needs to be provided in a round-robin fashion, including assignment of a finite set of identifiers or simply creating a css zebra list of some sort. Repeat is less useful here since it will repeat a single item instead. Always use with clojure.core/take on front!

Comments (View)
July 9, 2014

Clojure Weekly, July 9th, 2014

Welcome to another issue of Clojure Weekly! I’ve got tons of ideas and resources to follow coming out from EuroClojure, I’ll be digesting them here during the following weeks. If you don’t know what this is, Clojure Weekly collects a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

My Top Clojure Articles - Adam Bard and his magical blog Signalling a nice collection of Clojure related articles by Adam Bard. They are divided by level of proficiency with the language, so it makes it a very good start to pick up Clojure from scratch.

EuroClojure’s Videos on Vimeo Unless they are already displayed when you read this, keep an eye on the EuroClojure channel on Vimeo because videos will appear very soon here. Go for David Nolen for the inspirational talk, Tommy Hall for the entertaining one or yours truly (Renzo) because this is a shameless plug!

Thoughtworks technology radar The last technology radar sees ClojureScript in the trial phase, up to the top close to the adopt section. Clojure the core language is not present, while Scala is in the adopt section. Clojure (Om-ClojureScript) is present in the explanation section as well. My impression is that TW is not endorsing Clojure as a server side language but as client side, which is amazing and disturbing at the same time (or as someone else put it on twitter, it is given Clojure as implicit adopt?). There are other well known technologies and platforms, but there are also new entires I’d like to have a look at.

Grimoire Grimoire is a new documentation service and community contributed example repo similar to still comes up high in google searches despite it is documenting Clojure 1.3, by providing examples that are not easy to find elsewhere. Grimoire is instead up to date and also gives access to all the examples in clojuredocs. Grimoire is open to community contribution over git pull requests and will likely be improved in the future to make contributions easier.

Difference between defrecord and extend - Google Groups This interesting thread finally solved my problem. Extending a type to a protocol is not equivalent to a defrecord definition that implements that same protocol. They generate different kind of polymorphism. The first main difference is that extending a type with a protocol is not adding functions to its interface (and this you can’t invoke them on a record instance). Second main difference is that extending the type with a protocol allows for an implementation swap at any point, while defrecord definition of functions are forever.

Clojure - todo Another small bit of history, a Clojure todo list back from 2009. Is not very important today but I want to keep an handle to things I discover randomly just in case. Interesting to notice that 90% of what we are talking about nowadays with faster compilers for mobile or Cloj in Cloj were already there. Others like Datalog were not baked in directly in the language but in Datomic.

Clojure Gazette 1.81 - Nicola Mometto I’m very interested in everything compiler related these days and of-course I’m following the amazing work Nicola is doing to port Clojure in Clojure. This Clojure Gazette is an interview with Nicola that explains a little but of the background about his work, past, present and future. I hope we’ll be soon meeting Nicola at some Clojure conference speaking about the work he’s doing, but as he said in the interview, he’s mostly spending his time coding and the better way to know about his work is to follow the public activity on github.

Comments (View)
July 1, 2014

Clojure Weekly, July 1st, 2014

Welcome to another issue of Clojure Weekly! I’ve got tons of ideas and resources to follow coming out from EuroClojure, I’ll be digesting them here during the following weeks. If you don’t know what this is, Clojure Weekly collects a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

midje-doc Midje-doc generates beautiful documentation starting from midje facts, which are treated as examples to show how code works. There is some directives you can give during namespace declaration to tell midje-doc how do you want your tests to be translated into “live documentation”. Midje-doc supports the midje :autotest philosophy and can show how the documentation shapes up while facts are being written. There is a 14’ screencast to demonstrate all of this on the github repo page.

[GSoC 2014] Lean compiler: first iteration - Clojure on Android Quick one to signal that project Skummet is now able to output static declaration of Vars in the generated Clojure byte-code, one of the several optimisations envisioned for Android environment that could have also beneficial impact for quick development feedback at the REPL. I tried the build on my own projects without noticing any errors.

Lisp in Small Pieces: Christian Queinnec Just ordered a copy of this (quite pricey) book about Lisp implementations. I found the book linked in many places, including rhickey suggesting it on IRC (5 years ago). The content is about typical problems and solutions for implementation of lispy-like languages (Scheme is the one used in the book), including compiled output, intermediate bytecodes or interpretation. The Rich Reference Implementation of Clojure is indeed all about this sort of problem.

metaprogramming - How do you evaluate a string as a clojure expression? - Stack Overflow I had to use something similar recently, so I could pass around a macro to be used in a different place from where it appeared in the code. With normal functions you can always use (var fn) or the equivalent #’ reader macro to create, for example, a map of keys - fns. But macros need special evaluation and thus something like (@#’clojure.repl/doc str) doesn’t work while (@#’clojure.lang/+ 1 1) is perfectly fine. The only (not very nice) way I found was to use (eval (read-string “clojure.repl/doc str”)) to make it work. Mind that there are very few cases where you need something like this, which is also suffering from security problems if eval-ing user input.

Euroclojure 2014 Here are the definitive notes for EuroClojure. Phil Potter wrote all of the notes at smoking speed over the conference, except during his own talk (I’m sure he’ll fix this annoying detail next year :) By the way, talks were amazing, with tons of ideas and links to follow that you can read on this gist as well. Thanks Phil!

Comparing Clojure Testing Libraries: Output - Jake McCrary An interesting comparison between output of testing libraries. Expectations is the winner of this informal but still useful comparison, mainly because of the care that put into the correct formatting of output between different data types. Midje is coming last with a promise (see comments below) by Brian Marick to make it better than ever. Can’t wait.

quil/quil Quil is a Clojure wrapper around, which is a drawing language and environment written in Java. With a few more wrapping layers on top, we are talking about driving openGL from Clojure. Quil is suitable for all your graphical and animation needs down to the pixel level, with a huge library of primitive available for more abstract drawing. I saw it in action during the interlude lunch-time lightning talk, showing tracks of a sequencer on the screen in a simple and effective way.

Comments (View)
June 24, 2014

Clojure Weekly, Jun 24th, 2014

Welcome to another stellar issue of Clojure Weekly! This one is just before my talk at EuroClojure. Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

lazy evaluation - Clojure: rest vs. next - Stack Overflow Nice discussion on StackOverflow about next VS rest. It can get quite philosophical and reading the sources is not helping a lot (I could only track that is calling next() inside but each collection has a different implementation of this). One sure thing is that to return nil next needs to look ahead and realise at least the next element or the next chunk of a sequence. So rest is more lazy than next.

clojure-compiler/src/net/n01se/clojure_compiler.clj at master · Chouser/clojure-compiler Another bit of Clojure history. Chris Houser is one of the protagonist of the Clojure scene and one of the earliest receptor of Rich’s ideas about the future of Clojure. Apart from his very good book ( he should also be credited for a couple of important early attempts: ClojureScript and Clojure in Clojure. Although his work didn’t end up being part the current related efforts, it is stil inspirational. Linked here is a clojure compiler in clojure from 2009. If you look at the bottom, it is tested by parsing the compiler itself.

Pelure - Shell Scripting in Clojure with Pallet is an internal clojure DSL that emits bash shell scripting. Personally I don’t write a lot of shell scripting, just the right amount when needed and when that happens I’m definitely going to look up yet again how I need to implement a condition or a loop. No more with Stevedore. I just write my favourite Clojure with some imperative style and voila, I can output shell scripting. Maybe that could be the base skeleton to start with. It allows advanced “macro style” scripting, with quoting pure Clojure to express some more complicated stuff that doesn’t necessarily belong to the DSL language. Cool.

ClojureDocs - clojure.core/group-by And just when you were abandoning all further attempts and accepted to use a fairly understandable “reduce” here comes the group-by. The name speaks quite clearly: give it a list of maps and a key and group-by will group those maps by the value of that key. The reduce is still there in the sources but handed gracefully and with an eye on performances by the standard library. If you open the sources you’ll see that it is assoc! a transient map to build up results and make it persistent at the end.

More Open-Source Clojure Systems, Please uSwitch is a neat Clojure shop in London and they recently decided to share some of the goodies they are producing over there. This post also illustrates a few of the Clojure infrastructure best practices and tools they adopted, including a component system, riemann monitoring and much more. The post is also an invite for all the other Clojure shops to open-source more of their work. I couldn’t agree more. At the Dailymail I started taking care of this part a little more and open sourced the first of a series of libraries/tools that are part of our daily practice. But we still have a lot to do in this direction. Stay tuned and share more.

ClojureDocs - clojure.core/comment comment is a macro that ignores the given body and returns nil. When comment is used in normal code it still needs to go through the reader before macro expansion inside the compiler when it is finally yielding nil. This has the important consequence that what is enclosed in a comment needs to be well formed, at least for the syntax checking that the Clojure reader is applying. For example the following: (comment {:a a :b}) won’t pass the MapReader check, because the reader knows nothing about the behaviour of the comment macro. The #_ reader macro ignores the next form and doesn’t force any compiler step, so it is usually a better choice.

Comments (View)
June 12, 2014

Clojure Weekly, Jun 12th, 2014

Welcome to another stellar issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

how is it possible to intern macros in clojure? - Stack Overflow Interning is the operation of storing a new symbol to var mapping pair in a namespace instance. The var can point to a function or a macro or something else. After interning the new symbol starts to work exactly like any other created using def/defn. Interning can be useful when the definition is done at runtime rather than compile time (a special case indeed, but similar to what is called meta-programming in other languages). This stack overflow question was answered to understand what to do in case of a macro, which turns out to be just some metadata away. The interned macro is then used in the context of the namespace it was defined into.

Automated Browser-based Testing with Clojure — An Architect’s View When the time will come to have some browser automation covering the main feature of our app, I want to be ready. I’m very reluctant to have a comprehensive suite of browser based tests and make it part of a top-down process, but I’m happy to have a sanity automation click-around that tells me if something important is severely damaged. It looks like Gregoire’s clj-webdriver is that nifty lib, a Selenium WebDriver wrapper that can be used easily from Clojure. This post by Sean Corfield explains and to set it up.

ClojureDocs - clojure.core/with-redefs with-redefs is the less sophisticated binding cousin. It changes the var root of a var for all the executing threads instead of being selective as binding is. It does this to all vars, those marked :^dynamic and those that are not. This brutal approach doesn’t have a lot of application in normal code, since it implies a global state change that other portion of the code might not be aware of. This is the reason why it is preferable to binding to mock out a function in testing. with-redefs will operate as expected even in case where tests are concurrent.

ClojureDocs - clojure.core/not-empty This little function seems useless but it enables better idiomatic Clojure. not-empty on a collection returns nil when the collection is empty. As we know, Clojure collection emptiness does not equal nil, that is (= nil []) is false. But (= nil (not-empty [])) is true. Why would you need that? To enable when-let forms on collections. If a function needs to create/process a collection first thing and only proceed if there is at least one element in the collection (maybe doing expensive stuff) (when-let [mycoll (not-empty (fetch-elements))]) only evaluates when there is something in the collection.

arrdem/oxcart Oxcart is another (GSoC) attempt to speed-up Clojure at the price of a reduced or removed dynamicity. It is a Clojure rewrite of the reader, analyzer, emitter triad that compared to the tools.* approach doesn’t seek Clojure compliance (other than the pure runtime). Compared instead to Alexander Yakushev’s Skummet or the Rich’ fastload branch, this is written in Clojure while the formers are taking it from the current Java implementation. Several interesting ideas in this project, but mainly the compilation of functiond belonging to the same namespace to a single class (instead of a class per function) or the entire program to a single class, thus allowing drastic optimisations once the entire requirements in term of bytecode are all collected in the same place.

clojure-classes/graph-w-legend.png at master · Chouser/clojure-classes Another great class diagram by CHouser. It’s from 2009 but it’s still a great “getting-around” reference considering the amount of classes and their relationship in Clojure core.

Comments (View)
June 3, 2014

Clojure Weekly, June 3rd, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

fastload Branch Commits · clojure/clojure Glad to see Rich is back working on speedup of Clojure. There are many people at the moment working on improving Clojure bootstrap. Maybe the trigger for this is that as the Clojure projects grow in size it is more and more difficult to deal with a fast feedback loop, even with a REPL and components frameworks. Another big demand is coming from mobile, where Clojure can be a compelling language to work with.

Clojure Cheat Sheet (Clojure 1.3 - 1.6, sheet v13) An enhanced version of the official with added popup tooltip and search box! The cheatsheet is quite useful to have a glance of the standard library functions grouped by functionality type. With this one you just hover over a function to see the docs and typing in the search box will filter down the list. Thanks Andy Fingerhut for posting this in the group list.

ClojureDocs - clojure.core/vector-of Vector-of creates a Vector, one of the Clojure data structures we are used to with [] that is using primitive types underneath. I couldn’t find compelling examples or decent documentation so I’ve opened up the sources. gvec.clj is offering a PersistentVector behaviour implemented on top of native Java arrays, when is using Object[] as a node instead. In that sense gvec is a translation of to Clojure, with primitive types as leaves (of the trie). When to use? Performances. Use vector-of when a persistent data structure is still important (because if not, you could just go transient or even int-array and friends). Of course you need to be sure you’ll never store anything else than a primitive type in it, that now that I think about it, it happens quite often to me.

ClojureDocs - clojure.core/pmap pmap is a dead easy way to parallelise a map operation in Clojure. It comes with trade-offs you really want to be aware of, before it’s too late. The model assigns each element of the map to a future, where the map operation will take place. Pmap is not a good idea for big collections and fast map operations, since at that point any possible speed gain will be overtaken by the creation of threads. For more big data things, reducers are a better solution.

ClojureDocs - clojure.core/with-meta Metadata in the form of a map can be attached to symbols or collections. Metadata are mainly designed to pass semantic information down to the compiler phases, so there is a list of them with a special meaning that is used by the clojure internals. Metadata can also be used by library or framework providers, to mark functions (symbol-Var pairs pointing to functions) for example for testing. Of course more creative use is possible, but implementing business logic as metadata is possibly a bad idea (ask yourself why that information needs to be hidden instead of being part of the code contract). With-meta is the extended form, but the reader macro ^{:doc “How obj works!”} is what you’ll probably most often see.

ClojureDocs - clojure.core/symbol The symbol fn takes a name or a ns name pair and return a new instance of clojure.lang.Symbol .There is no global table of created Symbols like what happens for Keywords instead, so every time you invoke (symbol “blah”) you always get a different (in the Java sense of object reference) symbol instance. If we are talking about equality instead, they just need to have same name and namespace, so: (= (symbol “asdf”) ‘asdf (clojure.lang.Symbol/intern “asdf”)) are all equivalent ways to express equivalent symbols. Symbol main purpose in Clojure is to pair up a name and a namespace and be used to lookup “things” like Vars. You can even invoke them! (‘+ #{‘+ ‘- ‘* ‘/}) will lookup itself in the set.

Life: Nasty, Brutish, and Short I know, couldn’t resist. No clojure here, but this is where you can get with APL on a typical matrix-based problem like the Game of Life. I don’t understand a line, but the explanation is fascinating nonetheless. The article explores APL solution to the Game of Like from the 1970 onward, with the goal of finding the shortest. A golf-programming exercise at the end, but an entertaining one. The final version is 9 tokens.

Comments (View)
May 29, 2014

Clojure Weekly, May 29th, 2014

Welcome to another issue of Clojure Weekly! Here I collect a few links, normally 4/5 urls, pointing at articles, docs, screencasts, podcasts and anything else that attracts my attention in the clojure-sphere. I add a small comment so you can decide if you want to look at the whole thing or not. That’s it, enjoy!

Functional Geekery Episode 9 – William E. Byrd Enjoyed listening to this episode of the Functional Geekery podcast (and all the others by the way). I had the pleasure to attend a couple of pair-talks by Wll Byrd and Daniel Friedman and appreciated their style presenting dense topics with a bit of humour. I’m fascinated by logic programming and what you can achieve declaratively. I think the big jump from FP to logic happens when you stop thinking about input and output as two different things. In logic programming you can very well feed the output of a function (or the output evaluation of a compiler) back as input and generate a set of all the solutions that can produce that output. William also remembers us that despite not conquering the entire world, logic programming has found specific niches where it has no rivals, like embedded query engines like the datalog engine in Datomic.

Session — Erlang, Lisp and Haskell — Medium Session is a REPL on steroids, an all-evaluable Clojure scratchpad that remembers LightTable but also allow for graphics and other fancy output, not just text. It is backed by a Datomic database, so sessions are persistent and stored. It uses some other fancy new tech like Om and designed to be extensible and modular (such as, replace the rendering engine if you need to). One application that comes into mind is creating custom editors for specific DSL, replacing the need of editing configuration files for example.

How Clojure works: a simple namespace : Deep Blue Lambda This is probably the best article so far of the series “clojure internals”. It explains what happens in case of a bare bone new namespace declaration. One of the most interesting facts is that a new namespace always trigger first thing a push of a new class loader into the thread bound table of Vars. Translated it means that from that moment on, all the functions declaration that will follow in the namespace will be loaded by a new instance of DynamicClassLoader custom class loader. I suppose this is a wise decision, since the dynamicity of Clojure will allow me to redefine functions at anytime in that namespace, resulting in a class being thrown away and a new class being generated and loaded. The DynamicClassLoader contains a weak reference cache that makes this process easier. Not sure about all the details yet, but very interesting stuff.

MailOnline/s-metric Quick and hopefully useful self-promotion. This little library implements a couple of easy algorithms for string matching and scoring. The typical use case is to compare a first string to another one and see how visually similar they are. For this the “naive” implementation presented here can be sufficient. But string matching theory is way more complicated than this :) so other interesting algos will be added soon. Clojure here shines for quick implementation of fairly complex recursive behaviour. If you need to push performances to the next level though, it takes some more Java knowledge and pre-processing with useful data structures.

Getting Started with Textmate | Clojure Project | Assembla Linking here another piece of abandoned Clojure history. The Assembla wiki was adopted some point in 2009 and then abandoned to move under the umbrella. There is not a lot there, except a few design scratch pad about some of the Clojure features built at that point. The page about the clojure compiler in clojure is a summary about some of the desired features of a a new compiler, nowadays tools.analyzer and friends.

ClojureDocs - clojure.core/take-while take-while is often the answer to the question “how do I cut short a loop” for people coming from a Java background. The lazy way to “cut short” can be implemented with a take-while that stops a sequence the first time the given predicate becomes true. It can be used perfectly fine with the for comprehension (which is just another way to create a lazy sequence) without the need for a “break” construct.

galdolber/clojure-core-java Quite an interesting investigation project from the same author of clojure-objc. This is what happens if you take a very simple Clojure hello world, even just a namespace declaration and AOT compile it. You’ll see a bunch of classes are generated. This project is the correponding Java source for the byte code that Clojure generates. By no mean this should be used, but it gives an impression of what is going on under the hood. You can obtain similar results by decompiling Clojure, but this is already done for you if you need a quick glance.

Comments (View)