Working with mutable objects

2011-04-13 Thread babui
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

Re: Fun: Write the fastest code that flattens nested maps of a particular type

2011-04-13 Thread babui
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

Re: Fun: Write the fastest code that flattens nested maps of a particular type

2011-04-13 Thread babui
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-recur

Re: Protocols and name collisions

2011-04-11 Thread babui
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 the.stuart.sie...@gmail.com wrote: You can omit clojure.core/first from your namespace like

Re: Protocols and name collisions

2011-04-11 Thread babui
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))

Re: Protocols and name collisions

2011-04-11 Thread babui
It has worked like a charm. Thanks. Juan Manuel On 11 abr, 16:45, Meikel Brandmeyer m...@kotka.de wrote: Hi, On 11 Apr., 16:35, babui jmgim...@gmail.com wrote: (ns b     (:use a :as mya)) You want require here, not use. (ns b (:require [a :as mya])) Sincerely Meikel -- You

Lazy sequences with circular definition

2010-11-19 Thread babui
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

Re: Lazy sequences with circular definition

2010-11-19 Thread babui
, On Fri, Nov 19, 2010 at 11:44 AM, babui jmgim...@gmail.com 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)). My problem arises when defining the sequence

Re: Nested For(s)

2010-10-19 Thread babui
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 josh.fe...@gmail.com wrote: Nested For(s) produce lists of lists: =(for [x (range 5)]            (for [y (range 5)]                 y)) ((0 1 2 3 4) (0 1

Re: strange bug in range or lazy-seq?

2010-10-12 Thread babui
On 12 oct, 03:56, Stuart Halloway stuart.hallo...@gmail.com 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))        

Rick presentation at Emerging Languages

2010-07-26 Thread babui
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

Re: Rick presentation at Emerging Languages

2010-07-26 Thread babui
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