I have a symbol "a" bound to a function:
(defn a []
(println "Hello, World"))
user=> a
#<user$a__292 user$a__292@97eded>
user=> (a)
Hello, World
nil
Then I use syntax-quote, it "resolves the symbol in the current context, yielding a fully-qualified symbol", according to Clojure documentation. But why can't I use it the same w...
(defmacro nif [expr pos zer neg]
'(condp = (Integer/signum ~expr)
-1 ~neg
0 ~zer
1 ~pos))
I get this error.
1:1 user=> #<Namespace Chapter7Macros>
1:2 Chapter7Macros=> (nif 1 (+ 2 2) (- 2 2) (- 3 2))
1:3 Chapter7Macros=> java.lang.Exception: Unable to resolve symbol: expr in this context (repl-1:57)
...
I have the a list in clojure, and (due to the underlying java library) must modify the list (using the iterator's remove method). Is there a more elegant way to get this effect in closure than writing a destructive equivalent of (map fn seq)?
...
I was practicing writing macros and I can't seem to get defn to work.
My syntax is: (my-define name parameter body)
Ignoring & parameters and recursive routines, How do I bind the name to a (fn[parameter] body)?
...
What would be the best way to implement a bi-directional map in clojure? (By bi-directional map, I mean an associative map which can provide both A->B and B->A access. So in effect, the values themselves would be keys for going in the opposite direction.)
I suppose I could set up two maps, one in each direction, but is there a more idi...
I am trying to get a list of all the photo sets in my account. I gave my application write access i can verify this has write access by creating an photo set but when ever i try to read the list i only get my public lists not my privates.
(def flickr (new Flickr api-key shared-sercret (new REST)))
(defn get-photo-sets [ ]
(let [;p...
I'm trying to write a function to play a sound file once, using some resources I found. The code is as follows:
(defn play [file]
(let [songp (URL. (.getCodeBase) file)
song (.newAudioClip songp)]
(. song play)))
The problem is, (.getCodeBase) is a malformed member expression. I'm not sure what to do. How do you call a meth...
How do I comment multiple lines in Clojure?
...
I'm trying to programatically load some clojure libraries to make a simple auto-test program.
What I end up sending to require is this
(require :reload '("peg" "test.peg-test"))
How do I transform that list into something useful, or am I totally barking up the wrong tree?
...
I can not find any info on how to parse xml documents and access elements.
I have found two ways to parse the xml document
(clojure.zip/xml-zip (clojure.xml/parse file))
and
(parse-seq file)
but i can seem to find any info on how to process the resulting structure?
Source file's refers to zip-query.clj on how to query the result...
When in practice should I use letfn vs. let for defining local functions?
What about cases where I want both local functions and local not-functions?
...
I'm trying to migrate from a custom designed blog software system to a WordPress.com site. I can access my MySQL database of posts and comments without too much difficulty, thanks in part to this post: http://stackoverflow.com/questions/613929/how-do-i-connect-to-a-mysql-database-from-clojure.
I think my next step is to generate the ps...
I want to import the entire weka.classifiers.functions package but dont want to import RBFNetwork class.
(ns com.wekatest
(:import (weka.classifiers Classifier Evaluation)
(weka.classifiers.functions)
(weka.core Attribute FastVector Instance Instances)))
Thanks.
Edit: (weka.classifiers.functions) doesnt impor...
In most of the IDEs, I had a Reindent All command. How do I do that in Eclipse 1.2?
Edit: The commands work with Java codes but is there a way I can get it to work with Clojure?
...
I want to keep a list of normalizing functions for a text. How do I store .toLowercase?
I was thinking of something like this:
(def normalizing-functions (list remove-punctuations .toLowerCase))
...
I want to apply a series of tests on my list and make sure that all the tests are passed.
Is there a function similar to "andmap" in Clojure?
...
I wasn't really sure how to phrase the name of this thread, so if you can clarify it any, please do so.
My example code is this:
(doseq [x [1 2 3] y [3 2 1]] (println (str x y)))
The output of that code is:
13
12
11
23
22
21
33
32
31
nil
I understand that list comprehensions, and doseq both evaluate like this. Is there another wa...
I have some structures with nested lazy sequences which read from files. When I'm testing I would like to be able to wrap them in a recursive version of doall to make sure all the data is pulled from the files before the files get closed.
...
I want to perform the following nested operations until the experession is satisfied..
Is there a :until keyword which stops doing further operations when the condition matches.?
This command generates the Pythagoran Triplet 3 4 5. I dont want it to do anything else once it gets to that sequence of numbers.
(for [a (range 1 100)
...
Should I use
(apply + (filter prime? (range 1 20)))
or
(reduce + (filter prime? (range 1 20)))
Edit: This is the source for prime in clojure from optimizing toolkit.
(defn prime? [n]
(cond
(or (= n 2) (= n 3)) true
(or (divisible? n 2) (< n 2)) false
:else
(let [sqrt-n (Math/...