Re: vec to map with consolidated vals

2013-08-16 Thread David Chelimsky
Thanks for the suggestions Sean and Ben. I learned new functions from both of you! Sean, your suggestion yields the following: (to-consolidated-map [[:a 1] [:b 2] [:a 3]]) ; {:a (1 3) :b (2)} So it still needs to reduce the vals using +. That led me to this: (defn to-consolidated-map [parts]

Re: vec to map with consolidated vals

2013-08-16 Thread Sean Corfield
How about this: (defn to-consolidated-map [parts] (apply merge-with concat (map (fn [[k v]] {k (list v)}) parts))) On Fri, Aug 16, 2013 at 9:57 PM, David Chelimsky wrote: > I've got a vector of 2-element vectors e.g. [[:a 1] [:b 2]] where the first > val of any vec might appear in another

Re: function creation, partial or #()

2013-08-16 Thread David Chelimsky
On Fri, Aug 16, 2013 at 9:49 PM, Gregg Reynolds wrote: > On Tue, Aug 13, 2013 at 1:50 PM, John D. Hume > wrote: > > Though in some cases the performance impact could be significant, my > concern > > is readability. My understanding of the concept of partial function > > application is that it's

Re: vec to map with consolidated vals

2013-08-16 Thread Ben Wolfson
I don't know if this is a *better* way, but I like it: user=> (require '[clojure.algo.generic.functor :as f]) nil user=> (def v [[:a 1] [:b 2] [:a 3] [:c 4] [:b 1]]) #'user/v user=> (defn consolidate [m] #_=> (f/fmap (partial apply +) (reduce (fn [acc [k v]] (update-in acc [k] conj v)) {} m)))

vec to map with consolidated vals

2013-08-16 Thread David Chelimsky
I've got a vector of 2-element vectors e.g. [[:a 1] [:b 2]] where the first val of any vec might appear in another vec e.g. [[:a 1] [:b 2] [:a 3]]. I need a fn that will consolidate this into a hash-map with the vals consolidated e.g. (to-consolidated-map [[:a 1] [:b 2] [:a 3]]) ; {:a 4 :b 2} I'v

Re: function creation, partial or #()

2013-08-16 Thread Sean Corfield
On Fri, Aug 16, 2013 at 4:32 PM, Timothy Baldridge wrote: > I'm just going to throw this out there, but I almost always consider using > #() instead of (fn []) to be bad practice. I still use #() for anonymous single argument functions that are small, single forms, but I've started switching to (

Re: Model validation - exceptions as side-effects?

2013-08-16 Thread Leonardo Borges
I would prefer not throwing an exception in the case of a validation. Say your validation function returns a vector or the first argument contains validation errors if any and the second contains the original map: (validate my-map) ;; returns [{:errors '("blah")} original-map] Then a neat way t

Model validation - exceptions as side-effects?

2013-08-16 Thread Alexandr Kurilin
Let's hypothetically say I have a Ring application and I'm performing some validation on the input map I receive as part of a POST request. The validate function throws an exception if anything's wrong with the input. The exception is caught in the middleware and turned into a 400 code response

Re: ANN swag a DSL for documenting Compojure routes using Swagger

2013-08-16 Thread Casper Clausen
Nice work. Looking forward to giving it a spin. On Thursday, August 15, 2013 12:13:11 PM UTC+2, ronen wrote: > > Swagger is a cool project > for documenting Restful API's, > > Swag is a DSL that wraps Compojure routes enabling them to be listed and

Re: function creation, partial or #()

2013-08-16 Thread Alex Baranosky
My two cents: The way I see it, the use of #( ... % ...) is analogous to the usage of the word "it" in English: only use it when it is obvious beyond a shadow of a doubt what "it" means. Think about how clunky English would be without the word "it". On Fri, Aug 16, 2013 at 4:32 PM, Timothy Bald

Re: core.async - handling nils

2013-08-16 Thread Ben Wolfson
On Fri, Aug 16, 2013 at 5:07 PM, Brandon Bloom wrote: > > have every other value come wrapped in a Just or Some-like constructor > > That's what I meant by "a pair of quote/unquote operators" > ah, gotcha -- Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which

Re: core.async - handling nils

2013-08-16 Thread Brandon Bloom
> have every other value come wrapped in a Just or Some-like constructor That's what I meant by "a pair of quote/unquote operators" -- -- 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

Re: What's your preference, partial or closures?

2013-08-16 Thread Sean Corfield
I went down the partial path for a long time but have moved more and more toward currying and closures lately as it seems to produce cleaner code - and this also seems to be the way Clojure/core have moved with the reducers library and other places...? Sean On Fri, Aug 16, 2013 at 3:00 PM, Alan S

Re: core.async - handling nils

2013-08-16 Thread Ben Wolfson
On Fri, Aug 16, 2013 at 4:50 PM, Brandon Bloom wrote: > I ran into the other half of this problem: If you expect nils to signify > closed channels, then you can't leverage the logically false nature of nil > without excluding explicit boolean false values. Given the pleasant syntax > of if-let /

Re: core.async - handling nils

2013-08-16 Thread Brandon Bloom
I ran into the other half of this problem: If you expect nils to signify closed channels, then you can't leverage the logically false nature of nil without excluding explicit boolean false values. Given the pleasant syntax of if-let / > Hi all, > > I'm experimenting with core.async. Most of it

Re: function creation, partial or #()

2013-08-16 Thread Timothy Baldridge
I'm just going to throw this out there, but I almost always consider using #() instead of (fn []) to be bad practice. Like all syntactic sugar, it has its place, but I reach for fn more often then not, because it allows me to name the arguments and track in my mind the data with which I am working.

Re: [ANN] slothcfg - Improved version of awesome but abandoned 'configleaf' project!

2013-08-16 Thread Greg
> So, just to be clear, you thought you'd just go ahead and fork, rename, and > reannounce my project, instead of sending me an email? My initial impulse was to send you a pull request however, I saw that there were already two outstanding pull requests. Justin had made his pull request over a

Re: [ANN] slothcfg - Improved version of awesome but abandoned 'configleaf' project!

2013-08-16 Thread David Santiago
So, just to be clear, you thought you'd just go ahead and fork, rename, and reannounce my project, instead of sending me an email? I'm quite open to collaboration and try to work quickly with people on patches, such as with Julian Eduard's recent work to make Hickory work on Clojurescript. I'm sorr

Re: Do you like the Clojure syntax?

2013-08-16 Thread Timothy Washington
Oh thanks Steven. I've lately been thinking about human cognition, intelligence, etc. So boning up on my Chomsky, Kurzweil, and so on. Remember that the original lisp syntax only had a few core features: homoiconicity, first-class functions, recursion, garbage collection, etc. But from this core,

What's your preference, partial or closures?

2013-08-16 Thread Alan Shaw
(defn newgrid [m initialize qi qj]... and then (let [init (partial newgrid m initialize)]... Or else: (defn newgrid [m initialize] (fn [qi qj]... and then (let [init (newgrid m initialize)]... -- -- You received this message because you are subscribed to the Google Groups "Cloju

[ANN] slothcfg - Improved version of awesome but abandoned 'configleaf' project!

2013-08-16 Thread Greg
Hey folks, After the configleaf plugin stopped working (most likely because of a change in Leiningen), I decided to take it under my wing as and call it slothcfg so that folks could grab the new changes via Clojars & Leiningen. Features slothcfg for Leiningen 2 fills in the missing features in

Re: Do you like the Clojure syntax?

2013-08-16 Thread Steven Degutis
Great point Tim. When I first realized that most problems and solutions are language-agnostic, I started downplaying the importance of syntax. But now I think they're like apples and oranges. Sure, semantics and syntax live together, but one's not more important than the other. They're both importa

Re: Halp Clojurinoes! Cannot deploy to Clojars! :-(

2013-08-16 Thread Greg
> My public key: > > > -- > Please do not email me anything that you are not comfortable also sharing > with the NSA. Errr... that's a typo in my email, not my public key. Not sure how it got there. Just copied this from the Clojars textarea: -BEGIN PGP PUBLIC KEY BLOCK- Version: G

Re: function creation, partial or #()

2013-08-16 Thread Gregg Reynolds
On Tue, Aug 13, 2013 at 1:50 PM, John D. Hume wrote: > Though in some cases the performance impact could be significant, my concern > is readability. My understanding of the concept of partial function > application is that it's about supplying some but not all of the arguments. > So when I see `p

Halp Clojurinoes! Cannot deploy to Clojars! :-(

2013-08-16 Thread Greg
I've been trying for at least an hour to deploy a project to Clojars to no avail—Wait... OK, apparently it made its way into Clojars despite giving me errors everything single time: However, under "Promotion" it says: Could not verify signature of /home/clojars/repo/slothcfg/slothcfg/1.0.0/sl

Generating a "Java bean" via Clojure?

2013-08-16 Thread Sean Corfield
I was working with a Java library recently and needed to create a "Java bean" to pass into it. It can be done via `gen-class` but it seems kind of verbose having to explicitly write out all of the getters and setters, and it seems you could also do it via `deftype` but that's also rather painful (I

Re: tools for minimizing forward declaration

2013-08-16 Thread Timothy Baldridge
And also note that protocol functions and multimethods also don't need forward declarations as they are polymorphic and the interface is defined ahead of time. So mutually recursive multimethods don't need to use declare at all. Timothy Baldridge On Fri, Aug 16, 2013 at 10:53 AM, Stuart Sierra

Re: Do you like the Clojure syntax?

2013-08-16 Thread Timothy Washington
I think it's a mistake to discount the importance of syntax to a language. Human beings, as a species is heavily symbolic. Think of ancient cave paintings, to pictograms, to scripts. We use these symbols to communicate with each other, our outside world, and our abstract thoughts. Whether it's writ

Re: Problem Downloading Leiningen

2013-08-16 Thread Andy Fingerhut
Without more details, it would be difficult to say. What OS and JDK are installed on the computer where you are having a problem? What error messages did you see when you tried "lein repl", "lein help", or both? On Thu, Aug 15, 2013 at 3:44 PM, MR wrote: > When I downloaded leiningen I couldn

Re: tools for minimizing forward declaration

2013-08-16 Thread Stuart Sierra
Forward declarations are rarely necessary in my experience: you just get used to defining your namespaces with low-level primitive functions at the top and higher-level functions at the bottom. You only need forward declarations (`declare`) in cases of mutual recursion, i.e. two functions that

Problem Downloading Leiningen

2013-08-16 Thread MR
When I downloaded leiningen I couldn't get lein help to open nor could I get Clojure REPL to open. I downloaded leiningen on my other computer and they work fine, but on this computer they don't. What seems to be the problem? -- -- You received this message because you are subscribed to the

Re: [PATCH] Re: creating a varargs method with gen-class

2013-08-16 Thread Daniel Kwiecinski
Sure I understand this. But I have need to generate hundreds of methods in single class. In clojure it is just few lines. Basically I use clojure in this case as an interface to asm lib. Also I was thinking about using the varargs not only in gen-class but in feify as well, which generates impl

Clojure ticket update

2013-08-16 Thread Alex Miller
Hello all, Wanted to update on a few things: 1) A bunch of tickets went through final review this week and were committed to Clojure master (aka 1.6.0-master-SNAPSHOT). If you want to try these out on your code base, that would be great. (help with snapshots

Re: memoization help

2013-08-16 Thread Christian Sperandio
You've understood well the memoization. So, your sole solution is to extract the board argument from the function you want to cache. Le 16 août 2013 14:14, "Jim - FooBar();" a écrit : > Hi all, > > I've got a memoization question... > > my chess-engine spends most of its time calculating legal

Re: function creation, partial or #()

2013-08-16 Thread Tim Visher
I will also note that any lamdba of more than one (_maybe_ two) args _must_, for me, be in the `(fn […] …)` form. Not only does it have the advantage of taking the function name, but it also is much easier to read what it's doing when I can explicitly name it's inputs. On Fri, Aug 16, 2013 at 7:3

Re: [PATCH] Re: creating a varargs method with gen-class

2013-08-16 Thread Neale Swinnerton
On 16 August 2013 12:59, Daniel Kwiecinski wrote: > This is a great patch. Have you submitted it in clojure jira? > I haven't submitted it. I've come to the conclusion that generating complex classes using (:gen-class) is a waste of time. Presumably the primary use case for generating complex ja

memoization help

2013-08-16 Thread Jim - FooBar();
Hi all, I've got a memoization question... my chess-engine spends most of its time calculating legal moves for pawns. That is because legal moves for pawns depend on the state of the board...all other pieces have logical moves that are buffered in a giant map but for pawns I have to calculate

Re: [PATCH] Re: creating a varargs method with gen-class

2013-08-16 Thread Daniel Kwiecinski
This is a great patch. Have you submitted it in clojure jira? -- Lambder On Thursday, 3 May 2012 18:31:29 UTC+1, sw1nn wrote: > > Updated patch to support varargs in constructors. > > > e.g with the patch you add some meta data to make the method a varargs > > method like this. > > > > (ns fo

Re: function creation, partial or #()

2013-08-16 Thread Stefan Kamphausen
On Friday, August 16, 2013 9:45:53 AM UTC+2, Antonio Terreno wrote: > > > I much prefer the #(), (fn[]) is longer so it's a no-go ;) > > > fn has the huge advantage of taking an (optional) name, which will show up in stack traces. Just my 2ct Stefan -- -- You received this message because

Re: [ANN] Marginalia has a new home

2013-08-16 Thread Denis Labaye
Marginalia is beautiful On Aug 15, 2013 4:34 PM, "Gary Deer" wrote: > This is my first major contribution to the Clojure community so I'm > looking forward to continuing the great work that Fogus et al have done. > > I'd like to publicly thank Fogus for letting me take the reins on a major > proj

Re: function creation, partial or #()

2013-08-16 Thread Antonio Terreno
As a newbie I got confused in the first place looking at codebases where partial was used, like your colleague said, it's in the docs: "Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function