clojure

Type hinting not enforced in defrecord constructors

I created a type using defrecord with type hints for the fields. However, I found that these type hints are not enforced in the constructors and I am able to do some strange things with them. Look at the snippet below for example: user=> (defrecord Person [#^String name #^Integer age]) user.Person user=> (seq (.getConstructors Person)) ...

clojure: adding a debug trace to every function in a namespace?

just started using log4j in one of my home-projects and I was just about to break out the mouse and cut-and-paste (trace (str "entering: " function-name)) into every function in a large module. then the voice of reason caught up and said "there has simply got to be a better way"... I can think of making a macro that wraps a whole block ...

How do I pass variables as variable names to a function?

I want to be able to do the following pseudocode: Pass in symbol a. Pass in symbol b. Pass in an expression using a and b As I change the value of a and b, print the output of c at each moment. Ideally, I would like the signature to look like: (runner a b (+ a b)) but I'm not sure that I'm approaching this correctly... I've tried ...

Why do Java programmers love Scala and shy away from Clojure?

I've just started to learn Clojure by reading some tutorials and watching every presentation by Rich Hickey, and I'm totally impressed by the language... so different from any C-like language (actually any language I've seen so far), yet so elegant... So I started to wonder... why is everyone so thrilled by Scala but not by Clojure? Is i...

Partitioning in clojure with a lazy collection of strings

Starting with a collection of strings like: (def str-coll ["abcd" "efgh" "jklm"]) The goal is to extract off a specific number of characters from the head of the string collection, generating a partitioned grouping of strings. This is the desired behavior: (use '[clojure.contrib.str-utils2 :only (join)]) (partition-all 3 (join "" str...

Trouble with this macro

Embarrassingly enough, I'm having some trouble designing this macro correctly. This is the macro as I have it written: (defmacro construct-vertices [xs ys] (cons 'draw-line-strip (map #(list vertex %1 %2) xs ys))) It needs to take in two collections or seqs, xs and ys, and I need it to give me… (draw-line-strip (vertex ...

'leiningen' related commands too slow with Mac OS X.

I installed and run lein, but it seems to slow on My Mac (10.6.4). Running 'time lein help' gives me real 11m8.674s user 0m54.297s sys 1m32.621s I tried once more. real 15m25.560s user 1m36.087s sys 2m52.745s What's wrong with this? Is anyone experiencing similar problem? Is there anyway to check what's the problem?...

Uninstall/Reinstall leiningen(clojure server) related issues.

As I asked and answered here, I found that running 'sudo lein deps causes some problem that forces me to run 'sudo lein swank', which is annoying. And I was told not to use sudo. I use Mac OS X 10.6.4. So, I'll try to uninstall and reinstall leiningen. Uninstalling leiningen Removing ~/.m2 directory is just uninstall, is this correc...

Race condition (?) when using Swing

I've moved on from trying to use OpenGL through Penumbra to trying to draw directly on a JPanel using its Graphics context. This would be great, except I'm running into some trouble… I compile my code, and ~1 time out of 25, the graphic (it's a rectangle for the example) draws just fine. The other ~24 times, it doesn't. Here's my code...

What is the most performant lisp on the JVM

What is the most performant (fastest) lisp implementation on the JVM? By lisp implementation I consider all implementations of any language in lisp family, like Common Lisp, Scheme, Clojure, ... I know that Clojure can be made pretty fast using type hints, that ABCL is in general not considered to be fast. I don't have experience using ...

How to compile file in clojure.

I've created file "hello.clj" (ns clojure.examples.hello (:gen-class)) (defn -main [greetee] (println (str "Hello " greetee "!"))) and try to compile clojurec hello.clj But I got this error Exception in thread "main" java.io.FileNotFoundException: Could not locate hello/clj__init.class or hello/clj.clj on classpath: ...

How do I dynamically load a Clojure script from outside of my classpath from java?

I wish to enable user defined Clojure scripts to interact with my Java App. The problem is, I don't know in advance where the Clojure scripts will be located, so I can't include them in my classpath when running the app. How do I dynamically load a Clojure script from outside of my classpath? I've tried the simple example: RT.loadReso...

How to create a lazy-seq generating, anonymous recursive function in Clojure?

Edit: I discovered a partial answer to my own question in the process of writing this, but I think it can easily be improved upon so I will post it anyway. Maybe there's a better solution out there? I am looking for an easy way to define recursive functions in a let form without resorting to letfn. This is probably an unreasonable reque...

Postorder tree traversal with clojure.zip to edit nodes

I have a tree represented as a nested vector. I want to have a generalization of indexed for trees, showing the index of each node like this, (visit 42); => [0 42] (visit [6 7]); => [0 ; [[0 6] ; [1 7]]] The naive implementation would use clojure.zip directly (as already asked here) (defn visit [...

Closure's (apply str) questions?

With closure (apply str [\a \b]) and (apply str '(\a \b)) returns "ab". (apply str (\a \b)) returns an error. Why is that? ...

clojure classpath problem for (require) function?

CLASSPATH has the "/Users/smcho/Desktop/clojure" as one of its path, and this directory has the file hello.clj. Running clojure, and running (require 'hello) give this error message. java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: (NO_SOURCE_FILE:0) When I change directory to "/Users/......

emacs slime-connect version of clojure doesn't lookup the $CLASSPATH

I need to use my clojure functions with slime-connect. And I put all my libs in the $CLASSPATH. As I learned from this question. I used the following command to check the CLASSPATH for current environment, and I found none of my $CLASSPATH is used. How can I attach my class path for my clojure with emacs/slime-connect? I installed my...

conjoin function of clojure question.

conj is used in (conj coll item), for example (conj #{} "Stu"). But, I found this example in 'Programming Clojure' book page16. (alter visitors conj username) I guess (conj visitors username) would be the correct usage. What's the secret? ...

Zipping Collections

How do you zip two sequences in Clojure? IOW, What is the Clojure equivalent of Python zip(a, b)? EDIT: I know how to define such a function. I was just wondering whether standard library provides such a function already. (I would be *very* surprised if it doesn't.) ...

Why do I get an error when I run (use 'clojure.contrib.repl-utils)?

I found that I can use Chris Houser's repl-utils library (clojure.contrib.repl-utils/source or show) for poking into Java by reading Programming Clojure book page 20. I searched the web and downloaded the 'clojure-contrib.jar', and set it as a part of classpath. The problem is I can't run the following command (use 'clojure.contrib....