Simple explanation of clojure protocols

The purpose of Protocols in Clojure is to solve the Expression Problem in an efficient manner. So, what’s the Expression Problem? It refers to the basic problem of extensibility: our programs manipulate data types using operations. As our programs evolve, we need to extend them with new data types and new operations. And particularly, we … Read more

Lisp in the real world [closed]

Franz, Inc. provides an inexhaustive list of success stories on their website. However: Please don’t assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web … Read more

What is the best way to do GUIs in Clojure?

I will humbly suggest Seesaw. Here’s a REPL-based tutorial that assumes no Java or Swing knowledge. Seesaw’s a lot like what @tomjen suggests. Here’s “Hello, World”: (use ‘seesaw.core) (-> (frame :title “Hello” :content “Hello, Seesaw” :on-close :exit) pack! show!) and here’s @Abhijith and @dsm’s example, translated pretty literally: (ns seesaw-test.core (:use seesaw.core)) (defn handler [event] … Read more

In Clojure, when should I use a vector over a list, and the other way around?

Once again, it seems I’ve answered my own question by getting impatient and asking it in #clojure on Freenode. Good thing answering your own questions is encouraged on Stackoverflow.com 😀 I had a quick discussion with Rich Hickey, and here is the gist of it. [12:21] <Raynes> Vectors aren’t seqs, right? [12:21] <rhickey> Raynes: no, … Read more

difference between use and require

require loads libs (that aren’t already loaded), use does the same plus it refers to their namespaces with clojure.core/refer (so you also get the possibility of using :exclude etc like with clojure.core/refer). Both are recommended for use in ns rather than directly.

In Clojure 1.3, How to read and write a file

Assuming we’re only doing text files here and not some crazy binary stuff. Number 1: how to read an entire file into memory. (slurp “/tmp/test.txt”) Not recommended when it is a really big file. Number 2: how to read a file line by line. (use ‘clojure.java.io) (with-open [rdr (reader “/tmp/test.txt”)] (doseq [line (line-seq rdr)] (println … Read more

Calling clojure from java

Update: Since this answer was posted, some of the tools available have changed. After the original answer, there is an update including information on how to build the example with current tools. It isn’t quite as simple as compiling to a jar and calling the internal methods. There do seem to be a few tricks … Read more