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
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
> "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
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
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
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"
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
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
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
> > > 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
"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
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
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
> 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
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
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
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
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
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
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
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
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
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
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,
+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
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
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
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
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
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
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
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:
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
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
34 matches
Mail list logo