Use the channel in `case`

(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

Clojure: anonymous function named

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

Sort the nested map Clojure

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

Destroy a card (using the keyword let)

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

go block vs wire in core.async

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

How can I add days to a date in Clojure?

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

why clojure clojure.lang.Ratio 3/2 steps = 1.5

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

Clojure REST API frameworks

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

Clojure NullPointerException with sort by

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

get exactly equal clojure / clojurescript strings in UTF-8

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

Automate the execution of several commands and vim strikes

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 -

Define a value with a dynamic name

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

Is there a way to do a history search in nrepl?

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

Object of the namespace by name

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

in clojure - How to use a list item one by one?

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

Java ID3 lib audio tags lib

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

Skip java items to a Clojure rating

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

Producer-consumer problem with a twist

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

Clojure returns an error only when using the namespace

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

How can I call a java static method in clojure?

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

Writing a Python Mail Server with Authentication

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