clojure

Let over lambda block-scanner in clojure

I have just start reading Let over lambda and I thought I would try and write a clojure version of the block-scanner in the closures chapter. I have the following so far: (defn block-scanner [trigger-string] (let [curr (ref trigger-string) trig trigger-string] (fn [data] (doseq [c data] (if (not (empty? @curr)) ...

apply first of a list of functions in Clojure

if i have a list of functions: (def lst '(+ -)) and i wish to apply the first of that list (+) to a list of numbers, i would think its (apply (first lst) '(1 2 3 4)) but apparently i am wrong? syntax mistake i assume. how do i do this? PS: =>(first lst) + =>(apply (first lst) '(1 2 3 4)) 4 both return without...

Importing clojure functions from jars

I'm playing around with Clojure, and I can't figure out how to import a function from clojure-contrib.jar. Working from this answer, I'm doing the following: Running the REPL like so: java -cp clojure.jar:clojure-contrib.jar clojure.main Then trying to import a function: user=> (use '[clojure-contrib.duck-streams :only (writer rea...

Tree traversal with corecursion

I'm trying to figure out corecursion in Clojure with nontrivial (i.e. not Fibonacci), but manageable, examples. Apparently it is possible to implement binary tree traversal with corecursion. Wikipedia has an example in Python which I am unable to understand. How can I implement it in Clojure? Let's say I'm looking for BFS, but it could ...

How to set configuration parameters in clojure library?

I am writing a Clojure library and I am wondering what is the best practice for setting configuration parameters of a library. Many libraries (like those in clojure-contrib) use global level parameter like *buffer-size* which the user can set by calling set! on them. But this does not seems to be best way to me as it creates a global s...

Location of generated class files when used in clojure repl

When I enter (use 'some.namespace) in the Repl, the corresponding clojure file is compiled and loaded. Are the compiled class files stored on the file system, or they only reside in the memory? The Repl is started from the command line, no editor/IDE is involved. ...

Clojure's :gen-class and double arrays

I am attempting to :gen-class a fn which takes a 2D array of Doubles as input. I have already seen the post and solution here concerning a similar topic, but I am still unable to produce a working solution. (ns gui.heatmap (:gen-class :name gui.Heatmap :methods [[heat-map2 ["[[D"] org.jfree.chart.JFreeChart]])) (defn foo [dbl...

How do I multiply all elements in one collection with all the elements in another collection?

Say I have: (def s1 [1 2 3 4 5]) (def s2 [1 2 3 4 5]) For every x in s1, I want to multiply it with every y in s2. To clarify, I basically want the Cartesian product, so I don't think map works here. ...

GUI in Scala/Groovy/Clojure

Last time I had to deal with Java was 2005 and I forgot almost everything about it since then. Today I need to build a GUI app on the top of Java. I guess it is better to use one of Scala/Groovy/Clojure languages. The question is: which of them is better for desktop GUI programming? My program will transform and display a series of jpe...

Comparison of Clojure web frameworks

There are a few web frameworks for Clojure Compojure Webjure Conjure Moustache and also some libraries for dealing with certain web development subtasks, such as Enlive for templating Hiccup for templating Ring to handle lower level stuff with requests/responses ClojureQL for persistence (it doesn't seem very active, though) Ther...

Using 3rd party java libraries, like com.jcraft.jsch, with clojure

I'm experimenting with clojure and am trying to get a feel for using 3rd party libraries. I've been able to download some source, bundle it into a jar file with leiningen, put it in my classpath and (use 'lib.etc) in my script. I've also played around with the objects in java.lang.*. I haven't had any success with 3rd party java, th...

Using Clojure deftype as a parameterized function

I am trying to use clojure in a compiler and thus need to parameterize calls to deftype; however, I am having difficulty making the type hints carry through. Consider the following code: (defn describe [x] (let [fields (.getDeclaredFields x) names (map #(.getName %) fields) types (map #(.getType %) fields)] (inte...

clojure vs. Ruby

I'm ASP.NET developer. I want to learn web development technologies and other languages than Microsofts. I heard about two languages but I don't know which one is better or how to favor one over the other especially that clojure is new somehow. Could anyone help me about why to choose one of them over the other?. Thanks. ...

Fast graphing library

I've been using Incanter for my graphing needs, which was adequate but slow for my previous needs. Now I need to embed a graph in a JPanel. Users will need to interact with the graph (e.g. clicking on certain points which the program would need to receive and deal with) by dragging and clicking. Zooming in a out is a must as well. I'...

Why doesn't Clojure let me define zero-padded numbers?

I'm trying to bind the following grid to a symbol (def grid [08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 ...

Clojure - named arguments

Does Clojure have named arguments? If so, can you please provide a small example of it? ...

Running clojure and other lisp at the same time on emacs.

I use Aquamacs, and aquamacs is pre-equipped with slime. (setq inferior-lisp-program "/usr/local/bin/sbcl") #####!!! (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME/contrib") (add-to-list 'load-path "/Library/Application Support/Aquamacs Emacs/SLIME") (require 'slime) (slime-setup) As is asked in here, I tr...

How do I access the app engine admin interface when loading jetty in the Clojure repl

Is there a way to get to the admin interface if I'm not using the dev_appserver.sh script and instead loading up jetty myself? I'm doing this so that I can use the Clojure repl during development. While my application works as expected, there is nothing handling the /_ad/admin requests and so I can't get to the data store viewer or look...

What are the good things about slime?

As I asked here, I couldn't make it run Aquamacs/slime/clojure, but I could use Auqamacs/clojure with 'M-x conjure-mode', then C-c C-z (run clojure) and C-c C-e (run expression). I don't have an experience with SLIME, but I feel that C-c C-z and C-c C-e is just enough for lisp/conjure REPL or debugging. What features SLIME has more th...

Running clojure with 'lein swank' on Aquamacs problem.

I stalled leiningen and run lein swank. sudo lein deps lein swank Aquamacs has everything about SLIME, so it's OK. Solution to this problem David helped me to be out of trouble. As Aquamacs has built-in slime, I didn't need anything complex about the setup. I just needed one line - (slime-setup '(slime-repl)). ...