Re: how to check if something is a channel ?

2014-01-16 Thread Meikel Brandmeyer (kotarak)
Hi, you could check to see whether a thing implements the interface. (defn channel? [x] (satisfies? clojure.core.async.impl.protocols/Channel x)) Meikel -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to cl

Re: Possible heisenbug in test suite (not in individual test runs) with memoization

2014-01-16 Thread David James
Justin and Cedric: thank you for your suggestions. I removed all uses of `with-precision`; instead, I used various BigDecimal methods directly, such as .divide, .round, and .setScale by passing in a MathContext. Best I can tell (so far), this solved my problem. On Monday, January 6, 2014 9:19:5

Re: functions inside of go blocks

2014-01-16 Thread t x
Hi Bart, !, alts! must happen within a _lexical scope_ of a (async/go block) On Thu, Jan 16, 2014 at 1:32 PM, Bart Spiers wrote: > I'm not really familiar with async, but why would you not be allowed to > call that function inside a go block? > > > On Saturday, January 11, 2014 8:45:08 PM UT

Re: how to check if something is a channel ?

2014-01-16 Thread t x
Hi Bart, This is a bit expensive in the general case -- i.e. having to construct an object every time I want to do a type check (and other objects may have expensive constructors). Now, technically, we could prebuild a gigantic map of "singleton objects" representing one of each type, i.e. (

Re: A more efficient undirected graph lookup?

2014-01-16 Thread Mark Engelberg
I'm familiar with the path compression technique for union-find, but I tend not to use it for two reasons: 1. That technique generally assumes you are going to continue to compress the path with each *find* operation, not just the union. This means you need to either use a mutable structure or el

Re: A more efficient undirected graph lookup?

2014-01-16 Thread Karsten Schmidt
Thank you for the example & pointing me to the official name of this problem, Mark! Having done some more digging I found a solution which still uses the "canonical nodes" idea (root nodes of component clusters/subtrees) but does structure it differently and compresses the paths of new nodes as the

Re: core.async count in a channel

2014-01-16 Thread t x
I second the request to add a "count" field to the channel protocol. I also agree that having to keep track of the buffer just to get the count is hacky-ish. On Thu, Jan 16, 2014 at 3:29 PM, Paul Viola wrote: > > Still finding my way around Clojure... sorry if this is trivial. > > I am using c

Re: functions inside of go blocks

2014-01-16 Thread Bart Spiers
I'm not really familiar with async, but why would you not be allowed to call that function inside a go block? On Saturday, January 11, 2014 8:45:08 PM UTC+1, t x wrote: > > Hi, > > Consider this function: > > (defn try-put! [chan msg] > (not (= (alts! [chan msg] > :defau

core.async count in a channel

2014-01-16 Thread Paul Viola
Still finding my way around Clojure... sorry if this is trivial. I am using core.async to implement a queue for a collection of workers that pull jobs and complete them (there may be multiple producers as well). All looks great so far. Except when it comes time to close down the pipe (and dr

Re: how to check if something is a channel ?

2014-01-16 Thread Bart Spiers
Hey t x, You could use type to check it. It's not very robust (if there are different types of channels, this might not work I guess) but will do the trick: (defn is-channel? [c] (= (type (async/chan)) (type c))) On Saturday, January 11, 2014 4:08:46 AM UTC+1, t x wrote: > > Hi, > > In cloju

Re: string/replace regex help

2014-01-16 Thread Kuba Roth
Sweet! Thanks so much! On 2014-01-16, at 1:17 PM, John Wiseman wrote: (clojure.string/replace myText #"(?s)START.*?END" "==") ;; "a==\nee\nff\nggg\n==\n\n" (?s) specifies multi-line mode, *? is the non-greedy form of *. On Thu, Jan 16, 2014 at 1:02 PM, Kuba Rot

Re: string/replace regex help

2014-01-16 Thread John Wiseman
(clojure.string/replace myText #"(?s)START.*?END" "==") ;; "a==\nee\nff\nggg\n==\n\n" (?s) specifies multi-line mode, *? is the non-greedy form of *. On Thu, Jan 16, 2014 at 1:02 PM, Kuba Roth wrote: > Hi, > This is more of a regex specific question the clojure,

string/replace regex help

2014-01-16 Thread Kuba Roth
Hi, This is more of a regex specific question the clojure, but anyway... I have the a multiline string as follow: (def myText "aSTART END ee ff ggg START ii E END ") .. and I need to replace all text between START END 'keywords' blocks.

Re: A more efficient undirected graph lookup?

2014-01-16 Thread Mark Engelberg
Whoops, typo, should have been: "(if (<= (count component1) (count component2))" Corrected: (defn register-same-as [{:keys [keys->canonical canonical->components] :as component-graph} key1 key2] (let [canonical1 (keys->canonical key1 key1)

Re: A more efficient undirected graph lookup?

2014-01-16 Thread Mark Engelberg
If I understand you correctly, this is known as the "union-find" problem. All you care about is whether two items are in the same component of the graph. The key here is to keep track of two maps, one map from each item to a "canonical item" in its component, and one map from each canonical item

lein do + pdo

2014-01-16 Thread t x
## Consider the following line: lein do cljx once, pdo cljx auto, cljsbuild auto, run -m server.main ## it does not appear (by running it) to be equiv to: lein cljx once lein pdo cljx auto, cljsbuild auto, run -m server.main ? ## is there a way to generate a single lein command which is equiv t

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread t x
After looking at edn/read-string and realizing I would have to modify Java code, I have decided that modifying the sender in clojure land isn't so bad after all. On Thu, Jan 16, 2014 at 9:41 AM, Alex Miller wrote: > I think I would change the sender to elide whatever parts you don't want > to s

Re: Looking to migrate thousands of Clojure applications from 1.2 to 1.5.

2014-01-16 Thread Toby Crawley
The isolation in Immutant is achieved (in part) by ShimDandy[1], which can be used outside of Immutant with a bit of work. It's been on my list for a while now to provide a sample application demonstrating usage - there is a minimal example in the README. Let me know if you are interested in the S

A more efficient undirected graph lookup?

2014-01-16 Thread Karsten Schmidt
Hi, I need to build a data structure to store aliases of arbitrary values (e.g. URIs), basically an undirected graph. Because I need a fast lookup, I thought using a map with bi-directional mappings could work well, e.g. stating "X" sameas "A" becomes this: ;; x == a : {a #{x} x #{a}} Continuing

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread Alex Miller
I think I would change the sender to elide whatever parts you don't want to send rather than mess with the receiver. On Thursday, January 16, 2014 2:11:02 AM UTC-6, t x wrote: > > Hi, > > Right now if I do (clojure.edn/read-string ...) on a string with a > unreadable part, I get an exception.

Re: A ClojureScript Tutorial For Light Table Users

2014-01-16 Thread Gary Johnson
Great job, David. Looking very sharp! ~Gary -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post.

Re: Looking to migrate thousands of Clojure applications from 1.2 to 1.5.

2014-01-16 Thread Petr
Yes, but this requires custom class loaders. AFAIK this is already implemented in Immutant project (http://immutant.org/) On Thursday, January 16, 2014 11:13:11 PM UTC+7, solo...@gmail.com wrote: > > Quick update and question: We've put together a preliminary migration plan > and are considering

Re: Looking to migrate thousands of Clojure applications from 1.2 to 1.5.

2014-01-16 Thread solo . levy
Quick update and question: We've put together a preliminary migration plan and are considering options. Can someone share information or point me to where I can learn whether two different versions of Clojure (1.2 and 1.5) can run in the same JVM? -- -- You received this message because you

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
I have been using Clojure for something more then 2 years, something more then 1 year intensive... But i think those feelings of frustration are absolutely OK, when i started with Clojure for the very first time, i was so frustrated (years of OOP mind-bending...) that i gave up for some time an

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Oh, yes, my mistake, it should be data instead of s Dňa štvrtok, 16. januára 2014 15:56:18 UTC+1 James napísal(-a): > > Thank you for sharing. > > I think the final `s` needs to be `data`, right? > > On 16 Jan 2014, at 14:53, Jan Herich > > wrote: > > Here we go, more generic solution: > > (defn

Re: Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
Thank you for sharing. I think the final `s` needs to be `data`, right? On 16 Jan 2014, at 14:53, Jan Herich wrote: > Here we go, more generic solution: > > (defn transform [data delimiter] > (reduce (fn [acc [k v]] > (let [key-strs (-> k (name) (str/split delimiter))] > (assoc-in

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Here we go, more generic solution: (defn transform [data delimiter] (reduce (fn [acc [k v]] (let [key-strs (-> k (name) (str/split delimiter))] (assoc-in acc (mapv keyword key-strs) v))) {} s)) Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a): > > Hello all, > > I've fo

Re: Grouping and nested keys in a hash

2014-01-16 Thread James
Wow, I feel like a clumsy fool bashing parens together. Have you been using Clojure for a long time Jan? I ask because I often don't know where to begin when approaching a problem with Clojure, and it can be quite frustrating. On Thursday, January 16, 2014 2:45:48 PM UTC, Jan Herich wrote: > >

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
My solution would work only for fixed 2 level deep maps, but it would be not so hard to modify it that it will be much more generic :) Dňa štvrtok, 16. januára 2014 14:46:46 UTC+1 James napísal(-a): > > Hello all, > > I've found myself stuck trying to move matching keys in a hash into a > nested

Re: Grouping and nested keys in a hash

2014-01-16 Thread James
And here is the final piece of working code, which we're using to transform results from Korma when we join a has one or belongs to association. (def ^:private rel-attribute-pattern #"(.*)--(.*)$") (defn- nested-key [k] (some-> (re-matches rel-attribute-pattern (name k)) second

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jan Herich
Another way of doing that: (def data {:b--name "B", :a--id 1, :b--id 2, :a--name "A"}) (defn transform [data delimiter] (reduce (fn [acc [k v]] (let [[f-k s-k] (-> k (name) (str/split delimiter))] (assoc-in acc [(keyword f-k) (keyword s-k)] v))) {} s)) (transform data #"--") ;; {:a

Re: Grouping and nested keys in a hash

2014-01-16 Thread James
Whoops… that's missing an all important (merge (into {} top)). On Thursday, 16 January 2014 14:36:45 UTC, James wrote: > > Thanks for the pointers. I've gotten as far as grouping the keys by the > prefix using `group-by`, and added clunky support for keys that aren't > nested like so: > > ``` cl

Re: Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
Thanks for the pointers. I've gotten as far as grouping the keys by the prefix using `group-by`, and added clunky support for keys that aren't nested like so: ``` clj (defn- nested-key [k] (some-> (re-matches #"^(.*)--(.*)$" (name k)) second keyword)) (defn nest-relations

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread Luc Prefontaine
Oups, skipped the last part of your emal. With edn I see no way to do this. Luc > Either you misunderstood my question or I misunderstood your answer. > > I don't want the entire expression to return nil. I only want the > _unparsable_ part to return nil. > > Thus, the above answer should be

Re: [ClojureScript] A ClojureScript Tutorial For Light Table Users

2014-01-16 Thread Mimmo Cosenza
Great initiative David!! It seems the fastest path to learn ClojureScript by minimising any incidental complexities generated by tools. mimmo On Jan 15, 2014, at 2:44 PM, David Nolen wrote: > I've started what I hope will be a collaborative and comprehensive reference > on the ClojureScr

Re: Grouping and nested keys in a hash

2014-01-16 Thread Jim - FooBar();
You could do something like this: (def v {:a--id 1 :a--name "A" :b--id 2 :b--name "B"}) (group-by #(-> % first str second str keyword) v) =>{:b [[:b--name "B"] [:b--id 2]], :a [[:a--id 1] [:a--name "A"]]} (reduce-kv #(assoc % %2 (into {} %3)) {} *1) => {:a {:a--id 1, :a--name "A"}, :b {:b--n

Grouping and nested keys in a hash

2014-01-16 Thread James Conroy-Finn
Hello all, I've found myself stuck trying to move matching keys in a hash into a nested hash. For example,: {:a--id 1 :a--name "A" :b--id 2 :b--name "B"} ;=> {:a {:id 1 :name "A"} :b {:id 2 :name "B"}} I've tried `clojure.walk`, I've tried building the args to `assoc-in`, and using `apply`.

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread Bronsa
What you want is currently not possible. If you need this functionality, I'll take a patch for tools.reader that adds a :nil-on-unreadable option to clojure.tools.reader.edn/read. Il giorno 16/gen/2014 11.05, "t x" ha scritto: > Either you misunderstood my question or I misunderstood your answer

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread t x
Either you misunderstood my question or I misunderstood your answer. I don't want the entire expression to return nil. I only want the _unparsable_ part to return nil. Thus, the above answer should be {:tag :message :chan ni} rather than nil On Thu, Jan 16, 2014 at 1:47 AM, Luc Prefontaine <

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread Luc Prefontaine
Wrap the read in a try catch just return nil in the catch clause for this specific exception and wrap it in a function for ease of use. You might want to throw up any other exceptions and only catch this one Luc P. > I should add: this problem arises due to cljs / clojure talking over the >

Re: clojure.edn/read-string exceptions => nil

2014-01-16 Thread t x
I should add: this problem arises due to cljs / clojure talking over the network, so: (*) not using serialization is NOT an option (*) however, I don't have to use edn/read-string + pr-str (*) it's perfectly fine to use different encoding/decoding methods On Thu, Jan 16, 2014 at 12:11 AM, t x

clojure.edn/read-string exceptions => nil

2014-01-16 Thread t x
Hi, Right now if I do (clojure.edn/read-string ...) on a string with a unreadable part, I get an exception. Instead, I would like to just get nil. For example: ## code (clojure.edn/read-string (pr-str {:tag :message :chan (async/chan 10)})) ## currently returns java.lang.RuntimeExcept