clojure

How to add classpath with emacs slime/conjure?

I setup emacs slime/clojure as written here. When I run (doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p))) to get classpath, I get the following. /Users/smcho/.swank-clojure/clojure-1.1.0-master-20091202.150145-1.jar /Users/smcho/.swank-clojure/clojure-contrib-1.1.0-master-20091212.205045-1.jar ...

Is conjure-contrib.jar not standardized now?

This page introduces a lot of clojure libraries. And this page also comments to consider using the clojure-contrib. Why the clojure-contrib.jar is different in size? The leiningen's clojure-contrib-1.2.0-beta1.jar is 479.2KB in size, but the conjure-contrib.jar that I downloaded from Programming Clojure is 2.9MB. As I explained in here...

Deliberate Clojure symbol name limitations or inherited?

In Common LISP I can do: (setf a1 'a) (setf 1a 'b) In clojure I can do the first (ignoring the fact that setf and def work differently) (def a1 'a) but with the second I get an error (def 1a 'b) java.lang.NumberFormatException: Invalid number: 1a Did Clojure just inherit this limitation from Java, or is it deliberate? (ie you c...

Difference between two maps

I need to very efficiently compare two maps in Clojure/Java, and return the difference as determined by Java's .equals(..), with nil/null equivalent to "not present". i.e. I am looking for the most efficient way to a write a function like: (map-difference {:a 1, :b nil, :c 2, :d 3} {:a 1, :b "Hidden", :c 3, :e 5}) => {:b nil, :c 2...

Extending protocols for custom Java classes, maps and sequences in Clojure

I have created a protocol in Clojure 1.2 that handles my own Java classes and has default handling for a generic java.lang.Object. The code looks something like: (extend-protocol PMyProtocol my.java.ClassName (protocol-function [c] "My Java class result") java.lang.Object (protocol-function [c] "Default object r...

How to setup the classpath when running the jar made from 'lein uberjar'?

I have a hello.clj as follows. (ns hello) (defn hi [] (println "HI")) Normally, I can use this function from main.clj as follows. The hello.clj is in the same directory that contains main.clj. And the classpath includes . (current path). (use 'hello) (hi) How can I use this hello.clj for the 'lein uberjar'? I used 'lein new mypr...

What is your way to do GAE Apps using Clojure?

I want to develop apps on GAE using Clojure with Compojure, using either Eclipse or Idea, emacs is not a bad idea :P So which are the best ways to do this? I don't think that I want to use leiningen because I believe that maven can be very strong if you pass the learning curve - I read this blog http://compojureongae.posterous.com/tag/g...

What principles should I follow to code in PHP with fewer Java-like objects and more similar to Clojure's functional programing principles?

I was introduced to Clojure not long ago, and while I haven't fully assimilated all of it's concepts, It has given me an alternative to Java and PHP's OO that I really want to move towards. I consider Clojure's systems to be my ideal. I know that I want to let it inform my PHP coding style as much as I can. I really don't like OO in P...

Trouble with BufferedImage & ImageObserver in Clojure/Swing/Java

I've been trying for hours to get my drawing method to work by drawing in a BufferedImage stored in a Clojure ref, and then to have that painted onto the component (in this case a JPanel) in order to display it. Unfortunately, this isn't working well at all. My code is this (pared down, but showing the relevant parts: (defn create-gra...

Future promises in Clojure hangs on me

When I run the following code it basically works how I intend it to, except that it hangs after the future is finished. What am I missing - some kind of "close agents/threads" call? How should I do this? (def name-to-greet (promise)) (future (println "Hello," @name-to-greet)) (print "What is your name? ") (flush) (deliver name-to-...

How to run the jar made from 'lein jar' command?

This is a follow-up for this question. After running 'lein jar', I get 'myproject-1.0.0-SNAPSHOT.jar', which doesn't contain the clojure-1.2.0-beta1.jar and clojure-contrib-1.2.0-beta1.jar. And running 'lein uberjar' gives me two jar files. The first one (that ends with -standalone.jar) is the jar contains everything, and the second ...

Purely functional soft heap

Are there any implementations of a purely functional soft heap data structure in any language? ...

Get available clojure namespaces

Is there an idiomatic way to get available namespaces that can be used? (all-ns) returns only already used namespaces. (Package/getPackages) returns all Java packages available for import, but only those Clojure namespaces that are already used. Then I stumbled upon this post, but it uses some classpath magic. So I want to get somethi...

Calling java functions from Clojure

I can use (.toUpperCase "GOOD") in clojure, as "GOOD" is java string, and java string has toUpperCase method. I also can use (java.io.File/separator) from clojure as a way of calling java functions. But, why can't I call (java.lang/Object wait 3) or (java.lang.System/println "hi")? Can't we use all the java functions from Clojure? ...

Handling large datasets in Java/Clojure: littleBig data

I've been working on a graphing/data processing application (you can see a screenshot here) using Clojure (though, oftentimes, it feels like I'm using more Java than Clojure), and have started testing my application with bigger datasets. I have no problem with around 100k points, but when I start getting higher than that, I run into heap...

How do I avoid Clojure's chunking behavior for lazy seqs that I want to short circuit?

I have a long, lazy sequence that I want to reduce and test lazily. As soon as two sequential elements are not = (or some other predicate) to each other, I want to stop consuming the list, which is expensive to produce. Yes, this sounds like take-while, but read further. I wanted to write something simple and elegant like this (pretendi...

clojure resolving function from string name

In clojure 1.2RC1, I wish to obtain a function based on its name as string and evaluate it. Function definition (ns my-ns) (defn mycar [x] (first x)) The following worked: ((ns-resolve *ns* (symbol "mycar")) '(3 4)) ((intern *ns* (symbol "mycar")) '(3 4)) ((eval (symbol "mycar")) '(3 4)) but they seem ugly. Is there a better wa...

Difference in Clojure between use and require

Hi, I recently started learning Clojure and I'm having a bit of difficulty wrapping my head around namespaces. As the creator of Clojure said, newcomers often struggle to get the concept right. I don't clearly understand the difference between (use ...) and (require ...). For example playing around in the REPL if I say (use 'clojure.con...

Issue reading command-line-args in script

Hi all, I'm attempting to write a library to do some domain-specific stuff. I'd like to add some scripts to this library that can be run straight from the commandline. Directory layout: +- project.clj +- src/ | +- my-lib.clj | +- my-lib/ | +- my-sub-1.clj +- scripts/ +- run-command.sh The src/my-lib.clj file loads the...

In php, how can I make a library of functions more cohesive?

I find php's Object Orientation somewhat verbose and unsavory. I love working with the cleanliness of functions, and my ideal is to code in php from as close to Clojure's excellent approach to Functional Programming as can be done & still make sense in php. As I move towards F.P., I've found that it's hard to keep a group of related fu...