background preloader

Clojure

Facebook Twitter

Counterclockwise User Guide. Clojure by Example. I don’t like reading thick O'Reilly books when I start learning new programming languages.

Clojure by Example

Rather, I like starting by writing small and dirty codes. If you take this approach, having many simple codes examples are extremely helpful because I can find answers to these questions very easily. How can I define a function? What’s the syntax for if and else? Does the language support string interpolation? What scopes of variables are available? These are very basic questions, but enough to start hacking with the new languages. Clojure xmi. Programming Digressions. Languages for the effective, daily practice of the software craft nowadays, I would point to Java and Scala as being absolutely indispensable.

Programming Digressions

At the same time, it's undeniably helpful to have in one's toolbox—programming models, if you will—tools from programming paradigms. I say so because I know full well the inevitability of the need to wield tools from whichever programming paradigm is up to snuff for slaying a particular, wicked problems. With that rather lofty assertion, I submit to you Scala enthusiasts should note that (1) this post is a direct analog of a recent post that has corresponding thoughts on the finest Scala books, and (2) this post on the best Clojure (think Lisp) books is also highly relevant to you.

Allow me to elaborate very briefly: The programmer who has done justice to the notion expressed in the second of the two preceding points—in underscoring the eminent relevance of Lisp to Scala—is David Pollak. With that, let's foray into the land of Clojure... Clojure-cookbook/clojure-cookbook. Functional Reactive Programming in Clojurescript. Clojure Cookbook: XML/HTML Processing - Getting Clojure. Traversing an XML Document Problem How do I work with XML documents?

Clojure Cookbook: XML/HTML Processing - Getting Clojure

Solution. Clojure zippers: structure editing with your mind - josf.info. …​but editable?

Clojure zippers: structure editing with your mind - josf.info

What about modifying the tree, though? What happens then? It turns out that simple edits are simple. Getting acquainted with Clojure zippers - josf.info. One last thing that took a while to sink in: zippers are cheap.

Getting acquainted with Clojure zippers - josf.info

Huet insists on how zippers are supposed to be fast since, in a very clojurey way, only the differences in path and position need to be taken into account, leaving most of the original data intact. In a more concrete way, just looking at a zipper, we see that there isn’t much to them. Here is your data: user> (def your-data [:a :b :c]) #'user/your-data Here is your data in a zipper: It’s just a two-item vector. But still, the data structure is very lightweight, especially when the zipper is at the root position of the tree. I’ll talk about “editing” zippers some other time, but I recently came onto a problem where I wanted to walk a tree several times with different functions each time. ClojureDocs - Community-Powered Clojure Documentation and Examples. Clojure Cheat Sheet (Clojure 1.5 - 1.8, sheet v37) Primitives Numbers Strings Other Collections Collections Lists (conj, pop, & peek at beginning) Vectors (conj, pop, & peek at end) Sets Maps Queues (conj at end, peek & pop from beginning) Relations (set of maps, each with same keys, aka rels)

Clojure Cheat Sheet (Clojure 1.5 - 1.8, sheet v37)

ClojureDocs - Community-Powered Clojure Documentation and Examples. Functional XML editing using zippers in Clojure → pckl.me. Since the Clojure documentation for clojure.zip is so bad I thought I'd walk through an example of editing some XML using a zipper.

Functional XML editing using zippers in Clojure → pckl.me

First off you'll need to add a few dependencies to your project.clj: (defproject zipper-demo "0.1.0" :description "An example app to show how to edit XML in Clojure using Zippers" :url " :license {:name "WTFPL – Do What the Fuck You Want to Public License" :url " :dependencies [[org.clojure/clojure "1.5.1"] [org.clojure/data.xml "0.0.7"] [org.clojure/data.zip "0.1.1"]]) then open up src/core.clj and require them. (ns zipper-demo.core (:require [clojure.zip :as zip] [clojure.data.zip.xml :as zx] [clojure.data.xml :as xml])) So what do they do?

Korny's Blog. "XML is like violence - if it doesn't work, use more" Clojure is awesome for parsing and processing structured data.

Korny's Blog

It has a wide range of functions for handling lists, maps (associative arrays), sets, and (if you really need them) objects. Clojure Documentation. This work is licensed under a Creative Commons Attribution 3.0 Unported License (including images & stylesheets).

Clojure Documentation

The source is available on Github. What Version of Clojure Does This Guide Cover? This guide covers Clojure 1.4 and Leiningen 2.x. Overview Try as you might, XML is difficult to avoid. Parsing NZB files For the purpose of the tutorial I have chosen a simple and fairly well known XML file format: NZB. Let us start by creating a new project (for details on using Leiningen, see this guide: Now edit project.clj to contain the following:

Clear View Training. Clojure for the Brave and True. As you read this hilarious book, you will at some point experience a very serious moment.

Clojure for the Brave and True

It is the moment you admit to yourself that programming is more enjoyable after knowing some Clojure. It is also the moment that your investment in this book, in money and time, comes back to you—with interest. Humor has a certain relationship to seriousness. It is appropriate to joke about serious things, but only after the right amount of time has passed. For example, it took years for me to be able to crack a smile when I remember my favorite uncle’s last words: “Hold my beer.”

This book works in the opposite way. This approach is refreshing because most of the programming books I’ve read are drier than a camel’s fart. Clojure is the topic of this book, but in a way it—or perhaps its creator, Rich Hickey—is also one of the authors, since Clojure is the most elegant programming language ever designed. Since 1958, there have been many Lisps and Lisp books. Alan Dipert. Quil Intro. This is an introductory post about Quil.

Quil is an interactive animation library for clojure. Simply speaking it allows you to draw whatever you want on a rectangular window. Quil provides tons of useful functions for drawing in 2D and 3D. In this post I will show how to create and run Quil sketches. Let's start with something simple: with trigonometry...