(let [a (clojure.core.async/chan)] (case a a :foo :bar)) #=> :bar I would expect :foo here. What am I doing wrong? On the other hand (condp = chan ...) does the job. PS: Basically I am trying to do following thing: (require '[clojure.core.async :as a
In Clojure, when and why does one want to use a named anonymous function? E.g., ((fn add-five [x] (+ x 5)) 3)) In ClojureDocs, one example's comment says that it is useful in stack traces. Can one give an example of that?There are two reasons to name
I have the following data structure (two Vectors of Maps I believe) { :put [{:listId "myList", :entryId "1", :dateTime 1434637074}, {:listId "myList", :entryId "2", :dateTime 1434637075}], :delete [{:listId "my
Is there a fast way to check if a sequence has exactly 1 element in Clojure? Note that a sequence may contain nils. If I'm reading the source correctly, calling count on a sequence takes O(n) time. Alternate solution: (and (not (empty? a-seq)) (empty
How do I get the environment name when using environ in Clojure? I mean, :dev, :test, etc. The reason for wanting this is to pass it to Yeller so when it displays errors it can tell me which environment they happened into. Errors in staging are treat
I am trying to sort a map by a key value. Given this map: {:1 {:bar "something" :rank 10} :2 {:bar "other" :rank 20}} I like to sort it by rank value: {:2 {:bar "other" :rank 20} :1 {:bar "something" :rank 10} } Its
As I understand it, the let keyword, locally binds variables to values (supporting some sort of pattern matching). It receives two arguments. First is a vector with the symbol we want to bind and the value we want bound. Then comes an expression that
The following code (-> (.getField (Class/forName "ccg.flow.processnodes.text.retrievers.Dictionary.Dictionary") "wordsTuples") .getType) tells me that wordsTuples is a java.util.ArrayList. But what I would like to be able to learn i
From http://martintrojer.github.io/clojure/2013/07/07/coreasync-and-blocking-io/ : To get a bit more concrete let's see what happens when we try to issue some HTTP GET request using core.async. Let's start with the naive solution, using blocking IO v
I have looked at the following question: How to add days to current date in clojure. However I am very new to Clojure and I am getting stuck on the following scenario I am getting the timestamp in string format. So I am parsing it using the following
I'm lost in clojure ratio. I can't understand it. Why do the equality and inequality tests behave this way? (= 3/2 1.5) ;; false (>= 3/2 1.5) ;; true (> 3/2 1.5) ;;false (not= 3/2 1.5) ;; true Use == for numerical comparisons where you want to know
I'm a Python developer taking the plunge into Clojure and decided that taking on a real project is they best way to get started (after learning syntax of course). I decided to build a REST API for a project that I'm working on. Things that are worth
Is this a bug or can I fix it somehow? (of course in my live code the similarity number is computed) (sort-by :similarity > (for [ob [:a :b :c]] [:object ob :similarity 0.0])) NullPointerException clojure.lang.Numbers.ops (Numbers.java:961) Using Clo
I have one clj file: ;; stringparity.clj ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (ns stringparity) (defn get-java-string [input] (.getBytes input "UTF-8")) And one cljs file: ;;; stringparity.cljs ;;;;;;;;;;;;;;;;;;;;;;;;;;;; (ns stringparity (:import go
Based on core.async walk through example, I created below similar code to handle some CPU intensive jobs using multiple channels with a timeout of 10 seconds. However after the main thread returns, the CPU usage remains around 700% (8 CPUs machine).
I want to automate running several commands in vim, i.e. by typing :repl. The commands are: :ConqueTerm lein repl <Esc> :set syntax=clojure <i> How do I define a custom vim function (command) that executes the above? About the above: clojure -
So I want to pass a function to the "name" portion of def. The problem is: "First argument to def must be a Symbol" I'm trying to for instance do: (def serverNumber 5) (def (str "server" serverNumber) {:id serverNumber :value
When I eval this code in lighttable: (ns app.core (:require [datomic.api :refer [q] :as d] :reload-all)) (defn add-person [conn id] (d/transact conn [{:db/id #db/id[:db.part/user -1000001] :person/id id}])) I get: clojure.lang.ExceptionInfo: No reade
You know how when you hit the up arrow in bash it will fill in the last command you typed in? Is there any way to do this in nrepl? So far I've been doing a reverse search (C-r), typing the first few characters of the line in question, killing the li
What's a neat way to map a function to every nth element in a sequence ? Something like (map-every-nth fn coll n), so that it would return the original sequence with only every nth element transformed, e.g. (map-every-nth inc (range 16) 4) would retu
Is there a way to get namespace object by its name? For example: (def ns-symbol (ns-name *ns*)) ;; get namespace name as symbol (def ns-object (ns-by-name ns-as-str)) ;; convert it back to namespace object So in this example I need function ns-by-nam
i'm using a StructMap in Clojure, and trying to add map using struct by a list of values. currently my struct includes only 3 keys, so i'm using the following to add new struct: (struct user-struct (first list-vals) (second list-vals) (nth list-vals
I have a .clj file that starts like this : (ns clojure_crawl.core) (require '[clj-http.client :as client]) (use 'clojure.contrib.json) Followed by several function definitions : (defn f1 [] "" (+ 1 1)) (defn f2 [] "" (+ 2 2)) etc... Ho
I'm looking for a good libraries to edit .mp3 tags ID3v(22,23,24) (like author, title, track and this kind of stuff), write in java or clojure, any ideas ? There is some standard "de facto" in this field... I have just look at this question: htt
I'm calling Clojure from Java and calling eval on a string passed in. The Java code will hold the objects, and the client code can specify strings of Clojure code to run on an object. I know how to call the Clojure code from Java, but how do I pass a
I have got an HTML snippet similar to: <div id="root"> <div id="A" attrib_2="bar"></div> <div id="B" attrib_2="baz"> <div id="H" attrib_1="gnu"> <p>
The producer is finite, as should be the consumer. The problem is when to stop, not how to run. Communication can happen over any type of BlockingQueue. Can't rely on poisoning the queue(PriorityBlockingQueue) Can't rely on locking the queue(Synchron
I've started working on a chess game in Clojure, but am having trouble with my namespace. At the top of my file, I have (ns chess.core (:require clojure.contrib.str-utils2)) and also define several functions, including to-string, which turns the symb
I wish to call class on the String class. How can I access this static method?You can call a static method using (ClassName/methodName arguments). However class is not a static method, it's a java keyword and you don't need it in clojure. To get the
I'm trying to write a simple mail server using Python. I found smtpd that can be used as a simple smtp server, but I don't think it supports any form of authentication. For pop or imap, I haven't found anything at all yet. I do know Twisted has some