one is clearly worse:
(time (doall (flatten-maps-lazy data)))
user=> "Elapsed time: 0.469 msecs"
({:a 1, :b 1} {:a 2, :b 2} {:a 3, :b 3} {:a 4, :b 4} {:a 5, :b 5} {:a
6, :b 6} {:a 7, :b 7} {:a 8, :b 8})
> On Wed, Apr 13, 2011 at 12:59 PM, babui wrote:
> > I was asking b
I was asking because my timings show that the lazy version is the
fastest one.
My (very simple & stupid) test is:
(defn flatten-maps
"The original one"
)
(defn flatten-maps-lazy
"The lazy one"
)
(defn flatten-maps-eager
"The eager one"
)
(defn flatten-maps-r
A solution using recur:
(defn flatten-maps-recur
([ms] (flatten-maps-recur ms ()))
([ms fl] (if-let [[f & r] (seq ms)]
(recur (concat (get f :c) r) (cons (dissoc f :c)
fl))
fl)))
Please, can you publish how are you doing your timings?
Thanks,
JM
I have a project in which I have to use some java mutable objects
(e.g. a graph).
In my code, I have some functions that get these objects and add nodes
to them, for instance:
(defn make-graph [] returns a graph wrapped with other things)
(defn add-to-graph [graph n] adds n to the stru
It has worked like a charm.
Thanks.
Juan Manuel
On 11 abr, 16:45, Meikel Brandmeyer wrote:
> Hi,
>
> On 11 Apr., 16:35, babui wrote:
>
> > (ns b
> > (:use a :as mya))
>
> You want require here, not use. (ns b (:require [a :as mya]))
>
> Sincerely
>
I'm having trouble avoiding name collisions with protocols. A third-
party librery defines:
(ns a)
(defprotocol PA
(fa [this ...])
(ga [this ..])
(ha [this ..])
.)
And i want to be able to use some of this protocol for a type I'm
defining. So I do
(ns b
(:use a :as mya))
(d
Do protocols respect namespace rewriting? For instance:
We define a protocol in a namespace:
(ns a)
(defprotocol P
(p [this]))
(defn g[] )
This works:
(ns b
On 6 abr, 00:02, Stuart Sierra wrote:
> You can omit clojure.core/first from your namespace like this:
>
> (ns your.namespace
;
> On Fri, Nov 19, 2010 at 11:44 AM, babui wrote:
> > I've been playing with lazy sequences defined by autoreferential
> > definition. For instance:
>
> > (def ones (lazy-seq (cons 1 ones)))
>
> > which is equivalent to (def ones (repeat 1)).
>
> >
I've been playing with lazy sequences defined by autoreferential
definition. For instance:
(def ones (lazy-seq (cons 1 ones)))
which is equivalent to (def ones (repeat 1)).
My problem arises when defining the sequence of fibonacci numbers.
With this definition:
(def fibs
(lazy-seq (list* 0 1
simply don't put a for inside a for:
(for [x (range 5)
y (range 5)]
y)
Hope this helps.
JM
On 19 oct, 06:57, Rising_Phorce wrote:
> Nested For(s) produce lists of lists:
>
> =>(for [x (range 5)]
> (for [y (range 5)]
> y))
>
> ((0 1 2 3 4) (0 1 2 3 4) (0 1 2
On 12 oct, 03:56, Stuart Halloway wrote:
I've tried your definition
> (def primes
> (concat
> [2]
> (let [primes-from
> (fn primes-from
> [n]
> (if (some #(zero? (rem n %))
> (take-while #(<= (* % %) n) primes))
> (recur (+
> BTW, it's Rich, not Rick
Sorry, Rich.
JM
PS: I hope this messsage does not contain any error :-)
--
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 mo
Hi all,
does anyone knows if (and where) the presentation Rick gave at
the Emergin Languages Summit is available?
Thanks,
Juan Manuel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups
13 matches
Mail list logo