Re: Euler 14

2011-01-20 Thread ka
Running in VisualVM suggests that % of Used Heap is actually very less. So the problem is that GC isn't running often enough, so the JVM has to keep allocating more memory. By problem I meant, in my case, of too much memory consumption. Odd. I'd expect the JVM to run a GC immediately before

Re: Euler 14

2011-01-20 Thread ka
Andreas, How are you running that? Also what do you see in the heap dump and what is the jvm heap size? -- 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

Re: Getting started with Counterclockwise

2011-01-20 Thread ka
I've been using ccw for a while now and it works perfectly as advertised. Plus the new 0.2.0 version looks to be really promising. I invite all ccw users to give their inputs. What's bugging is not that you faced a problem or that ccw didn't work as you expected, what's disturbing is how you

Re: Euler 14

2011-01-19 Thread ka
To me this looks totally fine, max-key should keep at most two sequences in memory. I don't think there should be any difference between the non-lazy and lazy versions as the depth of cseq is ~500. The non-lazy version works for me (no heap error) for inputs 1M, 2M, 4M, but for 4M the java

Re: which IDEs are you all using?

2011-01-11 Thread ka
Here's one way to use eclipse + ccw + lein 1. Download latest eclipse helios. Go to market place and search for counter clockwise plugin. Install the latest stable. 2. Create a new Clojure project. Delete the 4 jars it provides :) (yes that's right delete them). 3. Install lein

Re: running just one test

2011-01-11 Thread ka
@Bill, If you have a REPL open you can just run the test as a zero arg function. (ns 'abc) (detest xyz ...) user= (abc/xyz) -- 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

Re: Question about sorted-sets

2011-01-11 Thread ka
Yes that compareTo doesn't define a total order on your class. I think you are missing a clause in cond: (cond (= sr sr2) 0 (= (.lik sr) (.lik s2)) return something based on quasi-isomorphic ( (.lik sr) (.lik sr2)) -1 :default 1) I think you should implement quasi-isomorphic as a

Re: currying in clojure for fixed number of arg functions

2010-12-20 Thread ka
+1 on partial with no args ! I have a doubt: using partial conveys the intent, but with automatic currying one may get confused between partial application function call, no? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send

The 'in' family

2010-12-14 Thread ka
The functions get-in, assoc-in, update-in are really useful. Just wanted to share a thoughts. user= (def m {:a {:b {:c 10 :c1 20} :b1 90} :a1 100}) #'user/m 1. Lets see the behavior of these functions in the corner case of empty keyseq: user= (get-in m []) {:a {:b {:c 10, :c1 20}, :b1 90}, :a1

Re: Getting strange behavior when stubbing

2010-12-10 Thread ka
Hi Brian, Can you explain this in more detail : I didn't have the laziness problem. I don't know if that was by accident or because Midje applies an #'eagerly function before checking. Because it seems that if code has a laziness problem, Midje will actually hide it in tests? Thanks. --

Re: dosync style

2010-12-03 Thread ka
(defn dec-or-dissoc! [key] (dosync (let [n (@*counts* key)] (if ( 1 n) (alter *counts* assoc key (dec n)) (alter *counts* dissoc key) Is it true that in that case, one would have to use ensure to make the operation correct? I don't think ensure is necessary

Re: why not change type compare functions do a compare on strings as well?

2010-12-03 Thread ka
Hi Tim, How about compare? user= (compare a b) -1 user= (compare b b) 0 user= (compare b a) 1 user= (compare 1 2) -1 user= (compare 2 2) 0 user= (compare 2 1) 1 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: when to use io! macro?

2010-12-03 Thread ka
This is a good question and I'm not sure of the right answer or if there is one. Personally, if I were exposing an API I would use the io! macro for sure. Even otherwise its a good convention to follow. On Nov 30, 9:06 am, Alex Baranosky alexander.barano...@gmail.com wrote: Hi guys, I've

Re: functional thinking

2010-12-03 Thread ka
Hi Michael, We're in a very similar situation to yours. Here's what we did: 1. 2 back end storage impls rah.storage1, rah.storage2 - these are private nses. 2. a single storage interface rah.storage for the rest of the business code. At runtime this decides which of storage1 or 2 to call. 3. Now

Re: resultset-seq improvement: mapping column names

2010-12-03 Thread ka
I'm also stuck with the same issues: 1. no option to get string keys 2. I don't understand, why do libs go through the trouble of downcasing ? Having said that I totally agree with the point Ryan makes: A greater feature of clojure is its extensibility. What I am after is a generalization of

Re: record serialization

2010-11-23 Thread ka
Hi Islon, Records already implement java.io.Serializable. So this is working: (ns record-serialization) (defrecord R [x y]) (defn test-serialization [] (with-open [oos (java.io.ObjectOutputStream. (java.io.FileOutputStream. tmp))] (.writeObject oos (R. 12 42))) (with-open [ois

Re: Some questions about Clojure Protocols

2010-11-04 Thread ka
May I ask a heretic question: Why don't you specify the contract in the docstring of the protocol? Yes Meikel that is exactly what I have right now. Just trying to learn and stir up a discussion here :) Most times you'll just do fine by passing 'something' to Coolness functions and expect

Re: Bug with instance? inside deftypes

2010-11-04 Thread ka
Christophe, Is it reasonable to assume that atleast the documentation should be modified to reflect the situation? -- 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

Re: Meta-circular STM for teaching purposes

2010-11-04 Thread ka
Hi Tom, I might not be even remotely qualified but since I'm interested and find the idea cool, so here's my take: - has anyone already experimented with a toy STM in Clojure for didactic purposes? No idea :) - what would be a good resource to start such a design from? (my current plan

Some questions about Clojure Protocols

2010-11-03 Thread ka
1. How to combine protocols? For example I have protocols walks, talks, sleeps, now how might I come up with an abstraction which walks-talks-and-sleeps ? In Java one might create an interface which extends multiple interfaces. Although getting an instance which walks-talks-and-sleeps is made

Bug with instance? inside deftypes

2010-11-03 Thread ka
Clojure 1.2.0 1:1 user= 1:2 user= 1:3 user= (deftype T [] Object (equals [this o] (if (instance? T o) true false))) user.T 1:4 user= (def t (T.)) #'user/t 1:5 user= (.equals t t) false 1:6 user= (deftype T [] Object (equals [this o] (if (= T (class o)) true false))) user.T 1:7 user= (def t (T.))

Re: Bug with instance? inside deftypes

2010-11-03 Thread ka
I would guess the problem is referring to T inside the deftype. This also works: (deftype T [] Object (equals [this o] (if (= T (class o)) true false))) But as Meikel said hope that this is not the end of the story. -- You received this message because you are subscribed to the Google Groups

Re: Some questions about Clojure Protocols

2010-11-03 Thread ka
AFAIK, it is not possible. You must implement all the different protocols. It might look desapointing, but on the other hand it is not necessary. (As there is no static typing in Clojure) What is your use-case? Current use case is that I want an abstraction which comprises of a set of

Re: REQUEST for feedback on http://clojure.org

2010-11-02 Thread ka
Hi Alex, Can we have a section: Clojure - What's next? Dishes out some details links for the next versions and ideas. -- 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

Clojure namespace dependencies - cdeps

2010-11-01 Thread ka
generates namespace (and package) dependency graphs at various levels - complete src, single ns, single package. Additionally the graph itself is available in many forms - Clojure map, .xml, .dot, .png The code itself is a bit ugly old but it works on both unix and windows - http://github.com/na-ka-na

Re: Clojure 1.3 Alpha 2

2010-10-27 Thread ka
Hi, Please explain this! code path for using vars is now *much* faster for the common case, and you must explicitly ask for :dynamic bindability -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: Reference Menu sans Transients

2010-10-23 Thread ka
+1, besides adding transients, protocols 1.2 features, can we also have a Future section after the Reference section? -- 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

Re: Idiomatic Way to Keep a Variable Private to a Namespace

2010-10-16 Thread ka
I've been wondering about having let over defn, I have the following concerns - 1. Not recommended in the docs http://clojure.org/special_forms#Special%20Forms--%28def%20symbol%20init?%29 says - Using def to modify the root value of a var at other than the top level is usually an indication that

Re: Cross-referencing objects?

2010-10-06 Thread ka
@Alan I'm trying to understand why you find the solution you gave gross I could construct all the objects and have a single global map, with mappings for both set-id=[objects] and object=set-id, but this seems kinda gross and obscures what is actually meant (objects belong to sets) with

Re: Clojure ensure

2010-10-02 Thread ka
I follow this thread, but haven't read Clojure's source. I have a similar question - http://groups.google.com/group/clojure/browse_thread/thread/46415b89c7b311f6, but haven't got any responses yet. -- You received this message because you are subscribed to the Google Groups Clojure group. To

Re: RFC: updated c.c.logging with some breaking changes

2010-09-07 Thread ka
These seem like good changes to me! Any plans to push? -- 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

Performance of ensure

2010-08-29 Thread ka
Hi, I have two refs a1, a2. One thread modifies a1, another modifies a2. Sample code: http://gist.github.com/556679 If I don't ensure any ref in the transaction, the code runs in ~ 0.2 ms. $ java -cp lib/clojure-1.2.0.jar\;src clojure.main -e (require 'tt) (tt/transaction-simul {:ensure2

Re: Efficiency of reduce function for lists.

2010-07-26 Thread ka
For the program, I know that when processing a character, I do not need the previous result. All I need is the current character, and I can return a function that acts on the result. I'm not sure if this is simple to implement in a functional way. Actually my understanding says that you need

Re: Small problem in CCW IDE

2010-07-26 Thread ka
So, it appears the (read-line) consumes the Clojure form (in-ns 'test.readln) probably stacked by CCW (at least I didn't type that!) Yup you're right, CCW typed that, you may disable that feature from the Windows Preferences Clojure Editor. Thanks -- You received this message because you

Re: alter atom while iterating

2010-07-21 Thread ka
@Meikal, Hi, I get what you mean. Consider the following func - (defn r [n lazy?] (.println System/out (str Called (r n ))) (let [r-lazy-seq (fn r-lazy-seq [i n] (lazy-seq (when ( i n) (.println System/out (str Realizing

Re: Leiningen 1.2.0 released!

2010-07-20 Thread ka
Awesome awesome new features !! Yes, when does windows support stop being experimental ? Even though one of the new features is - * Added experimental Windows support. Has anyone tried lein 1.2 on windows (with the lein.bat on http://github.com/technomancy/leiningen) ? -- You received this

Re: alter atom while iterating

2010-07-20 Thread ka
@Chouser Sorry, my above post was directed as a question to you. Have to stop being lazy while posting atleast :) ! -- 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

Re: alter atom while iterating

2010-07-15 Thread ka
(for [a (r 2), b (r 3)] [a b]) ; produces: range 2 (range 3 [0 0] [0 1] range 3 [0 2] [1 0] [1 1] [1 2]) Why does (r 2) get evaluated before the seq is needed ? = (def k (for [a (r 2), b (r 3)] [a b]) ) range 2 #'a/k - Thanks -- You received

Re: clojure.contrib.logging in side-effect free functions?

2010-06-24 Thread ka
To my naive inexperienced eyes, there doesn't seem to be something obviously wrong with your code. Since FOR returns a lazy sequence of the results, is this function safe? (Seeing that it is not side-effect free?) I'm not getting this, do you foresee any safety issues? I think that the logs

Re: Can't send from agent error handler?

2010-06-24 Thread ka
I'm also facing the same problem - (let [handler (agent 50) a (agent 42 :error-handler (fn [_ ex] (do (println Inside agent a error handler fn (Thread/ currentThread)) (send handler (fn [_] (do

Re: Transform columnar data into a tree?

2010-06-23 Thread ka
How about this (using only map, reduce) - user= (def data1 [[:a1 :b1 :c1] [:a1 :b1 :c2] [:a1 :b2 :c3] [:a1 :b2 :c4] [:a2 :b3 :c5] [:a2 :b3 :c6] [:a2 :b4 :c7] [:a2 :b4 :c8]]) user= (pprint (reduce (fn f [tree

Re: Enhanced Primitive Support

2010-06-21 Thread ka
My favorite option of those proposed is: +, *, -, inc, dec auto-promote. loop/recur is changed so that primitive bindings are boxed. +',*',-',inc',dec' give error upon overflow. A new construct, loop', is introduced that doesn't box primitives and enforces recur with primitive upon penalty

Re: API in Clojure for Java folklore

2010-06-05 Thread ka
Since the stubs are around, you can also run JavaDoc. The stubs don't need to be saved. In the Maven world, they are part of the build, not source files. On Jun 4, 8:03 am, ka sancha...@gmail.com wrote: @Jason I'm supplying a Java API (implemented in Clojure) so needed a solution quickly

Re: Having trouble getting full performance from a quad-core with trivial code

2010-06-03 Thread ka
Hi Zak, It seems very weird that my version of fac changes performance characteristics on my machine and not yours (OS/hardware dependent?). Can you tell your hardware configuration, esp. number of physical and logical cores? I am planning next to leave out using pmap and just try to run the

Re: Having trouble getting full performance from a quad-core with trivial code

2010-06-01 Thread ka
Hi Zak, I tried your example on my i7 (4 physical cores, 8 logical); here are the results - 1:298 user= (time (do (doall (map fac (take 10 (repeat 5 nil)) Elapsed time: 54166.665145 msecs 1:300 user= (time (do (doall (pmap fac (take 10 (repeat 5 nil)) Elapsed time: 27418.26344

Understanding sequence abstraction

2010-05-30 Thread ka
Hi Clojurians, I have some conceptual questions on the sequence abstraction. I understand that (seq coll) will give me a sequence. coll maybe be a list, vector, map, set, LazySeq or nil. 1. In case coll is a LazySeq why does (seq coll) realize its first element? I thought seq just did a type

Re: API in Clojure for Java folklore

2010-05-28 Thread ka
I've also added a :class-doc key to the macro - (gen-class+javadoc :class-doc Class Docs ul li One /li li Two /li /ul :name a.b.c.MyCoolClass :methods [ #^{:static true} [method1 [clojure.lang.PersistentArrayMap] int]

Re: Some suggestions for transients

2010-05-28 Thread ka
Oops didn't know that Rich had already answered. Google seems to think that our posts are commutative :/ (often they're not, or are they? I can't take a stand on this) and just uses the commute fn instead of using alter and failing the transaction (informing us); but it does allow for more

Re: Todo item annotation in Clojure.

2010-05-27 Thread ka
This looks cool. I'll definitely give it a try in my next project. Any chance to get it integrated somehow with eclipse ccw? - Thanks -- 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: do clojure and la(tex) have something in common ?

2010-05-27 Thread ka
Hi Tim, Thanks! for such a detailed response. Really got things in perspective for me, my thinking yet isn't of such large scale. So you say literate programming is for those who are writing code that will live for decades to come and that writing literate programs takes ~3x resources. Is

Re: Comparing Cycle

2010-05-27 Thread ka
It would be voodoo magic :) and totally awesome might I say if (= a (drop 4 a)) returned true immediately! - Thanks -- 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

Re: Some suggestions for transients

2010-05-27 Thread ka
My 2 cents, I read about transients for the first time (why is the page not linked from clojure.org?) and they seem very promising at a first glance. I'm not sure if I agree with Michael's idea of having the same functions for transients and persistents both. Functions should have easy,

Re: promoting contrib.string to clojure, feedback requested

2010-05-27 Thread ka
Stefan Kamphausen writes: sorry, I'm a little late. However, to me it is not clear what the trim functions shall do. If they become a replacement for chomp they are clearly misnamed. In many applications and languages (like Excel, several SQL variants, oh, and Java, ...) trim means

Re: do clojure and la(tex) have something in common ?

2010-05-25 Thread ka
Tim, I don't know much about either lisp or latex :). But it looks like a really neat idea at a first thought to me. Have two remarks- 1. From the developer's pov - I'm not sure how the developer, who is accustomed to looking at just code + some comments, will manage working with the book. But

Re: Dividing list by predicate

2010-05-24 Thread ka
You may use reduce, as follows: (let [r (java.util.Random.) f (fn [el] (.nextBoolean r))] (def pred f)) (reduce (fn [m el] (let [k (pred el)] (assoc-in m [k] (conj (m k) el {true [] false []} (range 10)) Thanks -- You received this message

Re: finding combinations given a coll and selection of n

2010-05-22 Thread ka
As Steve said, better look at the combinatorics-api. As for your original code, the idea you have gives all permutations not combinations! Few changes will make it functioning - (defn permutations [n coll] (if (= n 1) (map #(vector %) coll) (for [el coll nlis (permutations (- n

Re: reducing multiple sets

2010-05-22 Thread ka
1:6 user= (use '[clojure.set]) nil 1:7 user= (reduce union #{} #{#{[3 2] [5 4] [3 3] } #{[4 3] [5 4] [3 3] } #{[3 2] [2 2] [3 3] } } ) #{[3 2] [4 3] [5 4] [2 2] [3 3]} 1:8 user= Thx -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this

Re: API in Clojure for Java folklore

2010-05-22 Thread ka
Hi, any responses? -- 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,

API in Clojure for Java folklore

2010-05-21 Thread ka
Hi all, I've written an API in Clojure to be consumed by people working in the Java world. Now most of these people haven't even heard of Clojure; but all they care about is 1) a working API and 2) with nice documentation. 1) Something about the API - I tried out various things, types, records,

Re: Block on structure until some data appear

2010-05-15 Thread ka
@Michael, There is already a monitor mechanism available in Clojure via the 'locking' macro or more primitive monitor-enter, monitor-exit. So in your case all you have to implement is the blocking behavior, I'm not sure if it can be already done somehow using just Clojure elements. The above code

Re: Block on structure until some data appear

2010-05-14 Thread ka
If add-watch is not what you want because you want the consumers to have a life of their own, then does something like this work? - (def my-hash (ref {})) (def new-keys (ref #{})) (defn produce [] (let [new-key (rand-int 10) new-val P] (Thread/sleep 100) (dosync (alter

Re: Block on structure until some data appear

2010-05-14 Thread ka
 pm, ka sancha...@gmail.com wrote: If add-watch is not what you want because you want the consumers to have a life of their own, then does something like this work? - (def my-hash (ref {})) (def new-keys (ref #{})) (defn produce  []   (let [new-key (rand-int 10)         new-val P

Re: Block on structure until some data appear

2010-05-14 Thread ka
You can get rid of the I/O in the transaction and still see a consistent snapshot by simply return the contents of the refs. (defn report-status   []   (apply println (dosync [...@my-hash @new-keys]))) Sincerely Meikel -- Isn't ensure necessary? Because http://clojure.org/refs says

Re: Annoying auto-signature

2010-05-09 Thread ka
+1 On May 7, 2:13 am, Mibu mibu.cloj...@gmail.com wrote: Am I the only one driven mad by the new auto-appended signature to every message in this group (You received this message because you are subscribed...)? It started on April 16th. Is there a way a moderator can stop it? -- You

Re: Why Clojure rocks..

2010-05-09 Thread ka
Not wanting to become an uninvited guest to your party :-) ... but do you mind elaborating .. ? On May 9, 2:31 am, Base basselh...@gmail.com wrote: I just replaced 443 lines of java with 61 lines of Clojure. THANK YOU RICH !!! -- You received this message because you are subscribed to the

Re: Try + finally question

2010-05-01 Thread ka
are constructed ? 2010/4/29 Alex Osborne a...@meshy.org: ka sancha...@gmail.com writes: Above I wrote a macro with-open-flexi! ... which I'm planning to use in my app's API . .. please let me know if there are any bugs / gotchas / improvements etc... I didn't get any responses, so does

Re: Try + finally question

2010-04-29 Thread ka
Hi ppl, Above I wrote a macro with-open-flexi! ... which I'm planning to use in my app's API . .. please let me know if there are any bugs / gotchas / improvements etc... I didn't get any responses, so does it means there is something so obviously wrong that you can't even begin where to start

Re: Try + finally question

2010-04-23 Thread ka
would be useful, if only as syntactic sugar. On Wed, Apr 21, 2010 at 10:43 AM, ka sancha...@gmail.com wrote: Thanks all for replies. Laurent, Alex you guys are right, the problem is only with aesthetics of nesting / boilerplate.  The nesting implementation semantically expresses exactly

Try + finally question

2010-04-21 Thread ka
Hi, I'm using an API to connect to a server which does not provide constructors, just static methods to get close connections. How can I do something like ... (try (let [conn (API/getConnection ..)] ()) (catch ..) (finally (if conn (API/closeConnection conn Problem is that

Re: Try + finally question

2010-04-21 Thread ka
.closeConnection(conn2); } I agree that this code doesn't look good from a purist pov, but any issues besides that? - Thanks! On Apr 21, 4:58 pm, Alex Osborne a...@meshy.org wrote: ka sancha...@gmail.com writes: How can I do something like ... (try   (let [conn (API/getConnection

Re: Try + finally question

2010-04-21 Thread ka
{$s ~= 'd';} default {$s ~= 'z';} } is $s, 'c', 'Caught number'; }; Thanks! On Apr 21, 7:05 pm, Alex Osborne a...@meshy.org wrote: ka sancha...@gmail.com writes: The whole code gets cluttered with all these try finally (and one catch) statements.   (try     (let [conn1

Permutations of n things

2010-02-14 Thread ka
I'm trying to make a function which gives the n! permutations of a vector of n things. Here is my first attempt : (defn permute Gives the n! permuations of the input vector of things [v] (if (= 1 (count v)) (list [(v 0)]) (loop [i 0 perm '()] (if (= i (count v)) perm

Re: Newbie question - Functional programming special cases

2010-02-10 Thread ka
Thanks, that answers my questions. -- 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

Clojure binding for Open CL

2010-02-10 Thread ka
Hi, I was just wondering if (by now) Open CL has been 'wrapped' by higher level languages. I came across these from the Khronos site (http:// www.khronos.org/developers/resources/opencl/#timplementations) - 1. http://ruby-opencl.rubyforge.org/ 2.

Newbie question - Functional programming special cases

2010-02-01 Thread ka
Hi clojure folk, I'm reading up on clojure from the book 'Programming clojure'. In chapter 2 there is a statement - The imperative indexOfAny must deal with several special cases: null or empty strings, a null or empty set of search characters, and the absence of a match. These special cases