Re: Practical Clojure

2012-04-13 Thread David Cabana
I need to clarify something, since I unintentionally introduced confusion into this discussion. The initial comment by faenvie referred to the book "Practical Clojure", a very good book (I own a copy). I spaced out and thought that faenvie's comment concerned the newly released "Clojure Programmi

Re: Practical Clojure

2012-04-13 Thread David Cabana
I have not read it all (yet), but what I have read is outstanding. O'Reilly has made the table of contents and first chapter available online. If you are at all curious, check it out. The first chapter contains an exceptionally lucid and thorough section on destructuring. http://cdn.oreilly.com/o

Re: What's the efficient functional way to computing the average of a sequence of numbers?

2012-03-29 Thread David Cabana
> "Very likely" strikes me as a huge overstatement here. Most sequences > that you want to average won't be source-code literals, they'll be > lazy sequences, and those aren't counted Point taken about lazy sequences. But the above was not intended to suggest the sequence needs to be source code l

Re: What's the efficient functional way to computing the average of a sequence of numbers?

2012-03-29 Thread David Cabana
On Thu, Mar 29, 2012 at 12:18 AM, simon.T wrote: > The obvious way is like the following, which traverse the sequence 2 times. > ... The obvious way does not necessarily traverse the sequence twice. If a sequence S satisfies the 'counted?' predicate, (count S) takes constant time. In particular

Re: ANN: Marginalia v0.7.0

2012-03-06 Thread David Cabana
Fogus, congratulations on the release. My thanks to you and all the contributors. Marginalia rules. -- 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 mod

Re: Korma - cannot acquire connections

2011-11-06 Thread David Cabana
This worked for me, with mysql 5.1 on Ubuntu Natty. The clojure_test library and fruit table already existed. (ns foo.core (use [korma.db]) (use [korma.core])) (defdb mydb {:subprotocol "mysql" :subname "//127.0.0.1:3306/clojure_test" :user "clojure_test"

Re: Clojure Conj extracurricular activities spreadsheet

2011-10-26 Thread David Cabana
Please add me to the 'Literate Programming' and 'Heroku Drinking' sessions. -- 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 patien

A Leiningen configuration question

2011-05-15 Thread David Cabana
There are dev dependencies (Marginalia, swank-clojure) that I want added to every new Leiningen project. Is there a way to configure lein so that these are automatically inserted into the project.clj file on project creation? Thank you, David -- You received this message because you are subscri

Re: How often do you use REPL?

2010-09-28 Thread David Cabana
My standard practice is to split the (Emacs) screen, one side is a Clojure mode edit session, the other a repl. Best of both worlds. One can easily build up complex expressions as required, and still easily evaluate expressions in either side of the screen. If you are not familiar with Emacs and

Re: concurrency example about java x clojure

2010-09-20 Thread David Cabana
> > > The fact that currently having vals and keys return seqs in the same > > order is not guaranteed by the documentation ? At the recent Pragmatic Studio class I asked Rich and Stuart about this very point. As I recall, Rich said vals and keys do behave as one would hope, so that for a map m we

Re: Announcement: secrets of monad fu, revealed

2010-09-06 Thread David Cabana
"Easy to grok" is music to my ears. I imagine most people who read my post would skip the proofs, and that is just fine. The proofs are gruntwork. I wouldn't want the tedious details to obscure the idea of the monad, which is quite elegant once you get your head around it. On Mon, Sep 6, 2010 at

Announcement: secrets of monad fu, revealed

2010-09-05 Thread David Cabana
I had too much time on my hands, and put together a Clojure-based monad tutorial. If that kind of thing is your cup of tea, I'd love to get some feedback on it. Here's the link http://erl.nfshost.com/2010/09/05/bind-unit-and-all-that-2/ David -- You received this message because you are subscrib

Re: clojure-conj registration is now open!

2010-09-04 Thread David Cabana
Yesterday I paid for my ticket, and scheduled a vacation day for Oct 22. Looking forward to it. -- 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 moderate

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
> conj sounds like 'append' to me which I have no idea about the > performance characteristics in clojure(it is a no-no in F#, Haskell ++ > is better but would grow the stack). conj is not the same as append; it will insert the new element in the smart (most efficient) way. For instance: user> (co

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
Using a vector instead of a list as the accumulator makes it possible to skip the mapping of reverse used in the earlier version of pw: (defn pw [f? x] (let [phi (fn [a e] (if (f? e) (cons [e] a ) (cons (conj (first a) e) (rest

Re: looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
On Sat, Aug 7, 2010 at 9:36 PM, gary ng wrote: > if you don't mind about performance, this seems to be natural to me > > user=> (reverse (map reverse (reduce (fn [a e] (if (even? e) (cons [e] a) > (cons > (cons e (first a)) (rest a (list) [1 2 3 7 5 4 1]))) > ((1) (2 3 7 5) (4 1)) I reworked

looking for a simpler implementation of a function I'm using

2010-08-07 Thread David Cabana
Here are a couple of implementations of a function I'm calling 'partition-when'. I feel like there should be a simpler way than either of these. If you have one, I'd love to see it. (defn partition-when;;version 1 "Partition a sequence into subsequences; begin a new s

Re: Leiningen and loading hooks

2010-07-30 Thread David Cabana
Phil, Just a personal opinion, but I'd urge you not to worry too much about breaking changes just yet. The future value of doing the right thing now outweighs the value of backwards compatibility in an application as young as Lein. To answer your direct question, I would not be affected by a requ

Re: filtering with multiple predicates

2010-07-23 Thread David Cabana
Here's an approach that doesn't use macros. I'm not sure I'd actually do this, but here it is just for grins. (defn bind [pred] (fn [[x bool]] [x (and (pred x) bool)])) (defn comp# [ & preds ] (let [ phi (reduce comp (map bind preds))] (fn [x] (second (phi [x true]) user> (filter (c

Re: filtering with multiple predicates

2010-07-23 Thread David Cabana
Alex, Very slick; I really liked that. Thank you for posting it . David On Fri, Jul 23, 2010 at 6:33 PM, ataggart wrote: > Not that preserves the short-circuiting behavior of 'and.  This works > though: > > (defmacro andf [& fns] >  (let [x# (gensym)] >    `(fn [~x#] (and ~@(map #(list % x#) f

Re: gobble up a collection 2 at a time

2010-07-21 Thread David Cabana
Here's my take: (defn mmap [f coll] (->> coll (partition 2) (map (fn [[x y]] (f x y) For instance: user> (mmap + (range 8)) (1 5 9 13) user> (mmap * (range 8)) (0 6 20 42) You probably want to think about whether you'll see input sequences with an odd number of terms, and how

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread David Cabana
I thought this problem was interesting enough to merit better treatment than I can give it here, hence a blog post was in order. Brief version: I think I have a lazy, functional, and idiomatic implementation with decent performance. Check it out here: http://erl.nfshost.com/2010/07/17/discrete-co

Re: A functional, efficient, convolution function. Is imperitive-style the answer?

2010-07-17 Thread David Cabana
I tried to run Jame's code, but the compiler (1.2 beta) squawked at me: Unable to resolve symbol: indexed in this context [Thrown class java.lang.Exception] What do I need to pull in to pick up the "indexed" function? On Sat, Jul 17, 2010 at 5:08 AM, James Reeves wrote: > Perhaps something lik

Re: Can anyone create a simpler version of prime factors in Clojure?

2010-06-13 Thread David Cabana
I looked through some of my Project Euler solutions and found this version. It is essentially the same as Uncle Bob's, but to my eye it is a bit easier to read. (defn least-nontrivial-divisor [n];; integer n > 1 (loop [k 2] (cond (zero? (rem n k)) k ;; k divides n,

Re: Clojure Conference Poll

2010-01-26 Thread David Cabana
+1 DC -- 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. To unsubscribe from this group, send email to

Re: How can I parse this with clojure.contrib.zip-filter.xml ?

2010-01-22 Thread David Cabana
James, That worked beautifully. I knew it had to be simple, but I was drawing a total blank. Thank you, David. On Fri, Jan 22, 2010 at 9:53 PM, James Reeves wrote: > On Jan 23, 2:29 am, David Cabana wrote: >> What I'd like to get from 'tickets' is something like ( [&q

How can I parse this with clojure.contrib.zip-filter.xml ?

2010-01-22 Thread David Cabana
I have been fooling around with clojure.contrib.zip-filter.xml, and feel like I'm stuck on something that should be simple. Below is code showing what I'm talking about. I'm trying to parse some simple xml, but can't quite get what I'm after. (ns foo (:require [clojure.xml :as xml]) (:require

Re: Processing list more elegantly

2009-12-27 Thread David Cabana
If speed matters, I found both of these to be faster than the version using reductions. First version is to roll my own replacement for reductions, specialized to addition: (defn partial-sums [coll] (loop [result [0] tot 0 terms coll] (if (empty? terms) re

Re: Processing list more elegantly

2009-12-27 Thread David Cabana
Try this: (use '[clojure.contrib.seq-utils :only (reductions)]) (defn left-total [lst] (map vector lst (reductions + (cons 0 lst On Sun, Dec 27, 2009 at 8:36 PM, Conrad wrote: > I've been writing Clojure code today and have noticed the same pattern > show up multipl

Can a function determine it's own name at runtime?

2009-12-20 Thread David Cabana
Suppose we define a function called sq: (defn sq [x] (do (println "sq") (* x x))) I wanted sq to print it's own name when run; to make it do so I inserted the name as a string. Is there some way to dynamically determine the name and so avoid using the string? Similarly, is it possible

Re: Funding Clojure 2010

2009-12-14 Thread David Cabana
For years I have complained about the parts of java I don't like, and lamented the stagnation of lisp. I never imagined anyone could simultaneously attack both issues so beautifully and so successfully. Bravo. I have yet to make a dime using Clojure, but hope to some day. So as a Christmas presen

Re: Matlab for Lisp programmers?

2009-09-11 Thread David Cabana
If clean syntax really matters to you, you might want to take a look at Mathematica. Its syntax is extremely simple and regular, very lispy. Check out this link: http://reference.wolfram.com/mathematica/tutorial/EverythingIsAnExpression.html On Fri, Sep 11, 2009 at 10:43 AM, CuppoJava wrote:

Re: Lazy sequence blows starck. Why?

2009-07-03 Thread David Cabana
On Jul 3, 11:11 pm, Gert Verhoog wrote: > This seems to work: > > (def triangle-numbers (lazy-cat [1] (map + (iterate inc 2) triangle- > numbers))) > > cheers, > gert Gert, Your proposed change works very well. It's interesting that a (seemingly) small change makes a huge difference in perfo

Lazy sequence blows starck. Why?

2009-07-03 Thread David Cabana
ng approach is the same, except for an alternative definition of the triangle numbers: (defn triangle-numbers [] (lazy-cat [1] (map + (iterate inc 2) (triangle-numbers This second approach dies with a stack overflow. Can anyone shed some light on why? Thank