I’ve heard newcomers to Clojure ask how to get started with functional programming. I believe that learning to program in the functional style is mostly a matter of practice. The newcomer needs to become familiar with a handful of higher order functions, and how they are used in common idioms. This can be done by [...]
Archives for languages
Tree reparenting
Chris Houser contributed the very pretty problem 130 to 4clojure. I won’t repeat the problem statement here, just my thoughts on how to approach the problem, and my solution. The strategy is to decompose a complex task into a sequence of simpler tasks. The complex task is to transform a tree: we are given a [...]
A simple parallel computation
The 2 June 2011 issue of The Economist contains an article on parallel programming. The article points out what is obvious to some, mostly because they have learned it the hard way. You might expect a six-core machine to be six times faster than a machine with a single-core microprocessor. Yet for most tasks it [...]
map, mapp, and mapc
In a 1988 paper called Algebraic Identities for Program Calculation, Richard Bird wrote: Probably the most useful law about map is the fact that it distributes over functional composition: (map f) . (map g) = map (f . g) Bird’s paper predates Haskell, and instead uses a language called Miranda, but Haskell later adopted very [...]
I’m smiling today
Whenever I start a Leiningen project, I always want to add the same couple of dev-dependencies to the project file: swank-clojure and Marginalia. Being the lazy sort, I got to wondering whether there was some way to configure lein to automatically add user selected dev-dependencise as part of the new task. I googled for an [...]
The transpose function
I am going to discuss a function I think belongs in the Clojure core language. The function is called transpose. It is defined as follows. (defn transpose [xs] (apply map vector xs)) Here is what it does: user> (def m [ ['a 'b 'c 'd] [1 2 3 4] ]) #’user/m user> m [[a b [...]
Free, as in beer
I want to tell you a few of the reasons why you should come out to the TriClojure Monthly Meetup next Monday (5/2/11) at 7:00pm. First: location, location, location. We’ll be meeting at the mothership of Clojure goodness in the RTP area, the offices of Relevance, Inc. I’ve been there, and let me tell you, [...]
Cracker Barrel puzzle
A recent posting to the Trifunc group invited the members to solve the Cracker Barrel puzzle. Brian Adkins, the author of the challenge, posted a solution in Haskell. Here is my Clojure solution. The game is played on a triangular board with 15 holes, labeled 0 through 14. Initially, 14 of the holes contain pegs, [...]
A thread safe fsm?
Today I wanted to play around with building a small thread-safe finite state machine. I’m mostly interested in the thread safety angle, so the machine is kept extremely simple. Clojure’s protocol feature turned out to be just what the doctor ordered. The fsm consists of three things: the current state, the input alphabet, and a [...]
Clojure Programming Studio: a review
On Sept 13-15 I had the pleasure of attending the Pragmatic Studio’s Clojure Programming course in Reston, VA. This is a brief review. First, the external elements. The course was held at the Learning Tree Reston Education Center. The facility was spacious, modern, and well run. There was good food, plenty of drinks and snacks, [...]
Posts