Posts Tagged ‘clojure’

Gunzipping files with Clojure

Posted: February 17, 2012 in Clojure, Lisp
Tags: ,

This is just a quicky that might be useful to others, too. The following function unzips the input to the output. Update: As Ben pointed out, tis will only work correctly for gzipped text files encoded in UTF-8 as input (ASCII, ISO-5589-1 will also be fine). (ns foobar (:require [clojure.java.io :as io])) (defn gunzip [fi [...]

With a lot of help from Ambrose, I managed to make Clojure’s core.logic library work with my custom Java data structures. In this posting, I’ll explain the code.  I assume that you are already familiar with Clojure in general, and you know core.logic and relational programming at least from a user’s point of view. Ok, [...]

defmacro! revisited

Posted: September 28, 2011 in Clojure
Tags: ,

In my last post, I’ve introduced the defmacro! macro, which is just like defmacro, except that it guarantees that all of the arguments are evaluated once only. However, in contrast to Doug Hoyte’s defmacro! he introduced in Let over Lambda, my macro expanded into a normal defmacro form that expanded into a form where all [...]

Once-only evaluation for Clojure macros

Posted: September 23, 2011 in Clojure
Tags: ,

When programming macros, it’s often desired to have its arguments evaluated only once. Let’s have a look at a simple example: user> (defmacro square [x] `(* ~x ~x)) #’user/square user> (square 5) 25 At a first glance, it seems to work. But see what happens here: user> (def c (let [a (atom 4)] #(swap! a [...]