I'd like to have a small (not doing too damn much) daemon running on a little server, watching a directory for new files being added to it (and any directories in the main one), and calling another Clojure program to deal with that new file.
Ideally, each file would be added to a queue (a list represented by a ref in Clojure?) and the ...
I have an XML file with format similar to:
<root>
<baby>
<a>stuff</a>
<b>stuff</b>
<c>stuff</c>
</baby>
...
<baby>
<a>stuff</a>
<b>stuff</b>
<c>stuff</c>
</baby>
</root>
And a Clojure hash-map similar to:
{:a "More stuff" :b "Some other stuff" :c "Yet more of that stuff"}
And ...
The library in question is Tokyo Cabinet.
I want is to have the native library, JNI library, and all Java API classes in one JAR file to avoid redistribution headaches.
There seems to be an attempt at this at GitHub, but
It does not include the actual native library, only JNI library.
It seems to be specific to Leiningen's native dep...
Hi,
I'm looking for an idiomatic way to get dynamically scoped variables in Clojure (or a similar effect) for use in templates and such.
Here is an example problem using a lookup table to translate tag attributes from some non-HTML format to HTML, where the table needs access to a set of variables supplied from elsewhere:
(def *attr-t...
I may have missed the whole point about protocols but my question is, can protocols be used to dictate how to iterate a custom data structure or how println would print the object?
Assuming a map with two vectors,
{:a [] :b []}
When called first on it I would like to take from the :a vector but when conj on this structure i would lik...
I am looking through some example Fibonacci sequence clojure code:
(def fibs (lazy-cat [1 2] (map + fibs (rest fibs))))
I generally understand what is going on, but don't get the point of lazy-cat.
I know that lazy-cat is a macro that is translating to something like this:
(def fibs (concat (lazy-seq [1 2]) (lazy-seq (map + fibs ...
If I call (shutdown-agents) from the REPL, and then later on try to use an agent later on, I get an exception saying the agent pool isn't available (of course!). The question is, how can the agent thread pool be re-started without having to re-launch the REPL and lose all of my state?
Thanks!
...
Hi,
I'm a starter with Emacs (but quite experienced Vim user) and trying to play with Emacs+Clojure combination. Maybe my setup will be unusual for Emacs world, as I'm not using SLIME/swank-clojure, but Emacs + eshell with running clojure REPL in it, mostly due simplicity (or probably because SLIME quite scares me off :D).
So, maybe th...
I am trying to write a simple sieve function to calculate prime numbers in clojure. I've seen this question about writing an efficient sieve function, but I am not to that point yet. Right now I am just trying to write a very simple (and slow) sieve. Here is what I have come up with:
(defn sieve [potentials primes]
(if-let [p (firs...
As a neophyte clojurian, it was recommended to me that I go through the Project Euler problems as a way to learn the language. Its definitely a great way to improve your skills and gain confidence. I just finished up my answer to problem #14. It works fine, but to get it running efficiently I had to implement some memoization. I could...
I would like to have a macro which I'll call def-foo. Def-foo will create a function, and then will add this function to a set.
So I could call
(def-foo bar ...)
(def-foo baz ...)
And then there would be some set, e.g. all-foos, which I could call:
all-foos
=> #{bar, baz}
Essentially, I'm just trying to avoid repeating myself. ...
I'm trying to extend a Java Swing component in Clojure, i.e. I want to extend a javax.swing.JComponent and add some custom methods implemented in pure Clojure in addition to all the standard inherited methods.
I've tried using "proxy" which works great if I just want a single instance (in the same way as an anonymous inner class). Howev...
I'm trying to figure out how I can manage my log4j.properties file with leiningen. I'd like to be able to automatically include the file in the jars that lein creates as well as have the properties file be accessible to "lein swank" (and lein repl).
Right now I have the file in my project "root", but I get this error when I using loggi...
I'm working on some Java / Clojure interoperability and came across a reflection warning for the following code:
(defn load-image [resource-name]
(javax.imageio.ImageIO/read
(.getResource
(class javax.imageio.ImageIO)
resource-name)))
=> Reflection warning, clojure/repl.clj:37 - reference to field read can't be res...
Hi;
What would be an ideomatic way in Clojure to get a lazy sequence over a file containing float values serialized from Java? (I've toyed with a with-open approach based on line-reading examples but cannot seem to connect the dots to process the stream as floats.)
Thanks.
...
Say I have a sorted-set of integers, xs, and I want to retrieve all the integers in xs that are [x, y), ie. between x and y.
I can do:
(select #(and (>= % x) (< % y)) xs)
But this is inefficient - O(n) when it could be O(log n), I expect the number of elements returned to be small. Using take-while and drop-while would let me exit on...
I want to construct a macro that, given a symbol 'foo, creates a method called foo*. How can I concatenate 'foo and '*?
...
The code below doesn't behave as I would expect.
; given a function name, its args and body, create 2 versions:
; i.e., (double-it foo []) should create 2 functions: foo and foo*
(defmacro double-it
[fname args & body]
`(defn ~fname ~args ~@body)
`(defn ~(symbol (str fname "*")) ~args ~@body))
The code abo...
I had never really thought about whether a symbol could be a number in Lisp, so I played around with it today:
> '1
1
> (+ '1 '1)
2
> (+ '1 1)
2
> (define a '1)
> (+ a 1)
2
The above code is scheme, but it seems to be roughly the same in Common Lisp and Clojure as well. Is there any difference between 1 and quoted 1?
...
My answer to this problem feels too much like these solutions in C.
Does anyone have any advice to make this more lispy?
(use 'clojure.test)
(:import 'java.lang.Math)
(with-test
(defn find-triplet-product
([target] (find-triplet-product 1 1 target))
([a b target]
(let [c (Math/sqrt (+ (* a a) (* b b)))]
(let [s...