Applying function on a vector of tags to extract content from xml

2013-07-08 Thread Vesna Petkovic
I am trying to apply function for extracting content of one tag from xml on a collection of tags. Basically, I am trying to make a function that will extract content from xml, like this (defn get-events[xz] (map (juxt #(zf/xml1-> % :title zf/text) #(zf/xml1-> % :performers :perform

Re: Sequential conditional transforms of an argument

2013-07-08 Thread Bob Hutchison
On 2013-07-08, at 2:40 AM, Laurent PETIT wrote: > thank you all for your answer. > > So to go back to my original concern, there does not seem to be a way > to do this as I intended by just combining the existing features in > core. > I'm not sure what you're asking for here. Do you mean *in-

Re: Don't understand why this core.async code fails

2013-07-08 Thread Timothy Baldridge
A few thoughts on ways to improve this code: Using agents and go blocks in the same code is a bit odd. If you need a queue plus a process, just do something like this: (defn faux-agent [c] (go (loop [] (when-let [msg (! req-chan :req) do something like this: (>! req-chan [file-nam

how to create in-memory hsqldb database via java.jdbc

2013-07-08 Thread Colin Yates
Hi, I am using clojure.java.jdbc with HSQLDB, but I cannot figure out how to create an in-memory database. Whatever I try defaults to a file based instance, so: (def hsql-db {:classname "org.hsqldb.jdbcDriver" :subprotocol "hsqldb" :subname "memory"}) creates a file called memory.log etc. in

Re: how to create in-memory hsqldb database via java.jdbc

2013-07-08 Thread Colin Yates
Found it - typically - messed around for hours, then post, the find it. The answer is to use something like 'mem:XYZ' for the subname. The clue was checking in https://github.com/clojure/java.jdbc/blob/dd3c05b940b9a9c7a739247e2508ea6a5d55df65/src/main/clojure/clojure/java/jdbc.clj#L416 and see

[ANN] 16th tutorial of the modern-cljs series

2013-07-08 Thread Giacomo Cosenza
Hi all, I just pushed the 16th tutorial of the modern-cljs series. By using the clojurescript.test lib and the cljx lein plugin I was able to make the unit tests portable on both the client-side and the server-side of a web app. To me this is very important, because allows to potentially move a

Can't figure out how to merge this dern map.

2013-07-08 Thread VaedaStrike
So I have data structure that's equivalent to the following— ({:apple "red and crunchy"} nil nil {:Numb 1} nil nil {:Field "FRUIT.Description"}) and I'm trying to combine the maps into a single map and I'm just being flummoxed I tried destructuring it and then applying a merge to the maps whi

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Alexander Solovyov
The simplest way I see is (apply merge (filter identity '({:apple "red and crunchy"} nil nil {:Numb 1} nil nil {:Field "FRUIT.Description"}))) results in {:Field "FRUIT.Description", :Numb 1, :apple "red and crunchy"} On Mon, Jul 8, 2013 at 6:01 PM, VaedaStrike wrote: > So I have data struct

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Alexander Solovyov
Actually, drop filter - just (apply merge sequ) is enough. On Mon, Jul 8, 2013 at 6:16 PM, Alexander Solovyov wrote: > The simplest way I see is > > (apply merge (filter identity '({:apple "red and crunchy"} nil nil {:Numb > 1} nil nil {:Field "FRUIT.Description"}))) > > results in > > {:Field "

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Gary Trakhman
I think the destructuring you're trying to do uses [ ]. Apply/reduce merge is the general answer. On Mon, Jul 8, 2013 at 11:16 AM, Alexander Solovyov wrote: > The simplest way I see is > > (apply merge (filter identity '({:apple "red and crunchy"} nil nil {:Numb > 1} nil nil {:Field "FRUIT.Desc

clojure 1.5.1, emacs/nrepl and clojure.repl

2013-07-08 Thread Colin Yates
Hi all, If using clojure 1.4.0 then when I start nrepl (CcMj) then I the clojure.repl namespace is automatically 'used. If I upgrade to Clojure 1.5.1 then it doesn't. I can still (use 'clojure.repl) but is this a bug? I can't believe I would be the first to spot this but there I couldn't find

Re: clojure 1.5.1, emacs/nrepl and clojure.repl

2013-07-08 Thread Neale Swinnerton
Hi Col, On Mon, Jul 8, 2013 at 4:43 PM, Colin Yates wrote: > Alternatively, in the vein of just getting things done, can I do some > emacs fu to automatically load clojure.repl? Silly me - of course I can - > this is emacs :). No idea what that fu would be though... Any hints? > > Since nrepl

[ANN] clj-wamp 1.0.0-rc1 is released

2013-07-08 Thread Christopher Martin
clj-wamp: WAMP WebSocket subprotocol for HTTP Kit. New release of clj-wamp *1.0.0-rc1* includes: - Feature: WAMP-CRA (Challenge Response Authentication). - Feature: WebSocket subprotocol and origin header validation in an optional response handler (`with-channel-validation`). - Depen

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread VaedaStrike
Well it's clear I need to understand apply better. Thanks!!! I very much appreciate the help! On Monday, July 8, 2013 9:16:16 AM UTC-6, Alexander Solovyov wrote: > > The simplest way I see is > > (apply merge (filter identity '({:apple "red and crunchy"} nil nil {:Numb > 1} nil nil {:Field "FRU

Re: Don't understand why this core.async code fails

2013-07-08 Thread vemv
Took me a while to get the idea but higher-order channels are brilliant - that way one ensures a given reply was actually targeted at one's request. Thanks for the suggestion! Faux-agents would have the limitation of not being to (reasonably) perform blocking I/O - which is the point of my samp

Re: [ANN] Instaparse 1.2.0

2013-07-08 Thread Mark Engelberg
FYI, there was a dependency problem with 1.2.0, and I've pushed a version 1.2.1 fixing the issue out to clojars. If any further bugs are reported, I will provide further bugfixes under the 1.2 numbering series (1.2.2, etc.), so I encourage you to check back at the github site

Re: Don't understand why this core.async code fails

2013-07-08 Thread Timothy Baldridge
Eh, you're right, there is however, a blocking version of go, called thread: So perhaps something like this? (thread (while true (let [[filename response-chan] (!! response-chan (slurp filename) Or perhaps I'm missing something. Timothy On Mon, Jul 8, 2013 at 10:09 AM, vemv wrote:

Re: clojure 1.5.1, emacs/nrepl and clojure.repl

2013-07-08 Thread Tim Visher
On Mon, Jul 8, 2013 at 11:43 AM, Colin Yates wrote: > If using clojure 1.4.0 then when I start nrepl (CcMj) then I the > clojure.repl namespace is automatically 'used. If I upgrade to Clojure > 1.5.1 then it doesn't. I can still (use 'clojure.repl) but is this a bug? > > I can't believe I would

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Max Penet
You don't need apply, you can just use into: user> (into {} [{:apple "red and crunchy"} nil nil {:Numb 1} nil nil {:Field "FRUIT.Description"}]) {:apple "red and crunchy", :Numb 1, :Field "FRUIT.Description"} On Monday, July 8, 2013 5:01:20 PM UTC+2, VaedaStrike wrote: > > So I have data struct

Re: [ANN] 16th tutorial of the modern-cljs series

2013-07-08 Thread Chas Emerick
Looks like another great installment in the series! One note: I've been working on giving cljx a bit of a facelift of late to address some pitfalls of it using Clojure's reader. The result is in the 'sjacket' branch of cljx here: https://github.com/lynaghk/cljx/tree/sjacket As the bra

Re: [ANN] 16th tutorial of the modern-cljs series

2013-07-08 Thread Steven Degutis
Thanks for this series Mimmo, I found it the other day and it helped me to get my feet wet with Cljs. I was wondering, is there any reason you chose Domina instead of Dommy? On Mon, Jul 8, 2013 at 10:01 AM, Giacomo Cosenza wrote: > Hi all, > I just pushed the 16th tutorial of the modern-cljs se

Re: [ClojureScript] Re: [ANN] 16th tutorial of the modern-cljs series

2013-07-08 Thread Giacomo Cosenza
Thanks Chas, I'll take a look asap. Mimmo On Jul 8, 2013, at 6:31 PM, Chas Emerick wrote: > Looks like another great installment in the series! > > One note: I've been working on giving cljx a bit of a facelift of late to > address some pitfalls of it using Clojure's reader. The result is in

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Gary Trakhman
Into is reduce-conj, and this relies on a special-case of conj for maps and map entries. I find it hard to read, so I would vote for apply/reduce merge. This is weird and unexpected, so please don't: user> (into {:c :d} [{:a :b}]) {:c :d, :a :b} user> (into {:c :d} {:a :b}) {:c :d, :a :b} On M

Re: [ANN] 16th tutorial of the modern-cljs series

2013-07-08 Thread Giacomo Cosenza
On Jul 8, 2013, at 6:35 PM, Steven Degutis wrote: > Thanks for this series Mimmo, I found it the other day and it helped me to > get my feet wet with Cljs. I'm glad you found it useful > > I was wondering, is there any reason you chose Domina instead of Dommy? The main reason is that dommy wa

Re: Can't figure out how to merge this dern map.

2013-07-08 Thread Alex Baranosky
Agreed that it is weird and I never use `into` in that manner, either. On Mon, Jul 8, 2013 at 9:50 AM, Gary Trakhman wrote: > Into is reduce-conj, and this relies on a special-case of conj for maps > and map entries. I find it hard to read, so I would vote for apply/reduce > merge. > > This is w

Re: clojure 1.5.1, emacs/nrepl and clojure.repl

2013-07-08 Thread Colin Yates
Ah yes - nice find. On 8 July 2013 17:24, Tim Visher wrote: > On Mon, Jul 8, 2013 at 11:43 AM, Colin Yates > wrote: > > If using clojure 1.4.0 then when I start nrepl (CcMj) then I the > > clojure.repl namespace is automatically 'used. If I upgrade to Clojure > > 1.5.1 then it doesn't. I can

Re: clojure 1.5.1, emacs/nrepl and clojure.repl

2013-07-08 Thread Colin Yates
That works a treat - thanks. On 8 July 2013 16:49, Neale Swinnerton wrote: > Hi Col, > > On Mon, Jul 8, 2013 at 4:43 PM, Colin Yates wrote: > >> Alternatively, in the vein of just getting things done, can I do some >> emacs fu to automatically load clojure.repl? Silly me - of course I can - >

Confused about exception handling

2013-07-08 Thread Marcel Möhring
Hello, as a Java developer I'm a bit confused about the lack of exceptions. A minimal example: (spit "filename" "a String" :encoding "UTF-8") the corresponding Java code has got 4 possible exceptions: UnsupportedEncodingException FileNotFoundException 2 x IOException (on .write and on .close)

Re: Confused about exception handling

2013-07-08 Thread Gary Trakhman
Clojure doesn't have checked exceptions, but it uses a java compiler trick called sneaky-throws to rethrow and catch them, so versions past 1.3 don't wrap them in RuntimeExceptions. Generally, clojure won't go out of its way to protect you from exceptions or catch them for you, but it's idiomatic

Re: core.logic - Using featurec to describe relationships around keys in a map

2013-07-08 Thread David Rocamora
On Sat, Jul 6, 2013 at 6:03 PM, David Nolen wrote: > On Sat, Jul 6, 2013 at 12:27 PM, Norman Richards wrote: > >> >> On Fri, Jul 5, 2013 at 1:06 PM, David Rocamora wrote: >> >>> >>> I'm trying to use featurec to describe some relationships within a >>> nested map. When I try to use it to find so

group-by replacement when an item has many groups?

2013-07-08 Thread Colin Yates
Hi, I have a sequence of items and want to group them into categories, the value of which is a function of the item. This sounds exactly what group-by is after. The kicker is that the function could return multiple values. Imagine each item was a date range and I wanted to group them by the

Re: Applying function on a vector of tags to extract content from xml

2013-07-08 Thread Jeremy Heiler
On July 8, 2013 at 5:39:14 AM, Vesna Petkovic (vesna.petko...@gmail.com) wrote: (defn func [& tags](#(zf/xml1-> (xml-zipper tags) % zf/text))) As the exception states, you are passing 0 arguments to a function that doesn't accept 0 arguments. The name of the function "datamodel$func$fn" narrows it

Re: Don't understand why this core.async code fails

2013-07-08 Thread Víctor M . Valenzuela
The downside of #'thread (just as with send-off) is that it can use arbitrarily many threads for performing IO ops. And while some IO tasks benefit from performing them from multiple threads (for fairness, perf), others don't (e.g. writing to a log, AFAICT). And in no case one wants to spawn a thou

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Jim - FooBar();
you can use group-by as you showed and then reduce-kv over them map replacing each key with '(count key)'...I don't see a way of doing this in one-pass using group-by alone... Jim On 08/07/13 20:25, Colin Yates wrote: Hi, I have a sequence of items and want to group them into categories, th

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Ben Wolfson
You could do something like this, which is just a generalization of group-by to the multiple value case (except that group-by actually uses transients): user> (defn groups-by [f coll] (reduce (fn [acc x] (let [ks (f x)] (reduce (fn [acc' k] (update

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Colin Yates
Perfect, and bonus points for spotting my stupid "not slept in days" muppetry. The results I want are as you infer: {1 [1 2 3] 2 [1 2] 3 [3]}. Now all I have to do is understand your code - time for more coffee I think (not implying your code is difficult, rather the difficultly is a function of

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Colin Yates
Hi Jim, I don't think that would give the result I need. Let me give a more realistic example: (defn every-day [[start :start end: end]] ...) ; returns [date1 date2 date3] (def m [{:id 1 :start 1/1/2010 :end 3/1/2010} {:id 2 :start 3/1/2010 :end 3/1/2010}] (group-by every-day m) would give some

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Michał Marczyk
Another implementation: (defn groups-by [f coll] (apply merge-with into (map (fn [k] (zipmap (f k) (repeat [k]))) coll))) Or with ->>: (defn groups-by [f coll] (->> coll (map (fn [k] (zipmap (f k) (repeat [k] (apply merge-with into))) Could use #(zipmap (f %) (repeat [

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Colin Yates
Wow - I need to get some sleep: {1 [1 2 3] 2 [2 3] 3 [3]} On 8 July 2013 20:52, Colin Yates wrote: > Perfect, and bonus points for spotting my stupid "not slept in days" > muppetry. The results I want are as you infer: {1 [1 2 3] 2 [1 2] 3 [3]}. > > Now all I have to do is understand your cod

java.jdbc - (sql/where ...) with multiple values (i.e. 'x in (1,2,3')

2013-07-08 Thread Colin Yates
Using the latest release of java.jdbc, does anybody know how I can construct a where clause when I want to check if the value is one of many values? For example, if I have a filter {:age [1 2 3 4]} then (sql/where filter) causes an error: "Wrong data type: java.lang.NumberFormatException: For

Re: java.jdbc - (sql/where ...) with multiple values (i.e. 'x in (1,2,3')

2013-07-08 Thread Jeremy Heiler
On July 8, 2013 at 5:28:13 PM, Colin Yates (colin.ya...@gmail.com) wrote: Using the latest release of java.jdbc, does anybody know how I can construct a where clause when I want to check if the value is one of many values? For example, if I have a filter {:age [1 2 3 4]} then (sql/where filter) c

clojure interpreters?

2013-07-08 Thread kovas boguta
I believe a reify-able clojure interpreter would be useful and interesting. For instance, for debugging, partial evaluation, environment capture / manipulation, and a variety of tasks that currently require resetting the environment just to see the behavior of code. I imagine this being mostly us

Re: [ANN] clj-wamp 1.0.0-rc1 is released

2013-07-08 Thread Jason Gilman
Thanks for the awesome library. I've been using it for a couple weeks now and it's been really easy to use. I appreciate the great documentation. On Monday, July 8, 2013 11:54:00 AM UTC-4, Christopher Martin wrote: > > clj-wamp: WAMP WebSocket subprotocol for HTTP Kit. > > New release of clj-wamp

Re: group-by replacement when an item has many groups?

2013-07-08 Thread Yoshinori Kohyama
Hi Colin, One more solution, with example data in the process commented *(let [f #(range 1 (inc %))* * coll '(1 2 3)]* * (->>* **(for [*x coll*; x = 1, 2, 3 * y *(*f x*)]* *; y = 1 (where x = 1), **; 1, 2(where x = 2), *

Re: java.jdbc - (sql/where ...) with multiple values (i.e. 'x in (1,2,3')

2013-07-08 Thread James Ferguson
On Monday, July 8, 2013 5:28:07 PM UTC-4, Colin Yates wrote: > > Using the latest release of java.jdbc, does anybody know how I can > construct a where clause when I want to check if the value is one of many > values? > > For example, if I have a filter {:age [1 2 3 4]} then (sql/where filter)

Re: clojure interpreters?

2013-07-08 Thread Shantanu Kumar
An interpreter would be great! I attempted a different approach, which simply evaluates an S-expression with a user-specified environment (collection of maps), here: https://github.com/kumarshantanu/quiddity It works in Clojure and CLJS (I saw it works in ClojureCLR too but haven't managed to

[ANN] Varspotting: spotting Clojure Vars for fun and profit!

2013-07-08 Thread Michał Marczyk
Hi, Inspired by this Stack Overflow question: Roughly how many functions are in the Clojure core libraries? http://stackoverflow.com/questions/17524906/roughly-how-many-functions-are-in-the-clojure-core-libraries I have released Varspotting, a Leiningen plugin and library for summarizing Va

Re: Overflowing (count ...)

2013-07-08 Thread Andy Fingerhut
Making count return a correct long or BigInt value in such cases would be a significant change, given that Java's int is used for the return value for many count() and countFrom() methods sprinkled around Clojure's source code. I've created a ticket CLJ-1229 and attached a patch that causes count