Re: slow mysql inserts
I suspect that ClojureQL and with-connection are opening and closing the connection for every query, whereas the Java and Perl versions are reusing their connections. Try adding a connection pool to the mix. On Tue, Jan 18, 2011 at 19:32, rygorr ryg...@gmail.com wrote: I'm currently doing some preliminary performance testing of db inserts with various technologies. The db server itself is nothing special but what surprised me was the difference in INSERT speeds between Clojure and the other solutions I've tried. Clearly there is something I'm missing so perhaps I can get some insight. Java code INSERT was about 500 rows/sec. The Clojure code was about 30 rows/sec (both ClojureQL and with-connection versions). Perl DBI and ObjC were both around 500 rows/sec. I'm comparing relative speed -- the 'mysql server' is just a mac-mini running Mysql 5.0. While I recognize this is a pretty simplistic seat-of-the-pants test I wasn't expecting 16x slower. ClojureQL code: (def test (sql/table db :test)) (doseq [x (range 2000)] @(sql/conj! test [{:value x}])) Vanilla clojure code I tried as well. (doseq [x (range 2000)] (with-connection db (insert-values :test [:value] [x]))) db is the com.mysql.jdbc.Driver connection string. Pure Java: for(int i = 2000 ; i0 ; i--){ try { java.sql.Statement s = conn.createStatement(); s.executeUpdate(insert into test (value) values( + i + )); } catch (Exception e) { System.out.println(e); System.exit(0); } } where conn here is again my com.mysql.jdbc.Driver connection string. I used the same mysql-connector-java jar for all tests on the JVM. Initially my tests were run in the cake-swank JVM. To try to eliminate any variables I also created a jar with lein and tested that. The pure java code was compiled and run command line. I don't believe for a second this is an issue with clojure, but to be honest I'm not clear where to start troubleshooting. What sort of things can I play with to figure out where the bottleneck is? 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 members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: why not change type compare functions do a compare on strings as well?
I think it will make more sense to branch on whether something is Comparable or IComparable, than a string. On Mon, Nov 29, 2010 at 08:59, Tim Robinson tim.blacks...@gmail.com wrote: why not change type compare functions do a compare on strings as well? (defn ([x] true) ([x y](if (string? x) (. clojure.lang.Numbers (isPos (.compareTo x y))) (. clojure.lang.Numbers (gt x y ([x y more] (if ( x y) (if (next more) (recur y (first more) (next more)) ( y (first more))) false))) (defn ([x] true) ([x y](if (string? x) (. clojure.lang.Numbers (isNeg (.compareTo x y))) (. clojure.lang.Numbers (gt x y ([x y more] (if ( x y) (if (next more) (recur y (first more) (next more)) ( y (first more))) false))) It's just cleaner so we can do things like: user= ( 2010-06-11 2010-11-01) true user= ( Banana Apple) false make sense? Notes: * I ran a bunch of benchmarks, showing no real impact on performance. * probably would need to include = and = too. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Reference Menu sans Transients
+1 and a vote to also add these: http://clojure.org/protocols http://clojure.org/datatypes On Sat, Oct 23, 2010 at 12:08, ka sancha...@gmail.com wrote: +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 members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Best practices for protocols
My understanding of protocols is this: they are an abstraction representation of data. They allow you to write functions, building upon the protocol, such that they work for all concrete implementations of that protocol. So the protocol is a view on data. And the many ways of modifying the data is left out, and put in functions. Before defining a new protocol, I think it is a good idea to ask oneself if one could not just as well have built something out of maps, lists and vectors, and a set of higher-abstracted functions. I hope these thoughts can inspire you to an improved design. On Fri, Oct 15, 2010 at 20:58, K. kotot...@gmail.com wrote: If your protocol functions generally look like : display that data on this view, then why not leverage multimethods and double dispatch ? I think I choose a misleading example, sorry about that. I'm working mainly with one kind of data, but there a lot of functions. For instance one function will display the search result, another will notify the view of a particular change in the document etc. Data are big so changes are done incrementally at the view level. That means there is a function for each kind of change. Then a function for each kind of listeners (I wanted to abstract the concrete listeners from the controller) etc. Other functions are for setting a dirty marker etc. There is merely only one view : the one used to edit the document. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Generating special classes
Actually... what I *really* want is your clj-native library :D Is this it? http://github.com/bagucode/clj-native On Wed, Oct 6, 2010 at 07:21, mac markus.gustavs...@gmail.com wrote: There is always clojure.asm if you don't mind getting your hands dirty with bytecode generation. That's what I did when I needed exactly what you describe for clj-native. It wasn't that much work, the JVM bytecode is uncomplicated to begin with and since JNI method stubs require no code all you have to do is generate class skeletons. You might have trouble with AOT compilation though, if you want to support that you need to detect when it's happening (*compile-files*) and save your class to a class file instead of loading it directly. Would be nice with core support for native (JNI) methods though, perhaps something similar to :static? /Markus On Oct 5, 6:18 pm, nickikt nick...@gmail.com wrote: deftype? On 5 Okt., 17:42, Christian Vest Hansen karmazi...@gmail.com wrote: I suppose there's no better way to generate classes with custom static initializers and methods with the native keyword, other than perusing the innards of gen-class? -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Generating special classes
I suppose there's no better way to generate classes with custom static initializers and methods with the native keyword, other than perusing the innards of gen-class? -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: testing local functions?
From someone who's window to your code is your public API, a refactoring should make no observable change. So if you only test on the public API, but you test it thoroughly, then your tests will ensure that this property holds. Tests that delve into implementation details and private things, are more brittle because they are affected by changes in implementation details. On Fri, Sep 10, 2010 at 14:16, alux alu...@googlemail.com wrote: Hi James, thanks for your answer. your tests should be testing your public interface Hhmmm. Well, I tend to disagree here. I sometimes like to have tests in place for things I want to refactor. To not inadvertently do something foolish. But I agree that this is not easily accomplishable. Greetings, alux On 10 Sep., 13:39, James Reeves jree...@weavejester.com wrote: On 10 September 2010 12:24, alux alu...@googlemail.com wrote: I always thought it to be good style to make helper functions only as visible as needed, e.g. by using letfn. But when I want to test my code, I just dont see a way to access these local functions for tests. I don't believe you can. You could make them private functions, and then test them by referring directly to their vars, e.g. (#'your.namespace/private-function ...) But in general, your tests should be testing your public interface, not a specific implementation. Your tests shouldn't care what your code does behind the scenes, so long as the publicly accessible functions return the correct result. - James -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Bug in try/finally?
The bug has nothing to do with try-finally. Take a look at the macro expansion: user= (macroexpand '(.. (System/out) (print -) (println -))) (. (. (System/out) (print -)) (println -)) You are trying to call 'println on what ever 'print returns. But 'print is a void method. On Tue, Aug 10, 2010 at 08:36, Brian Stiles brian.sti...@gmail.com wrote: The following succeeds: (try (prn 1) (finally (prn 2) (doto (System/out) (.print -) (.println - prints: 1 2 -- The following fails (note the odd duplication of 2 in the output): (try (prn 1) (finally (prn 2) (.. (System/out) (print -) (println - prints: 1 2 -2 -Exception in thread main java.lang.NullPointerException (NO_SOURCE_FILE:0) at clojure.lang.Compiler.eval(Compiler.java:4658) at clojure.core$eval__5236.invoke(core.clj:2017) at clojure.main$eval_opt__7411.invoke(main.clj:227) at clojure.main$initialize__7418.invoke(main.clj:246) at clojure.main$null_opt__7446.invoke(main.clj:271) at clojure.main$main__7466.doInvoke(main.clj:346) at clojure.lang.RestFn.invoke(RestFn.java:426) at clojure.lang.Var.invoke(Var.java:363) at clojure.lang.AFn.applyToHelper(AFn.java:175) at clojure.lang.Var.applyTo(Var.java:476) at clojure.main.main(main.java:37) Caused by: java.lang.NullPointerException at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:26) at user$eval__1.invoke(NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:4642) ... 10 more -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Most elegant way of comparing vectors?
You can use the equality function (=) if the ones and zeroes have to be in the same exact places in the matrix: user= (= [1 0] [1 0]) true user= (= [1 0] [0 1]) false user= (= [[1 0] [0 1]] [[1 0] [0 1]]) true user= (= [[1 0] [0 1]] [[1 0] [1 0]]) false user= If the shapes can be offset inside the matrix, then I'm afraid you will have to device a more complex algorithm. Also, less idiomatically I suppose, if the matrices are always four by four cells, then the whole matrix can be represented in a short (the number type short). :p On Wed, May 19, 2010 at 8:39 AM, Thomas Kjeldahl Nilsson tho...@kjeldahlnilsson.net wrote: Hello, newbie question here. :) I'm writing a Tetris game to teach myself Clojure, and I'm trying to keep the code ideomatic as I go along. One of the most basic parts of the underlying model is representing the pieces and playing field as two dimensional matrices. This is an L shaped playing piece (represented by a two dimensional vector literal): (def L-shape [ [0 1 0 0] [0 1 0 0] [0 1 1 0] [0 0 0 0] ]) I want to check if other matrices of same size have the same shape, ie. are the 1's and 0's in the same places in the compared matrix? I suppose the most straight-forward way is write a function which steps through the two matrices simultaneously, comparing corresponding elements one by one. My question: is there a more elegant way of determining equivalence of collection structures like these in Clojure? -- Cheers, Thomas Kjeldahl Nilsson http://kjeldahlnilsson.net -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Problem using count
On Tue, Mar 9, 2010 at 6:26 AM, Srini devfac...@gmail.com wrote: Hi. I am completely new to clojure - my 3rd day or so. Need to go buy a book on the subject. So please help me with a couple of things: Item 1) I have two calls to count. One works, and the other does not. ; counts number of items in collection user= (count (list 1 2 3 4 er 34) ) 6 ; count does not work. I get an exception. Need to figure out what I am doing wrong here. user= (count (list 23 3er oel 5) ) java.lang.Exception: EOF while reading string You are missing a double-quotation character before eol Item 2) I see from the documentation that the contains? function (it is a function, right? just want to be sure. this is my 2nd or 3rd day learning about clojure.) returns true if key is present in collection. And there is a reference in the online docs to numerically indexed collections like vectors and Java arrays. In the following examples, the first one works as I expected. But the second one does not work as I thought. How do I check if an item is in a list? ; does the vector contain index 0? user= (contains? [1 2 3 4] 0) true ; could not get it to work for lists. apparently works only for numerically indexed collections like vectors. ; doesn't throw an exception either. intuitively, I think the following should have returned true. user= (contains? (list 3e 2 tired 1 more) 3e ) false I think contains? only work on things that are associative: user= (associative? []) true user= (associative? (list)) false So a list is not associative, as it has no (near) constant-time way of looking up things in it by index, key or value. Maybe you want to use a set instead of a list: user= (contains? #{3e 2 tired 1 more} 3e ) true Your help is much appreciated. Thank you for your time. - Srini As an aside, I guess I am approaching this as I have regular procedural languages like C, C++, Java, C#, VB, and my all-time favourite so far - Python, etc. And its taking a different kind of thinking to even understand the basics of closure since its just so different from the others. I am recording my learning experiences in my very first blog ever :) http://closurefp.blogspot.com/ Hopefully it will help someone. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Possible change to launch script in homebrew
I want to change the clojure launch script in homebrew (a package manager for Mac OS X), but before sending a pull request I want to bounce it off of you guys. The existing script was pretty minimal, and I wanted to at least have it check if rlwrap was available. These are the changes I've made: * It will use rlwrap if it is available on the PATH * It now takes a -cp or -classpath argument, which is appending to the existing one (including $CLASSPATH) * It no longer launches the -server VM by default * It is now possible to pass flags to the JVM with -J flags. Examples: -J-server -J-Dname=value -J-Xmx2g My brew formular is located here: http://github.com/karmazilla/homebrew/blob/master/Library/Formula/clojure.rb -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: locking semantics: queue for the monitor?
I think it uses intrinsic locks, which are always non-fair. You can instantiate fair locks (what you are asking for) with the implementations in this package: http://java.sun.com/javase/6/docs/api/java/util/concurrent/locks/package-summary.html But that requires you use lock.lock() and lock.unlock() directly in a try-finally structure. On Thu, Oct 15, 2009 at 4:26 PM, Garth Sheldon-Coulson g...@mit.edu wrote: Hi All, If multiple threads are competing for the monitor of an object using (locking obj ... ), is it a strict queue for the monitor (first in, first lock) similar to send and send-off? Or are there other considerations? I would probably know this if I knew more about Java sync, but quick web/groups searches don't give a clear answer. Sorry for the basic question. Garth -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Metadata: something funny
On Sun, Sep 20, 2009 at 6:20 PM, samppi rbysam...@gmail.com wrote: I was messing with the REPL when I found this happens: Clojure 1.0.0- user= (def a #^{:a 5} [1 2 3]) #'user/a user= ^a {:a 5} user= (def b #^{:b 2} '(1 2 3)) You have a quote symbol in there, so that line can also be written as: (def b #^{:b 2} (quote (1 2 3))) #'user/b user= ^b {:line 3} user= (def c (with-meta '(1 2 3) {:c 0})) #'user/c user= ^c {:c 0} What's going on with that {:line 3}? Is it something that the REPL is doing? Where did {:b 2} go? And why does it happen with the reader macro #^ and not with-meta? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Metadata: something funny
On Sun, Sep 20, 2009 at 7:25 PM, Christian Vest Hansen karmazi...@gmail.com wrote: On Sun, Sep 20, 2009 at 6:20 PM, samppi rbysam...@gmail.com wrote: I was messing with the REPL when I found this happens: Clojure 1.0.0- user= (def a #^{:a 5} [1 2 3]) #'user/a user= ^a {:a 5} user= (def b #^{:b 2} '(1 2 3)) You have a quote symbol in there, so that line can also be written as: (def b #^{:b 2} (quote (1 2 3))) ... and #^{} applies read-time to the following *form* rather than the value they evaluate to, so that is why neither (list ...) nor (quote ...) work. #'user/b user= ^b {:line 3} user= (def c (with-meta '(1 2 3) {:c 0})) #'user/c user= ^c {:c 0} What's going on with that {:line 3}? Is it something that the REPL is doing? Where did {:b 2} go? And why does it happen with the reader macro #^ and not with-meta? -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Ensure and STM: find the bug...
On Thu, Sep 17, 2009 at 6:28 AM, Krukow karl.kru...@gmail.com wrote: On Sep 16, 10:06 pm, Rich Hickey richhic...@gmail.com wrote: On Sep 16, 11:39 am, Stuart Halloway stuart.hallo...@gmail.com wrote: The docs could be more clear, but if validate-fn must be side effect free then it certainly can't look at any other refs. Yes. The docs should say the function must be pure. While I understand the multi-ref validation use case, currently it is not supported. Ok, I guess I was thinking of a side-effect as something that *changes* state. When you take a lock, you change the state of that lock, and that state-change is a side-effect that can be observed by everyone who have access to that same lock :) That, however, is probably easy to forget. Like it is also easy to forget that deref'ing a ref means taking and releasing a read-lock. But I see that pure is really means referentially transparent in this case (which does not include looking at other refs). I would suggest that the docs are changed to: ... validate-fn must be nil or a side-effect-free (referentially transparent) fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an exception. validate-fn will be called on transaction commit, when the ref has its final value. Validation across multiple refs is currently not supported or some variant of that (not sure the 'referentially transparent' comment is necessary, although it was helpful for me :-). One question I would like to ask is about increasing concurrency in the use-case I mentioned in this post. In my example I have two accounts a1 and a2, requiring that @a1 + @a2 = 0 invariably. A withdraw transaction that ensures one account, checks that the invariant holds, and does the withdrawal from the other is really permitting less concurrency than what is optimal. The call to ensure prevents/serializes also any concurrent activity which would not violate the constraint that @a1 + @a2 = 0, e.g., a concurrent deposit. So it seems that multi-ref validation also has a use-case in terms of increased concurrency (i.e., retry only if the invariant doesn't hold)? Any thoughts? Final question. The docs say that 'ensure' permits more concurrency than promoting the ref to a write. Is there a quick/simple way of explaining how? (Or do I need to go to the source :-) Thanks for the clarifications /Karl -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Eval troubles
You need to unquote the x to get its value from the let. You can do that with the tilde character inside syntax quotes: user= (let [x 1] (eval `(inc ~x))) 2 On Thu, Sep 3, 2009 at 8:24 AM, Miron Brezuleanumbr...@gmail.com wrote: Hello, I'm a Clojure newbie (many thanks to Rich Hickey and everyone involved - it's a great programming environment) and I have some trouble with 'eval'. What I'm trying is: $ java -cp clojure.jar clojure.lang.Repl Clojure 1.1.0-alpha-SNAPSHOT user= (let [x 1] (eval '(inc x))) java.lang.Exception: Unable to resolve symbol: x in this context (NO_SOURCE_FILE:1) (on a freshly downloadedcompiled clojure from github) According to my understanding of http://clojure.org/evaluation, my code should simply return 2. What am I missing? :-) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: clojure vs scala
On Tue, Aug 25, 2009 at 10:43 PM, npowellnathan.pow...@gmail.com wrote: On Aug 25, 4:36 pm, Christian Vest Hansen karmazi...@gmail.com wrote: I think he misrepresents both Scala and Clojure. ... Not a super helpful assessment. I'd like to hear more. What do you disagree with and why? Listed as a downer for Scala: Functional programming can be difficult to understand for a Java developer - same can be said for Clojure, so I think it is a similarity but he presents it as a difference. Another Scala downer: Scala is very powerful, some developers might shoot themselves into the foot - I don't see how this applies more to Scala than Clojure. If we want to talk about foot-shooting, we could talk about macros. There are some common mistakes that people with weak macro-fu do. Granted we can argue that people learn not to do these mistakes, but this learning still has to take place, and since the article is about which language to learn, I assume that this learning has yet to happen to these mentioned some developers. I would also like to mention the age-old dynamic vs. static typing debate because there's a twist to it here I'd like to point out: This is an assumption because I don't know Scala that well, but; I think it is harder to reason about performance and write fast code in Clojure than it is in Scala. I don't buy the no objects argument against Clojure. He links to Halloways rifle-programming article that presents object oriented using multimethods, so I presume he means no objects as in no ability to define classes and interfaces, but that is what gen-class, gen-interface and proxy are for. And new-new, at some point. I think Scala an advantage in this regard with native syntax for these concepts. I think the comparisons are inevitable, and knowing more about both helps developers make good choices. Your ideas about how to represent both languages would be valuable. They are at least provided above. I mean, I didn't think the article was terribly in depth, but a real, evenhanded comparison would be enlightening. I'm no position to do an evenhanded (objective?) comparison - I don't know the languages well enough to do that. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: clojure-maven-plugin 1.0 released and in maven central
How does it work if you have both Java and Clojure code in the same project? Which is compiled first? On Tue, Aug 25, 2009 at 12:46 PM, Mark Derricuttm...@talios.com wrote: For my own usages I've just been using IDEAs native maven support and opening the pom.xml - This sadly doesn't pick up the source directories thou. -- On Tue, Aug 25, 2009 at 7:33 PM, Laurent PETIT laurent.pe...@gmail.com wrote: Excellent, thanks Mark for this contribution ! When time permits, I'll undoubtedly give a thorough look at it, and see how I can integrate this with Counterclockwise (new name for clojure-dev eclipse plugin). Something like a mvn clojure:eclipse that could extend the eclipse:eclipse goal for initializing the eclipse project with the clojure nature, and use the provided strategy for resolving namespaces to compile. Regards, -- Laurent 2009/8/24 Mark Derricutt m...@talios.com Hey all, I've released 1.0 of my clojure-maven-plugin and its now available in maven-central. To use it, a minimal pom.xml declaring a dependency on clojure, and the the plugin (without configuration) is all you need. - http://gist.github.com/174217 With the above pom, running mvn clojure:compile will scan any .clj file under ./src/main/clojure and compile them into the ./target/classes directory. mvn clojure:test-compile will do the same for any .clj file under ./src/test/clojure. For more options such as hooking up a test script, filtering namespaces etc. see the project site at: http://github.com/talios/clojure-maven-plugin Mark -- Discouragement is a dissatisfaction with the past, a distaste for the present, and a distrust of the future - Maree De Jong, Life NZ. blog: http://www.talios.com podcast: http://www.illegalargument.com skype / twitter: talios -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: clojure vs scala
I think he misrepresents both Scala and Clojure. On Tue, Aug 25, 2009 at 7:11 PM, Emekaemekami...@gmail.com wrote: Hello All, This sounds great! http://codemonkeyism.com/clojure-scala-part-2/ Regards, Emeka -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure with maven - how to?
Did you remember to push your tags? (git push --tags) On Sun, Aug 16, 2009 at 9:51 PM, Mark Derricuttm...@talios.com wrote: I posted a simple example project to: http://github.com/talios/clojure-maven-example last night which demonstrates the plugin. As I mentioned in a post to this list yesterday theres 3 tags - step1, step2, step3. step1 just has a basic pom and a test, step2 pulls in compojure and a simple webapp, step3 adds a simple automated test for that compojure app. Mark -- On Sun, Aug 16, 2009 at 3:03 AM, Dragan Djuric draga...@gmail.com wrote: Can somebody help by posting a hello world example for one of (or both :) these issues? :) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: binary serialization
Java object serialization handles cycles based on object identity. On Tue, Aug 11, 2009 at 6:17 AM, fft1976fft1...@gmail.com wrote: On Aug 10, 8:19 pm, Kyle R. Burton kyle.bur...@gmail.com wrote: Does all this work with cycles, Java arrays, etc.? It will work with anything that implements the Serializable interface in Java. Arrays do implement that interface, as do all the primitives. With respect to cycles, I'd suspect it does, but would test it. If you have a repl handy it should be pretty easy to test those functions out on your data structures. What class has the cycle? Is it a standard collection? Cycles are a special case of substructure sharing. Let's talk about that instead. (def common [1 2 3 4 5]) (def a [6 common]) (def b [7 common]) (def c [a b]) If you are serializing c, I want common to get copied only once. I don't know JVM too well, but I think no efficient user-level solution is possible. Why? To take care of substructure sharing, you need to remember a set of shareable values that have already been serialized, and do reference equality comparisons when new new substructures are serialized. This comparison and a set implementation can easily be done with pointers (because you have ), but there are no pointers in the JVM, and no reference inequality, so you must use linear seeks, making the time complexity of serialization quadratic, where in C/C++ it could be O(N log N) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Good memory profilers (program or human)?
together. But first I'd like to explain why it is using so much, because I must be missing something. Thank, Andy -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Examining performance on the JVM
I haven't tried to look beyond the JIT to see what it does, so I wouldn't know which tools to use, but if you do not already know about it, you might find the HotSpot Internals wiki to be an interesting source of info: http://wikis.sun.com/display/HotSpotInternals/Home On Thu, Jul 16, 2009 at 5:39 AM, Bradbevbrad.beveri...@gmail.com wrote: I see lots of discussion on this list about Clojure performance how to get it to Java speed. I am also interested in the next steps that happen, how does the JVM convert byte code down to machine code and how does one examine that? The profiling tools I use for C code let me look at what the compiler has done with my C/C++ code where the machine is running slow (cache misses, pipeline stalls, etc). JVM apps obviously have another layer of indirection, the first layer is the quality of the byte code that has been generated, and then how hotspot compiles that into machine code. What tools are out there that let you examine the bytecode JVM machine code output? It would also be really nice if there were tools that told you why the JVM did or did not manage to optimize a block of code. I'm just curious here really, but it does seem like there are many knowledgeable people on this list that might be able to offer some tips. Thanks, Brad -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: FnParse, a functional parsing library
Tangentially relevant comment, FYI: You'd be hard pressed to find a JSON parser on the JVM that is faster than Jackson. On Mon, Jul 6, 2009 at 2:55 AM, Wilson MacGyverwmacgy...@gmail.com wrote: Thanks for the tip on looking at clojure.contrib. I keep forgetting to check there. On Jul 5, 2009, at 4:20 PM, samppi rbysam...@gmail.com wrote: If you need a JSON parser, there's already a good one included with clojure.contrib. The one with the FnParse library is just a sample to show how it works. But please feel free to use it however it can be useful to you. :) On Jul 4, 1:45 pm, Wilson MacGyver wmacgy...@gmail.com wrote: Very timely, I need to parse a bunch on JSON files on Monday :) good work Sent from my iPhone On Jul 4, 2009, at 3:16 PM, samppi rbysam...@gmail.com wrote: I'm pleased to announce FnParse, a monadic functional parsing library for Clojure, half a year in the making. I started on FnParse in December as my first Clojure project, and now it has matured to something that I believe is very and immediately useful. Currently, I'm writing a YAML parser using FnParse. With FnParse, you can easily parse a string or any sequence of tokens into native data structures. FnParse is based on the concept of the rule, a self-contained function that accepts a state data structure, containing a sequence of tokens, and either consumes some tokens-- turning them into new data--or fails. Rules correspond nicely to EBNF productions and productions in other sort of grammars. FnParse provides common rules, functions that create new rules, and functions that facilitate using rules. A sample JSON parser is athttp://wiki.github.com/joshua-choi/ fnparse/sample-json-parser . Online documentation is available at:http://wiki.github.com/joshua- choi/fnparse . The source is at:http://github.com/joshua-choi/fnparse. If you are confused about anything or find any bugs, please create an issue on GitHub (http://github.com/joshua-choi/fnparse/issues) or send me a message on GitHub. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Java STM
I believe that DeuceSTM i primarily intended as a research platform for Java STMs, hence the flexibility with pluggable algorithms. Another Java STM is multiverse: http://code.google.com/p/multiverse/ - the focus here is on performance. Multiverse is based on MVCC, like the Clojure STM. Both of these STMs operates with the mindset that objects are mutable by default, and tries to control this mutability. Whereas in the world of Clojure we have mutable references pointing to immutable values. In fact, the correctness of the Clojure STM depends on the objects stored in the refs be immutable. On Mon, Jul 13, 2009 at 2:07 AM, Vagif Verdivagif.ve...@gmail.com wrote: Potentially interesting library for clojurians. Java STM implementation: http://www.deucestm.org/ -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure STM not serializable
You can use `ensure` if you want to make sure that the transaction fails if a or b are altered while the threads are sleeping in your example: http://clojure.org/api#ensure Otherwise, regarding serializable concurrency level: If you want mutual exclusion, then that's what locks are for. On Thu, Jun 18, 2009 at 8:38 AM, Eric Willigersewillig...@gmail.com wrote: Hi all, I'm enjoying using Clojure. It is clean, concise and powerful. The containers and even defmacro are easy to use correctly. However, I'm yet to be convinced the same applies with the STM implementation. In the user code below, people might expect b == a + 1 after the two transactions run. Unfortunately, that isn't the case, as no read locks are being taken. (It would have been true if the transactions ran sequentially, in either order.) Is the lack of isolation affecting people, or do most users use idioms that avoid the problem? Example idioms would be writing every ref that is read, or using a single ref to switch to a new immutable data structure (as opposed to implementing mutable data structures using numerous refs). Regards, Eric. P.S. I'm aware Oracle and PostgreSQL similarly have non-serializable transactions. (def a (ref 0)) (def b (ref 0)) (.start (Thread. #(dosync (let [old-a @a] (Thread/sleep 2000) ; or any slow computation (ref-set b (inc old-a)) (.start (Thread. #(dosync (let [old-b @b] (Thread/sleep 2000) ; or any slow computation (ref-set a (dec old-b)) (Thread/sleep 6000) ; or join the above threads (println a= @a , b= @b) a= -1 , b= 1 -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: The thread ring problem
For kicks, I made an implementation* using agents: http://gist.github.com/119946 I think that you may not want to use the STM so much and instead figure out a different approach to sending the token around the ring. *it may be a bit liberal in its interpretation of the rules... didn't read them that carefully. On Fri, May 29, 2009 at 2:32 PM, Alvaro Vilanova Vidal alv...@gmail.com wrote: Hi everyone, I am a newbie in clojure world, so I have some newbie's questions :) To learn about clojure, I am trying to do the thread ring problem of clgb in clojure. The rules of problem are here, and my attempt here. It seems that works well, but I can only test it with a small load (5 - 15 threads, 503 is the target) because it runs extremely slow. I tried to use atoms, hints, and change the implementation, but always is slower. What am I doing wrong? And, by the way, why can't I compile the class? Thanks a lot. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Is apply slow or am I incorrectly benchmarking this?
I'm thinking that integer boxing on the argument to your Fn is perhaps dominating your numbers. I'm not up to date on the compiler, but I'd think that the argument to the direct Math/ceil call is parsed in primitive form. On Wed, May 20, 2009 at 9:38 PM, CuppoJava patrickli_2...@hotmail.com wrote: Hi, I'm using apply a lot in my code, and a small micro-benchmark is telling me that it's a very slow operation. Can someone confirm this? I'm wondering whether my benchmark is incorrect, or whether there's a hidden reflection that I'm not seeing. Thanks a lot for the help -Patrick (let [i [1]] (time (dotimes [j 1000] (apply #(Math/ceil %) i Elapsed Time: 4123.448 msecs (let [i 1] (time (dotimes [j 1000] (Math/ceil i Elapsed Time: 555.107 msecs -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Concerns About Pushing Clojure 1.0.0 to Maven Central Repo?
On Thu, May 7, 2009 at 4:47 PM, J. McConnell jdo...@gmail.com wrote: I guess only Rich can make the choice: statu quo, clojure (breaks maven artifact id), clojure-lang (breaks build.xml). Not that I have a strong stake in this, but I'd vote for going with clojure and getting it right for 1.0. Right. It's easier to change this pom before it goes into the public repo than after. When people are going to change their pom from some odd snapshot to 1.0 anyway, then this is probably a good time to sneak this artifactId change in too, no? - J. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Is Clojure production ready?
On Wed, Apr 15, 2009 at 9:34 PM, Aaron Feng aaron.f...@gmail.com wrote: Also, if anyone has any thoughts on hiring Clojure people, it would be greatly appreciated. If I may guess out aloud: In this case, I reckon that pretty much any Java programmer who knows concurrency and has a clue about functional programming will be able to pick up Clojure to a sufficient degree to get started, after a week or two of focused learning and playing. And if you can find one or two guys who already know Clojure to mentor them, then the quality of the first-month code will presumably improve noticably. Thanks, Aaron -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: I feel I'm making an elementary mistake with proxy, but I don't know what...
On Thu, Apr 2, 2009 at 2:33 AM, Luke VanderHart luke.vanderh...@gmail.com wrote: Ugh, I hate it when I make a fool of myself and realize the answer to a question 1 minute after posting it, even when wrestling with it for an hour beforehand... The reason the example doesn't work is that the method is of a different arity than the one I'm attempting to call. Still doesn't explain why it's failing with the same error when I try to actually use it on a Swing object, but I'll try to isolate that condition separately... Sorry for the pointless post. http://en.wikipedia.org/wiki/Rubber_Duck_Debugging :) Thanks, -Luke On Apr 1, 8:29 pm, levand luke.vanderh...@gmail.com wrote: Isn't this supposed to work? (defn create-layout [] (proxy [java.awt.LayoutManager] [] (addLayoutComponent [name comp] (println Called addLayoutComponent)) (removeLayoutComponent [comp] (println Called removeLayoutComponent)) (preferredLayoutSize [container] (println Called preferredLayoutSize)) (minimumLayoutSize [container] (println Called minimumLayoutSize)) (layoutContainer [container] (println Called layoutContainer user (def layout (create-layout)) #'user/layout user (instance? java.awt.LayoutManager layout) true user (. layout preferredLayoutSize) ; Evaluation aborted. java.lang.IllegalArgumentException: No matching field found: preferredLayoutSize for class clojure.proxy.java.lang.Object$LayoutManager (NO_SOURCE_FILE:0) [Thrown class clojure.lang.Compiler$CompilerException] I get the same thing for all its methods, when I try to call them manually and also when I hook it up to a Swing container. I'd greatly appreciate it if anyone has any insight regarding what is going on... Thanks, -Luke -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Print a Large Lazy Seq - Heap Error
On Thu, Apr 2, 2009 at 11:58 AM, fitzpatrick...@googlemail.com fitzpatrick...@googlemail.com wrote: Hi, I am attempting to print a large lazy seq to file. I have attempted various approaches and obviously am missing something obvious. I have attempted do use do-seq and also iterated manually through the sequence but i always come up with the heap error. Has anyone got any suggestions? Don't hold on to the head of the seq. It may not be obvious where, but you are most likely holding on the the head of the seq, which prevents the elements from being GC'd as you iterate them. tks, PJ -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure Users Group - Denmark
On Mon, Mar 30, 2009 at 3:13 PM, Krukow karl.kru...@gmail.com wrote: Hello everyone, I am thinking about setting up a Danish Clojure Users' Group (dcug) based in Aarhus, but with the goal to be country-wide, possibly with city local groups (e.g., dcugAarhus, dcugCopenhagen). I am setting up a website with an associated blog for news/updates: http://www.clojure.dk (nothing real on there yet). I am wondering if there is enough Danish Clojure users to make this an active group. So please drop me an email or reply to this thread if you would be interested in actively participating. Otherwise it would be a European cug ;-) Great. Now we are at least 3 danes who know Clojure - I have a feeling that there is at least one other guy out there :) I live in Copenhagen, but i think we're a tad too few to form city local groups. Maybe if the scope was broadened to be more like lambda lounge? Cheers, /Karl -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure + Java compilation and IntelliJ IDEA plugin
Sounds great :) On Wed, Mar 25, 2009 at 4:42 PM, Ilya Sergey ilyas...@gmail.com wrote: Hello, all. I've just uploaded new version of La Clojure plugin for IntelliJ IDEA. Among several bugfixes and minor changes I have to note several essential moments. 1. Now Clojure support is added as so-called `facet', which may be attached to every module. Creating new module, just choose Clojure among desired technologies. In this case necessary clojure jar will be downloaded automatically and adjusted as a project library unless you point to it manually. 2. If you open existing project, clojure facet will be detected automatically. For now facet serves as a label for clojure-aware modules. In that modules you may invoke create new clojure file action and their clojure files will be compiled. 3. From now IntelliJ IDEA provides support for batch compilation of Clojure files, whose namespace is marked by :gen-calss tag. Compiled classes will be places to the appropriate output directory of a module. One may choose, which sources should be compiled first - Java or Clojure to resolve one-way dependencies. By default Clojure is compiled first. Could you explain the reasoning behind compiling the Clojure code before the Java code? While trying out Daniel Spiewaks Clojure enabled Buildr, which also compiles the Clojure code first, I noticed that I could not access static methods of the classes that were defined in Java code. I have not tested this, but I would assume that type hinting using these classes don't work either. On the other hand, Java works with Clojure through the classes and interfaces defined in clojure.jar, and resolves their Vars at run time. The 'gen-class case stands as an example where you might have to compile Clojure first, but I wonder if this is the typical case? Moreoverm you may to choose whether to copy *.clj files to output path or not (this might be useful if you're going to invoke some functions from *.clj files dynamically). And, of course, automatic detection and compilation of class-labeled clojure files may be switched off. For more details see File - Settings - Compiler - Clojure. For someone these settings might seem not sufficiently flexible. So, all comments and proposals are appreciated. :) With best regards, Ilya Sergey -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: STM and useful concurrency
is performance. If I found out that a particular transaction was commonly being retried many times, is that a sign that I need to write the code differently? How would I find out that was happening? I know I could insert my own code to track that, but it seems like this may be a commonly needed tool for Clojure to detect excessive conflicts/retries in transactions. Maybe we could set a special variable like *track-retries* that would cause Clojure to produce a text file that describes all the transaction retries that occurred in a particular run of an application. If such a tool isn't needed or wouldn't be useful, I'd like to understand why. -- R. Mark Volkmann Object Computing, Inc. -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: Preliminary Clojure Support in Buildr
On Thu, Feb 26, 2009 at 8:36 PM, Daniel Spiewak djspie...@gmail.com wrote: Note that you cannot mix Java and Clojure sources within the same project. It is supported in the latest changeset. The following configurations are possible: - Just Clojure: * src/main/clojure Clojure and Scala: * src/main/clojure * src/main/scala Clojure, Scala and Java: * src/main/clojure * src/main/scala * src/main/java Clojure and Groovy: * src/main/clojure * src/main/groovy Clojure, Groovy and Java: * src/main/clojure * src/main/groovy * src/main/java Clojure and Java: * src/main/clojure * src/main/java - You'll notice that Clojure, Scala and Groovy is not among the possibilities. This is because the Groovy joint compiler and the Scala joint compiler both expect to be able to interleave Java dependencies within their type resolution process. They do not have support for the same functionality with each other, meaning that circular dependencies cannot be compiled between the two languages. Who needs those other languages anyway ;) Note that this is all predicated on a (possibly faulty) assumption about the Clojure compiler: everything must be late-bound. If Clojure's compiler needs to resolve types at compile-time, then this could potentially fail in unexpected ways. Specifically, circular dependencies between Clojure and Java/Scala/Groovy would not be possible. In such a case, you would need to somehow factor the circularity out into a separate .clj file and then exclude that file from compilation (forcing late binding). I honestly don't know if this is the compiler's behavior or not, but I thought it was worth the warning. To bump this one up again I only got around to playing with this again recently, and it seems that I can't access ie. static methods on my Java types. If I understand correctly, the Clojure code is compiled before the Java code. I don't think that makes much sense, since Java would call into Clojure through Vars which are always resolved at runtime, whereas Clojure would like to know about concrete types when calling into Java so it can avoid expensive reflection. One small change: in order to use this functionality now, you will need to include the following line at the top of your buildfile: require 'buildr/clojure' Joint compilation with Scala/Java or Groovy/Java does not necessitate an extra require, but this first one is necessary to get the process started and ensure that Clojure's compiler becomes the dominant selection. Daniel -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: User contributed packages (Cabel, CPAN, etc)
I was hoping that we could piggy-back on one of Java's packaging systems, so our programs can depend on Java libraries just as easy as Clojure libraries. And in this regard, the Maven repository system is pretty popular and even supported by build tools other than Maven (such as Ivy, Buildr and Gradle). On Sun, Mar 22, 2009 at 5:57 PM, Bradbev brad.beveri...@gmail.com wrote: Is the clojure-contrib portion of Clojure meant to act as a package system like Cabel, CPAN, etc? I suspect not. Clojure-contrib is more like the standard library that comes with Clojure. I think that going forward, Clojure is going to want to have a large and easily accessible library of packages. I would love to see a strong package system for Clojure that 1) Made it very easy to search for packages download them, along with all the packages they depend upon 2) Made the bar for contributing packages as low as possible so people can contribute easily (Ideally, after you have configured the package manager, uploading a new package should be as easy as 'packman upload mypackage') I feel that the next big growth phase for Clojure will be in the user community and the code that we can generate. A good package manager will help fuel that growth. And now I'll cop out say that I have no idea about how to actually implement this sort of thing - I'm hoping somebody else will want to do it for me :) Thanks, Brad -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: filter1 interesting?
On Mon, Mar 16, 2009 at 8:38 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Mar 16, 8:14 am, Rich Hickey richhic...@gmail.com wrote: Sorry to jump in late, but one problem with seek is that it is a homophone of seq. Did anyone consider ffilter or find-first? I thought find-first was too long, since it's almost as long as (first (filter ...) ffilter looks funny, especially in a proportional font. Others I considered: find1, filter1, select1, pick, detect, spot, hit, ... While considering suffixed names, what about firstp as inspired by condp? I personally like how the first part makes it clear that we are returning a single thing, rather than a collection or seq, and that it is the one closest to the head - the one we are going to, well, find first. That said, as you might imagine, I rather like find-first myself. I don't think it is too much to type. I may be biased here, considering my non-american keyboard layout, but saving a parenthesis for filter is more of a win than a few alphabetic characters. To conclude, I would prefer find-first as I believe the clarity is worth the extra characters. pick might be good. -Stuart Sierra -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Performance tips for Clojure
On Fri, Mar 13, 2009 at 7:49 AM, Chouser chou...@gmail.com wrote: On Fri, Mar 13, 2009 at 2:18 AM, Sergio bigmonac...@gmail.com wrote: There are a couple of obvious ones, but also some others that I haven't seen documented (like, map is much faster on lists than on vectors since rest is O(1) for lists). You're right that 'rest' is O(1) for lists, but it's O(1) for vectors as well. Your blog post include this table: rest - O(1) for lists. O(n) for vectors. count - O(1) for lists and vectors I think that count is O(n) for lists, no? nth - O(n) for lists. O(1) for vectors. cons - O(1) for lists, O(n) for vectors This has a couple errors. Both 'rest' and 'cons' are O(1) on vectors. I'm not sure what in the source code led you to believe otherwise. Both 'rest' and 'cons' create a seq from the vector, but this is an O(1) operation. You can also run some timing experiments and see that 'map' is at least as fast on vectors as on lists. (defn timemap [c] (time (dotimes [i 100] (last (map identity c) (timemap (into [] (range 1))) == Elapsed time: 158.464048 msecs (timemap (into [] (range 10))) == Elapsed time: 1690.745615 msecs Note that multiplying the length of the vector by 10 increased the time by roughly 10 -- this suggests an O(n) operation, as we would expect. (timemap (into () (range 1))) == Elapsed time: 185.460957 msecs (timemap (into () (range 10))) == Elapsed time: 1821.346964 msecs Again we see evidence of 'map' being O(n), but when walking across a list it appears to run slightly *slower* than across a vector, though probably not by enough to be significant. We can even time 'rest' itself: (defn timerest [c] (time (dotimes [i 100] (rest c (timerest (into [] (range 1))) == Elapsed time: 125.826519 msecs If 'rest' were O(n) on vectors, we should be able to multiply the length of the vector by 100 and see the time go up by roughly 100x: (timerest (into [] (range 100))) == Elapsed time: 147.096976 msecs The amount of time it takes to build the vector goes up significantly, but the timed part, calling 'rest' a million times, doesn't take anywhere near 100 times longer. --Chouser -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: filter1 interesting?
On Wed, Mar 11, 2009 at 9:01 AM, Vagif Verdi vagif.ve...@gmail.com wrote: Is (first (filter ..) lazy like in haskell ? Yes. I would hate to wait for filter to get all results just to throw them out and pick the first one. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Question about instance?
On Mon, Mar 9, 2009 at 11:10 PM, Laurent PETIT laurent.pe...@gmail.com wrote: Hello, I have the use case for calling instance? where, once instance? returns true, I want to do something with the successful instance, such as binding it, or directly calling something on it. For instance, I have in my code : (let [console (.getConsole v)] (when (instance? org.eclipse.debug.ui.console.IConsole console) ... ...) Where I would like to really use when-let : (when-let [console (instance? org.eclipse.debug.ui.console.IConsole (.getConsole v))] ... ...) For this to work, instance? would have to return logical true instead of real true. Do you think it could be an interesting idea to change instance? in such a way ? Or maybe there's already something similar in clojure-contrib I haven't seen ? What about this case: (when-let [x (instance? java.lang.Boolean false)] (println x)) I think that should print 'true', and therefor I am against this proposal. Thanks in advance, -- Laurent -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: What is Clojure NOT good for?
On Tue, Mar 10, 2009 at 12:17 AM, bOR_ boris.sch...@gmail.com wrote: I'm not from the software engineers field, but how difficult is it for some non-lisp, but java-savvy software writer to pick up a 600-line clojure program and learn to understand it? I think the majority of Java programmers will be able to pull that off, but it will take a good deal longer than the equivalent 2000-line Java program. Also, how do you think this increase in required effort grows? What if we are talking about a +10.000-line Clojure program? Now add schedule pressure, deadlines and the cost of missed oppotunities and you will find that many companies sees the introduction of a new programming language - especially if it is uncontrolled or happens without their knowledge - as a significant risk. I mean, everyone in this forum managed to learn clojure to some degree without too much trouble.. including me. If there is a function the poor software engineer doesn't know about, there is excellent documentation available (unlike, for example for K, where your documentation is the source code in Q), there's this google group, and there is irc. I am a scientist, and I seem to manage fine. Someone who programs for a living should be able to fix a program that is broken in whatever language relatively easy. Relative as in opposed to someone who does not program at all? ;) You may find it hard to pursuade an off-the-street VB hacker to fix bugs in your K code :) On Mar 9, 6:08 pm, Jay Fields j...@jayfields.com wrote: I've lived through this discussion for the past 3 years while writing web applications using Ruby and Rails. Here's what I've learned: - Using a language that the average stupid programmer can't understand virtually guarantees that you'll increase your success chances, since you and your team-mates will be of a higher caliber. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Question about instance?
On Tue, Mar 10, 2009 at 9:40 AM, Timothy Pratley timothyprat...@gmail.com wrote: How about a cast variant that doesn't throw an exception but returns nil? user= (cast java.lang.Boolean false) false user= (cast java.lang.Integer false) java.lang.ClassCastException (NO_SOURCE_FILE:0) user= (defn instance [c i] (try (cast c i) (catch Exception e))) #'user/instance user= (instance java.lang.Boolean false) false user= (instance java.lang.Integer false) nil That's a better idea. You might want to consider calling it 'coerce' instead of 'instance' - I think that name is clearer and fits the intent better. Regards, Tim. On Mar 10, 7:15 pm, Christian Vest Hansen karmazi...@gmail.com wrote: On Mon, Mar 9, 2009 at 11:10 PM, Laurent PETIT laurent.pe...@gmail.com wrote: Hello, I have the use case for calling instance? where, once instance? returns true, I want to do something with the successful instance, such as binding it, or directly calling something on it. For instance, I have in my code : (let [console (.getConsole v)] (when (instance? org.eclipse.debug.ui.console.IConsole console) ... ...) Where I would like to really use when-let : (when-let [console (instance? org.eclipse.debug.ui.console.IConsole (.getConsole v))] ... ...) For this to work, instance? would have to return logical true instead of real true. Do you think it could be an interesting idea to change instance? in such a way ? Or maybe there's already something similar in clojure-contrib I haven't seen ? What about this case: (when-let [x (instance? java.lang.Boolean false)] (println x)) I think that should print 'true', and therefor I am against this proposal. Thanks in advance, -- Laurent -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Mathy operations on non-numerics (was Adding strings)
On Fri, Feb 27, 2009 at 12:47 AM, Allen Rohner aroh...@gmail.com wrote: I agree regarding concatenation as well, but I think the case for comparison of non-numerics is still pretty strong. -Phil Are you referring to using , , =, with objects that implement java.lang.Comparable? i.e. given x.compareTo(y) == -1 ( x y) = true I would find that useful. I think having , , =, = be based on Comparable has been discussed before. And the conclusion was that it was a bad idea, because in Java: user= (.compareTo (Integer. 10) (Long. 10)) java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer (NO_SOURCE_FILE:0) And: user= (.equals (Integer. 10) (Long. 10)) false Whereas in Clojure: user= ( (Integer. 10) (Long. 10)) false user= (= (Integer. 10) (Long. 10)) true Given these consequences, I think the current behavior is the best compromise. Allen -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: Preliminary Clojure Support in Buildr
Nice initiative! However, it the net-ssh dependency has problems: [cvh: ~]$ sudo gem install djspiewak-buildr ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) timed out (http://gems.rubyforge.org/gems/net-ssh-2.0.4.gem) On Sat, Feb 21, 2009 at 10:33 PM, Daniel Spiewak djspie...@gmail.com wrote: I'm pleased to announce preliminary (and very experimental) support for the Clojure AOT compiler and REPL within Apache Buildr (http:// buildr.apache.org). At present, this support is only available within my Git fork available here: git://github.com/djspiewak/buildr.git More specifically, Clojure support is available within the clojure and master branches (master branch alone contains REPL support). It should be possible to install this particular version of Buildr by using the following commands, though I'm honestly not sure how up to date GitHub's gem repository is: gem sources -a http://gems.github.com sudo gem install djspiewak-buildr Once installed, Clojure support is activated in a project simply by storing your .clj scripts within the src/main/clojure directory. Note that the (ns) directive will need to match the subdirectory, otherwise compilation will fail. By default, every script is compiled to the target/classes directory. Namespaces are auto-detected from the directory structure. Only updated files are re-compiled (based on mtime of .clj file and its corresponding *__init.class). If you wish to override the auto-detection and specify a reduced set of namespaces, it can be done using the `compile.using` directive within your project definition in your buildfile. Thusly: define 'clojure-contrib' do compile.using :libs = ['clojure.contrib.command-line', 'clojure.contrib.mmap'] end Any scripts which are *not* pre-compiled will be copied verbatim to the target/classes directory w.r.t. their position in the directory structure. Note that you will need to have set CLOJURE_HOME for this to work. You will have to be using the master branch from my git repository in order to use the Clojure REPL through Buildr (or install via the gem command given above). To invoke, simply run the following command somewhere in your project hierarchy: buildr shell This will launch the Clojure REPL pointing at your project's dependencies and the updated target/classes directory (compilation is re-run if necessary). Additionally, if you have a valid license for JavaRebel, you can make use of it with the REPL by setting the REBEL_HOME environment variable. Note that you cannot mix Java and Clojure sources within the same project. Aww... :( However, this is fairly easy to overcome by splitting the languages into separate sub-projects. Thus, your top-level project might contain all of your Clojure sources, while the sub-project might contain Java. There are more details regarding this process on the Buildr project page. One thing to keep in mind is that Buildr was designed to serve as a build system for more static languages (specifically: Java, Scala, Groovy). Thus, it is pre-biased toward things like a separate compilation phase (the REPL points to target/classes rather than src/ main/clojure). Fair warning: this language support is *extremely* experimental and probably not too reliable at this point. Also note that while it is possible that Clojure support will be merged into the Buildr trunk in future, it has not yet been decided one way or another (see https://issues.apache.org/jira/browse/BUILDR-259). Use at your own risk! -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: ANN: Preliminary Clojure Support in Buildr
On Thu, Feb 26, 2009 at 6:17 PM, Daniel Spiewak djspie...@gmail.com wrote: Odd. Must be a problem with RubyForge. If you try again, does it work? I tried again at home and got quite a bit further. Maybe it was just a hiccup at rubyforge. However, I still see some questionable things in the output, and I have yet to actually try it out (this is the first time I'm trying out buildr). Here in verbatim: rowe:~$ sudo gem install djspiewak-buildr Building native extensions. This could take a while... Successfully installed builder-2.1.2 Successfully installed net-ssh-2.0.4 Successfully installed net-sftp-2.0.1 Successfully installed rubyzip-0.9.1 Successfully installed highline-1.5.0 Successfully installed rubyforge-1.0.1 Successfully installed hoe-1.7.0 Successfully installed rjb-1.1.6 Successfully installed Antwrap-0.7.0 Successfully installed rspec-1.1.4 Successfully installed xml-simple-1.0.11 Successfully installed archive-tar-minitar-0.5.2 Successfully installed djspiewak-buildr-1.3.4 13 gems installed Installing ri documentation for builder-2.1.2... ERROR: While generating documentation for builder-2.1.2 ... MESSAGE: Unhandled special: Special: type=17, text=!-- HI -- ... RDOC args: --ri --op /opt/local/lib/ruby/gems/1.8/doc/builder-2.1.2/ri --title Builder -- Easy XML Building --main README --line-numbers --quiet lib CHANGES Rakefile README doc/releases/builder-1.2.4.rdoc doc/releases/builder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc (continuing with the rest of the installation) Installing ri documentation for net-ssh-2.0.4... Installing ri documentation for net-sftp-2.0.1... Installing ri documentation for highline-1.5.0... Installing ri documentation for rubyforge-1.0.1... Installing ri documentation for hoe-1.7.0... Installing ri documentation for Antwrap-0.7.0... Installing ri documentation for rspec-1.1.4... Installing ri documentation for archive-tar-minitar-0.5.2... Installing ri documentation for djspiewak-buildr-1.3.4... File not found: lib rowe:~$ ruby --version ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin8] rowe:~$ A failure to generate the docs I can live with, but that File not found line looks pretty suspect. Daniel On Feb 26, 10:58 am, Christian Vest Hansen karmazi...@gmail.com wrote: Nice initiative! However, it the net-ssh dependency has problems: [cvh: ~]$ sudo gem install djspiewak-buildr ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) timed out (http://gems.rubyforge.org/gems/net-ssh-2.0.4.gem) On Sat, Feb 21, 2009 at 10:33 PM, Daniel Spiewak djspie...@gmail.com wrote: I'm pleased to announce preliminary (and very experimental) support for the Clojure AOT compiler and REPL within Apache Buildr (http:// buildr.apache.org). At present, this support is only available within my Git fork available here: git://github.com/djspiewak/buildr.git More specifically, Clojure support is available within the clojure and master branches (master branch alone contains REPL support). It should be possible to install this particular version of Buildr by using the following commands, though I'm honestly not sure how up to date GitHub's gem repository is: gem sources -ahttp://gems.github.com sudo gem install djspiewak-buildr Once installed, Clojure support is activated in a project simply by storing your .clj scripts within the src/main/clojure directory. Note that the (ns) directive will need to match the subdirectory, otherwise compilation will fail. By default, every script is compiled to the target/classes directory. Namespaces are auto-detected from the directory structure. Only updated files are re-compiled (based on mtime of .clj file and its corresponding *__init.class). If you wish to override the auto-detection and specify a reduced set of namespaces, it can be done using the `compile.using` directive within your project definition in your buildfile. Thusly: define 'clojure-contrib' do compile.using :libs = ['clojure.contrib.command-line', 'clojure.contrib.mmap'] end Any scripts which are *not* pre-compiled will be copied verbatim to the target/classes directory w.r.t. their position in the directory structure. Note that you will need to have set CLOJURE_HOME for this to work. You will have to be using the master branch from my git repository in order to use the Clojure REPL through Buildr (or install via the gem command given above). To invoke, simply run the following command somewhere in your project hierarchy: buildr shell This will launch the Clojure REPL pointing at your project's dependencies and the updated target/classes directory (compilation is re-run if necessary). Additionally, if you have a valid license for JavaRebel, you can make use of it with the REPL by setting the REBEL_HOME environment variable. Note that you cannot mix Java and Clojure sources within the same project. Aww... :( However, this is fairly
Re: ANN: Preliminary Clojure Support in Buildr
rowe:~$ buildr --version /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- buildr (LoadError) from /opt/local/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require' from /opt/local/lib/ruby/gems/1.8/gems/djspiewak-buildr-1.3.4/bin/buildr:18 from /opt/local/bin/buildr:19:in `load' from /opt/local/bin/buildr:19 rowe:~$ gem --version 1.3.1 rowe:~$ On Thu, Feb 26, 2009 at 10:30 PM, Daniel Spiewak djspie...@gmail.com wrote: I'm not sure what the File not found thing is all about, but you should still be ok (crazy gems). Try the following: buildr --version Daniel On Feb 26, 3:16 pm, Christian Vest Hansen karmazi...@gmail.com wrote: On Thu, Feb 26, 2009 at 6:17 PM, Daniel Spiewak djspie...@gmail.com wrote: Odd. Must be a problem with RubyForge. If you try again, does it work? I tried again at home and got quite a bit further. Maybe it was just a hiccup at rubyforge. However, I still see some questionable things in the output, and I have yet to actually try it out (this is the first time I'm trying out buildr). Here in verbatim: rowe:~$ sudo gem install djspiewak-buildr Building native extensions. This could take a while... Successfully installed builder-2.1.2 Successfully installed net-ssh-2.0.4 Successfully installed net-sftp-2.0.1 Successfully installed rubyzip-0.9.1 Successfully installed highline-1.5.0 Successfully installed rubyforge-1.0.1 Successfully installed hoe-1.7.0 Successfully installed rjb-1.1.6 Successfully installed Antwrap-0.7.0 Successfully installed rspec-1.1.4 Successfully installed xml-simple-1.0.11 Successfully installed archive-tar-minitar-0.5.2 Successfully installed djspiewak-buildr-1.3.4 13 gems installed Installing ri documentation for builder-2.1.2... ERROR: While generating documentation for builder-2.1.2 ... MESSAGE: Unhandled special: Special: type=17, text=!-- HI -- ... RDOC args: --ri --op /opt/local/lib/ruby/gems/1.8/doc/builder-2.1.2/ri --title Builder -- Easy XML Building --main README --line-numbers --quiet lib CHANGES Rakefile README doc/releases/builder-1.2.4.rdoc doc/releases/builder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc (continuing with the rest of the installation) Installing ri documentation for net-ssh-2.0.4... Installing ri documentation for net-sftp-2.0.1... Installing ri documentation for highline-1.5.0... Installing ri documentation for rubyforge-1.0.1... Installing ri documentation for hoe-1.7.0... Installing ri documentation for Antwrap-0.7.0... Installing ri documentation for rspec-1.1.4... Installing ri documentation for archive-tar-minitar-0.5.2... Installing ri documentation for djspiewak-buildr-1.3.4... File not found: lib rowe:~$ ruby --version ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin8] rowe:~$ A failure to generate the docs I can live with, but that File not found line looks pretty suspect. Daniel On Feb 26, 10:58 am, Christian Vest Hansen karmazi...@gmail.com wrote: Nice initiative! However, it the net-ssh dependency has problems: [cvh: ~]$ sudo gem install djspiewak-buildr ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) timed out (http://gems.rubyforge.org/gems/net-ssh-2.0.4.gem) On Sat, Feb 21, 2009 at 10:33 PM, Daniel Spiewak djspie...@gmail.com wrote: I'm pleased to announce preliminary (and very experimental) support for the Clojure AOT compiler and REPL within Apache Buildr (http:// buildr.apache.org). At present, this support is only available within my Git fork available here: git://github.com/djspiewak/buildr.git More specifically, Clojure support is available within the clojure and master branches (master branch alone contains REPL support). It should be possible to install this particular version of Buildr by using the following commands, though I'm honestly not sure how up to date GitHub's gem repository is: gem sources -ahttp://gems.github.com sudo gem install djspiewak-buildr Once installed, Clojure support is activated in a project simply by storing your .clj scripts within the src/main/clojure directory. Note that the (ns) directive will need to match the subdirectory, otherwise compilation will fail. By default, every script is compiled to the target/classes directory. Namespaces are auto-detected from the directory structure. Only updated files are re-compiled (based on mtime of .clj file and its corresponding *__init.class). If you wish to override the auto-detection and specify a reduced set of namespaces, it can be done using the `compile.using` directive within your project definition in your buildfile. Thusly: define 'clojure-contrib' do compile.using :libs = ['clojure.contrib.command-line', 'clojure.contrib.mmap'] end Any scripts which are *not* pre-compiled will be copied verbatim
Re: alternate syntax
On Mon, Feb 23, 2009 at 4:42 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I have an idea I'd like to float to see if there are reasons why it's a bad idea. What if Clojure had an alternate surface syntax that was translated into standard Clojure syntax by a kind of preprocessor? Do you by any chance mean custom reader when you say preprocessor? :) Many people that don't like Lisp dialects don't like them because of the parentheses. I'm trying to address that. How many of those have spend enough time with a lisp to form a valid opinion of the syntax? There are many programming languages who's syntax looks ugly to the eye that do not understand its meaning. Here's a simple example of valid Clojure code. (defn pig-latin [word] (let [first-letter (first word)] (if (.contains aeiou (str first-letter)) (str word ay) (str (subs word 1) first-letter ay (println (pig-latin red)) (println (pig-latin orange)) Here's what that same code would look like in my alternate syntax. defn pig-latin [word] let [first-letter (first word)] if .contains aeiou (str first-letter) str word ay str (subs word 1) first-letter ay println (pig-latin red) println (pig-latin orange) The rules for turning this into standard Clojure syntax are pretty simple. 1) If a line is indented farther than the previous one, it is part of the previous line. 2) If a line doesn't start with a (, then add one. 3) If the next line is indented less than this one, add the appropriate number of )'s at the end. 4) If the first token on a line is if and the first non-whitespace character after it is not ( then assume the rest of the line is the condition and wrap it in ( ). Rule 4 is a special case that introduces inconsistency. I am against it. The syntax is basically introducing implicit parenthesis based on indentation. I have been pondering this idea as well, but decided that Clojure already goes so easy on the parenthesis, that it wasn't worth my time to persue it any further. A translation from standard Clojure syntax to this alternate form should also be possible. Is this a bad idea? It is not inherently bad, but I doubt that a lot of people would prefer it as their primary reader over the standard Clojure reader. It could, on the other hand, find a nice niche in DSLs, for programs that need some level of scriptability by people who cannot be expected to be lisp savvy. -- R. Mark Volkmann Object Computing, Inc. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure Questions
I *think* that Clojure does not require anything from Java 6, and thus can work on any compliant Java 5 or greater. On Sat, Feb 21, 2009 at 3:13 PM, Sean francoisdev...@gmail.com wrote: Hi everyone, I'm working on cleaning up the wikibook some, and I've got a few questions. If anyone could answer, that would be a great help. What is the minimum required JVM version for clojure? What versions of Java have been tested? What versions of Java are supported? Thanks! -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: do-form swallows exception?
First, map returns a lazy seq. Second, do only returns the result of the last expression. So, the mapping you do in your do form is never executed because you never ask for the result. Try wrapping the mapping in dorun to explicitly realize the lazy seq from your mapping: (defn foo [] (do (dorun (map (fn [_] (throw (RuntimeException. fail))) [1 2])) no exception)) On Tue, Feb 17, 2009 at 5:11 PM, linh nguyenlinh.m...@gmail.com wrote: Hi, How come the following code does not throw an exception? (defn foo [] (do (map (fn [_] (throw (RuntimeException. fail))) [1 2]) no exception)) this however does throw exception: (defn foo [] (map (fn [_] (throw (RuntimeException. fail))) [1 2])) Is this a bug or am I missing something? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: map literals, computed keys and side-effects
That's odd. Might you have uncovered a bug regarding: user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) clojure.lang.PersistentHashMap user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}) clojure.lang.PersistentArrayMap While with the atom code we have: user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})) clojure.lang.PersistentArrayMap user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8})) clojure.lang.PersistentArrayMap On Tue, Feb 17, 2009 at 8:03 PM, Christophe Grand christo...@cgrand.net wrote: While kicking the tires, I encountered this behavior: user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) {3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9, 1 2} user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8}) {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8} Granted, it's not casual Clojure code but it's surprising. Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: map literals, computed keys and side-effects
I think I got it :) The two (swap! a inc) forms are added to the map at read-time - which is before they are evaluated. However, since we are associating the (swap! a inc) key with a value twice, only the last one counts. So the atom is inc'ed to 1 once (because keys can only be in the map once), and assoc'ed with the value 2 (because that's the second assoc we're doing to the (swap! a inc) form). The PersistantArrayMap, on the other hand, is more gullible and trusting towards the parsed array of forms that the reader presents it, and therefor accepts the (swap! a inc) key twice, which in turn causes it to evaluate twice; into two different keys with two different associations. On Tue, Feb 17, 2009 at 8:28 PM, Christian Vest Hansen karmazi...@gmail.com wrote: That's odd. Might you have uncovered a bug regarding: user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) clojure.lang.PersistentHashMap user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}) clojure.lang.PersistentArrayMap While with the atom code we have: user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})) clojure.lang.PersistentArrayMap user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8})) clojure.lang.PersistentArrayMap On Tue, Feb 17, 2009 at 8:03 PM, Christophe Grand christo...@cgrand.net wrote: While kicking the tires, I encountered this behavior: user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) {3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9, 1 2} user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8}) {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8} Granted, it's not casual Clojure code but it's surprising. Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: map literals, computed keys and side-effects
Just to clarify; I think PersistentArrayMap is too naïve: user= {1 1 1 1 1 1 2 2} {1 1, 1 1, 1 1, 2 2} Also, this is rev 1286 (just prior to lazy-branch merge thingy). On Tue, Feb 17, 2009 at 8:50 PM, Christian Vest Hansen karmazi...@gmail.com wrote: I think I got it :) The two (swap! a inc) forms are added to the map at read-time - which is before they are evaluated. However, since we are associating the (swap! a inc) key with a value twice, only the last one counts. So the atom is inc'ed to 1 once (because keys can only be in the map once), and assoc'ed with the value 2 (because that's the second assoc we're doing to the (swap! a inc) form). The PersistantArrayMap, on the other hand, is more gullible and trusting towards the parsed array of forms that the reader presents it, and therefor accepts the (swap! a inc) key twice, which in turn causes it to evaluate twice; into two different keys with two different associations. On Tue, Feb 17, 2009 at 8:28 PM, Christian Vest Hansen karmazi...@gmail.com wrote: That's odd. Might you have uncovered a bug regarding: user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) clojure.lang.PersistentHashMap user= (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8}) clojure.lang.PersistentArrayMap While with the atom code we have: user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})) clojure.lang.PersistentArrayMap user= (class (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8})) clojure.lang.PersistentArrayMap On Tue, Feb 17, 2009 at 8:03 PM, Christophe Grand christo...@cgrand.net wrote: While kicking the tires, I encountered this behavior: user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9}) {3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9, 1 2} user= (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 3 3 4 4 5 5 6 6 7 7 8 8}) {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8} Granted, it's not casual Clojure code but it's surprising. Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: map literals, computed keys and side-effects
On Tue, Feb 17, 2009 at 9:08 PM, Christophe Grand christo...@cgrand.net wrote: Fixing array-map would make the two tests consistent but I'm not sure that (let [a (atom 0)] {(swap! a inc) 1 (swap! a inc) 2 }) should evaluate to {1 2}. That would make it two distinct issues, as I see it. One for array-map, and one for whether association happens before or after the keys have been evaluated. It would seem really strange to me if the following behavior is correct: user= (def m (array-map 1 1 1 2 1 3)) #'user/m user= (m 1) 1 user= (m 2) nil user= m {1 1, 1 2, 1 3} So I went ahead and opened an issue for that: http://code.google.com/p/clojure/issues/detail?id=83 I agree it would be nice if the keys were evaluated before the map was created - python certainly does it that way, though it isn't a lisp. Clojure is the only lisp I'm familiar with, so I can't say what's normal here. Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: map literals, computed keys and side-effects
On Tue, Feb 17, 2009 at 10:07 PM, Rich Hickey richhic...@gmail.com wrote: On Feb 17, 3:30 pm, Christian Vest Hansen karmazi...@gmail.com Please don't create issues without getting a nod from me here first. Ok. I won't. I must have overlooked the Similarly, please confirm a bug before making an entry. part. These are bugs in user code. Map literals are in fact read as maps, so a literal map with duplicate keys isn't going to produce an evaluated map with distinct keys. If you create an array map with duplicate keys, bad things will happen. I'm not sure I want to slow down array-map in order to add the check. My opinion is unchanged, even though I always end up being in the wrong when we argue. Rich -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Anonymous recursive functions
There's a couple of Fibonacci's on the wiki that uses this approach: http://en.wikibooks.org/wiki/Clojure_Programming/Examples#Lazy_Fibonacci On Mon, Feb 16, 2009 at 6:50 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: I just discovered a nice feature that I don't remember having seen discussed or documented before: there is a way to write recursive functions without having them associated to any var/symbol in any namespace. The optional name of a function can be used for a recursive call. Example: ((fn fac [n] (if (zero? n) 1 (* n (fac (dec n) 5) I know this is not the best way to write a factorial (it is not tail- recursive), the point is just to show an example of a recursive call. Konrad. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: run clojure on 5,832 cores?
On Sat, Feb 14, 2009 at 1:31 AM, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Feb 13, 6:13 pm, Christian Vest Hansen karmazi...@gmail.com wrote: I see no mention of a JVM being available for those CPUs, but perhaps the no-asm HotSpot can be build with gcc on it. Looks like they run Linux, so it would probably be possible. This article http://www.networkworld.com/news/2009/020509-sicortex.html says they use slower, cheaper processors that work best when you're doing lots of small computations in parallel. The part I get excited about is the 8 TB of memory. When can I get THAT on my desk? You run into problems with the garbage collector when the heap gets big: the bigger the heap, the longer it takes to compact. Azul has hardware support for their garbage collector which allows their compaction phase to run concurrently with the application, otherwise there'd be no way they could make use of the 768 GB ram their kit can scale to, unless striped across hundreds of JVMs. If you try to scale a normal collector to those heap sizes, you will see your stop-the-world collections jump from sub-second to minutes or even hours. -Stuart Sierra -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: run clojure on 5,832 cores?
I see no mention of a JVM being available for those CPUs, but perhaps the no-asm HotSpot can be build with gcc on it. Otherwise, cool gear :) On Fri, Feb 13, 2009 at 11:47 PM, Raoul Duke rao...@gmail.com wrote: http://sicortex.com/products -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Type hint Java array of your own Java class
On Thu, Feb 5, 2009 at 7:33 AM, Christophe Grand christo...@cgrand.net wrote: Chouser a écrit : (defn foobar [#^#=(array-of MyClass) myarray]) Again, I apologize for even suggesting this Wow what a clever (ab)use of reader macros! This is where a raptor jumps in from the left and eats someone :) -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Queues
I don't know which of these two options are best in general, but I wonder; are persistance and immutability valuable properties of queues? Safe and cheap snap-shotting might be a nice feature of a queue but I (generally) wouldn't want it at the cost of more expensive put and take operations. Java already have concurrent, albeit mutable, queue implementations in the java.util.concurrent package. Since most operations you'd want to execute on a queue are writes, I can't help but think that a mutable datastructure is better suited, and that an attempt with immutable structures would most likely end up simulating mutability with some form of copy-on-write + CAS scheme anyway. Then again, safe snapshots might really be important, and that's where I'd use PersistentQueue as Christophe Grand mentioned. On Tue, Feb 3, 2009 at 2:35 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: Is there any reason to prefer lists over vectors or vice versa for implementing queues? It seems that for both lists and vectors, adding and removing at one end (front for lists, end for vectors) is cheap, whereas it is expensive at the other end. For queues you need to add at one end and remove from the other, so one of the two operations is necessarily expensive. But is there a difference between the two? Konrad. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure speed
2009/2/3 Gregory Petrosyan gregory.petros...@gmail.com: Here http://leonardo-m.livejournal.com/75825.html you can find similar microbenchmark. Java is more than 3х slower than Python's built-in integers, and more than 10x slower than GMPY ones. Seems like Java's BigIntegers have some problems with performance, hm? BigInteger have problems, but so does that benchmark: No warm-up. Includes startup time. Using client VM. And probably a number of less obvious things that commonly haunt Java micro-benchmarks. On the other hand, we have reason to hope that the big-math story will improve significantly in JDK 7: http://markmail.org/message/7conncsespvrlazn -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Memory Consumption of Large Sequences
The trick with these listish things is to not calculate the tail until you need it, and to throw away the head when you're done with it. On Mon, Feb 2, 2009 at 7:06 PM, Keith Bennett keithrbenn...@gmail.com wrote: All - I'm curious to know how to minimize memory consumption in Clojure for large lists. I did the following test in repl: (def d ()) (dotimes [_ 10] (def d (cons x d))) Here, you are keeping the head of the list in the d and do nothing but append to the d list and redefine d as the new, longer list. Instead, try defining d like this: (def d (take 10 (repeat x))) And take a gander at how much memory that consumes. However, the ideal thing here is to not define d as a list at all. Make instead a function that produces the value of d on demand - you don't actually need d, you need it's value. All d does is to reference the head of your list and thereby preventing it from being garbage collected. Then, I used VisualVM, an awesome free profiling tool (https:// visualvm.dev.java.net/) to examine the results. It indicated that the number of clojure.lang.PersistentList instances increased by 100,000. Each instance appeared to consume 48 bytes (not including the actual value, but only its reference, I presume). I don't think any were eligible for garbage collection, because I initiated gc several times, and they were not removed. (I know that gc() is not deterministic, but am pretty sure that they would have been removed. Feel free to correct me.) Thinking that maybe the special functions like map did some magic to save memory, I tried this: (def a (map #(* 2 %) (range 10))) The result was 100,000 clojure.lang.LazyCons objects, each of which consuming 52 bytes. But not until the list was realized. However, your a reference will prevent this list from being garbage collected as well. Are there alternate strategies for building a large sequence that would consume less memory per element? Don't keep the head around on any list (well, seq really) unless you really mean/need it. Thanks, Keith -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: what does - mean?
On Mon, Feb 2, 2009 at 1:34 PM, wubbie sunj...@gmail.com wrote: any concrete example? http://github.com/karmazilla/textjure/blob/cf4ac457358e02f1d1d46d14a2885da0544dbd46/textjure.clj#L342 thanks, -sun On Feb 2, 5:13 am, Christian Vest Hansen karmazi...@gmail.com wrote: On Sun, Feb 1, 2009 at 9:35 PM, e evier...@gmail.com wrote: This may be obvious to others, but what's the motivation behind it? Is it that we are very concerned about combatting the criticism that lisp has too many parens? The - macro is simply an excellent tool for drilling into nested structures and/or piping some value through a list of methods and functions. It works very well indeed when mixed with doto - especially if you have to work with Swing or other component'ish frameworks. On Sun, Feb 1, 2009 at 3:09 PM, kkw kevin.k@gmail.com wrote: Hi sun, I thought this question looked familiar. I found some answers here also: http://groups.google.com/group/clojure/browse_thread/thread/1f21663ea... Kev On Feb 2, 2:29 am, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: Sorry! That should have read; (- m :one :b) 2 On Sun, Feb 1, 2009 at 5:13 PM, e evier...@gmail.com wrote: I was able to work through the first two examples, and thanks for those. I will have to study maps more, I guess, to understand the last one. I don't know where 'x' came from: user= (- x :one :b) 2- Hide quoted text - - Show quoted text - -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: what does - mean?
On Sun, Feb 1, 2009 at 9:35 PM, e evier...@gmail.com wrote: This may be obvious to others, but what's the motivation behind it? Is it that we are very concerned about combatting the criticism that lisp has too many parens? The - macro is simply an excellent tool for drilling into nested structures and/or piping some value through a list of methods and functions. It works very well indeed when mixed with doto - especially if you have to work with Swing or other component'ish frameworks. On Sun, Feb 1, 2009 at 3:09 PM, kkw kevin.k@gmail.com wrote: Hi sun, I thought this question looked familiar. I found some answers here also: http://groups.google.com/group/clojure/browse_thread/thread/1f21663ea1ae9f58/ Kev On Feb 2, 2:29 am, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: Sorry! That should have read; (- m :one :b) 2 On Sun, Feb 1, 2009 at 5:13 PM, e evier...@gmail.com wrote: I was able to work through the first two examples, and thanks for those. I will have to study maps more, I guess, to understand the last one. I don't know where 'x' came from: user= (- x :one :b) 2- Hide quoted text - - Show quoted text - -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: nested maps
On Wed, Jan 28, 2009 at 10:31 PM, Vincent Foley vfo...@gmail.com wrote: (- person :employer :address :city) would be my pick I tend to prefer this method as well. I find that doto and - in general are excellent tools for picking apart and poking nested structures. Vincent On Jan 28, 4:02 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: I have a map that describes a person. It has a key that describes their address. It also has a key for their employer. The employer has its own address. (def person { :name Mark Volkmann :address { :street 644 Glen Summit :city St. Charles :state Missouri :zip 63304} :employer { :name Object Computing, Inc. :address { :street 12140 Woodcrest Executive Drive, Suite 250 :city Creve Coeur :state Missouri :zip 63141}}}) Is this the best way to retrieve the employer city? (reduce get person [:employer :address :city]) Is this the best way to get a new map where the city is changed? (update-in person [:employer :address :city] (fn [old args] Clayton)) I can't get this to work with #(Clayton) in place of the anonymous function above. The function returned by constantly will take any number of arguments. -- R. Mark Volkmann Object Computing, Inc. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Dauphin: mona lisa genetic algorithm in clojure
On Tue, Jan 27, 2009 at 8:43 AM, bOR_ boris.sch...@gmail.com wrote: According to one of the posts beneath the log, the issue has been fixed in the latests svns. I have no clue what the technical problem was in clojure's source. To my understanding, the technical problem was that Clojure used the same ClassLoader for these function classes and that ClassLoader was kept live. Classes can only get GC'd when their ClassLoaders are GC'd. The solution was to give each of these functions their own ephemeral ClassLoader, so the liveness of the ClassLoader depends on the liveness of the function. When the function is no longer live, both it and its ClassLoader become legible for garbage collection. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Multi-CPU on Mac Not Exploited?
On Tue, Jan 27, 2009 at 9:34 PM, hank williams hank...@gmail.com wrote: hmm... I'm confused. From the numbers in your example it looks like server has an advantage by a factor of about 2x. But in your text you say that the client version has an advantage with complicated code. What am I missing? Does one JVM have the advantage in one situation and one in others? He most likely had them switched around by mistake in the text. The -server VM is much better at optimizing the assembly it produces, but at the cost of increased memory usage and a longer startup time. Java benchmarks are typically run with the -server VM, though the -client VM is sometimes used when comparing startup times and memory usage with other non-Java VMs. Hank On Tue, Jan 27, 2009 at 3:20 PM, dreish dresweng...@dreish.org wrote: java -server is not the default on Macs. It makes a huge difference for Clojure. % java -jar clojure.jar Clojure user= (time (reduce #(+ %1 %2 (if (odd? %1) -1 0)) (range 1000))) Elapsed time: 11793.18 msecs 499001 % java -server -jar clojure.jar Clojure user= (time (reduce #(+ %1 %2 (if (odd? %1) -1 0)) (range 1000))) Elapsed time: 6757.651 msecs 499001 The rough rule I've noticed is that the more complicated the Clojure code, the bigger the advantage -client has over -server. On Jan 27, 3:04 am, Keith Bennett keithrbenn...@gmail.com wrote: All - I tried testing the code athttp://clojure.org/Refsto see what the benefit of multicore processing would be. To my surprise, the my-pmap function took *more* time, not less, than the map function. Whereas the times listed in the article were approximately 3.1 and 1.7 seconds, on my MacBookPro 2.33 GHz Intel Core 2 Duo laptop, my times were 14.9 and 15.1 seconds. What is the correct interpretation of these results? Does one need more than 2 CPU's to see a benefit? Or is the Mac JVM only using one CPU instead of two? Or...? ...and is there something wrong with my setup that both took so long? Thanks for any enlightenment. - Keith Bennett -- blog: whydoeseverythingsuck.com -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: dispatch macros that are new to me
On Wed, Jan 28, 2009 at 12:31 AM, Cosmin Stejerean cstejer...@gmail.com wrote: On Tue, Jan 27, 2009 at 5:21 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Yes, but it's specifically meant to be used as the first line of a file, to allow Clojure script to use unix shebang format. What should follow it? Something like this? #!/Users/Mark/bin/clj That's the path to where my clj script is located. I created a script named shebang.clj that contains that line and (println Hello). Then I tried to run it with ./shebang.clj, but it tried to run it with bash instead of my clj script and didn't understand println. #!/path/to/an/executable/but/not/a/shell/script You can't have your #! line point to another file with a #! line in it. (Well, you can but it won't do what you want). But what you can do is put your clj script in /usr/local/bin and then invoke it with #!/usr/bin/env clj :) -- Cosmin Stejerean http://offbytwo.com -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: NewBie Q: doall forces eval and dorun not; but why?
On Mon, Jan 26, 2009 at 3:20 PM, e evier...@gmail.com wrote: cool. Thanks for the info about #{}. I'm glad I learned about that. To learn even more, what is the reasoning behind that choice? I've seen the sharp used for other things in clojure; is there a connection? It activates a special read-table for the following character, so it is often used for special syntax. See the Dispatch under macro characters here: http://clojure.org/reader On Mon, Jan 26, 2009 at 1:36 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 26.01.2009 um 06:05 schrieb e: interesting to me that wasn't used for anything to add to the literal syntax. folks in another thread were using sequences for set theory. But maybe there needs to be a set notation. If that makes sense, {} should be sets, just like in math, should be vectors, just like in math, and [] could be maps. I know, I know, it's kinda late to be arguing to change this stuff. Another idea that fits in better would be to use as an alternative to quoting a list . . . and still not do anything for sets. There is already literal syntax for all the collection types: - [] = vector - {} = hash-map - #{} = set What are you missing? Try to blend out experiences from other fields. Eg. we never used for vectors in math, only (). So even this comparison is only your personal experience. It's good to have such experience when learning a new language, but it should not get into your way. Whenever you end up with But in this other field/language we do/have/can , you should take a step back and forget about the other field/language and look simply at Clojure. We cannot cater all the previous experiences of all the Clojure users Just my 2¢. Sincerely Meikel -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: an example where locking is appropriate?
All other invocations return the first calculated value. I fail to spot the part of your function where you keep this promise. From what I can tell, your function would return nil on all but the first invocation. I think you forgot to write @result in the else case in your last if clause. On Mon, Jan 26, 2009 at 9:32 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: Lancet's runonce function needs to wrap a function with runs-only-once semantics, *and* make subsequent callers wait for the return value before proceeding. There was a thread on this last November where Rich explained several approaches (http://groups.google.com/group/clojure/msg/406be93eb0a226aa ). None of those approaches quite fit what Lancet needs. However, this locking approach works (I think): (defn runonce Create a function that will only run once. All other invocations return the first calculated value. The function *can* have side effects, and calls to runonce *can* be composed. Deadlock is possible if you have circular dependencies. Returns a [has-run-predicate, reset-fn, once-fn] [function] (let [sentinel (Object.) result (atom sentinel) reset-fn (fn [] (reset! result sentinel)) has-run-fn (fn [] (not= @result sentinel))] [has-run-fn reset-fn (fn [ args] (if (= @result sentinel) (locking sentinel (if (= @result sentinel) (reset! result (function))])) Is this an example where locking is reasonable, or is there a better Clojurish way? Your problem is inherently dealing with mutual exclusion. I think locking is appropriate. However, I think your double-check scheme, while safe, is of limited value. Uncontended locks, as would be the case in lancet, are pretty cheap. Stuart -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: PermGen growth
Clojure creates class not for every function call, but for every function definition. The PermGen growth you see is the REPL compiling your input, most likely. On Sun, Jan 25, 2009 at 8:26 AM, Greg Harman ghar...@gmail.com wrote: I'm trying to debug a problem in one of my programs in which PermGen usage grows with and during each run (cumulatively within the same REPL session) until I eventually run out get the out of memory JVM exception. So I wrote the following utility just to help me track usage while I hack: (defn permGen [] (let [beans (java.lang.management.ManagementFactory/ getMemoryPoolMXBeans)] (doseq [mx beans] (when (= Perm Gen (.getName mx)) (println (.getUsage mx)) I ran this several times in succession: gp= (permGen) #MemoryUsage init = 16777216(16384K) used = 11035288(10776K) committed = 16777216(16384K) max = 67108864(65536K) nil gp= (permGen) #MemoryUsage init = 16777216(16384K) used = 11036888(10778K) committed = 16777216(16384K) max = 67108864(65536K) nil gp= (permGen) #MemoryUsage init = 16777216(16384K) used = 11038488(10779K) committed = 16777216(16384K) max = 67108864(65536K) nil gp= (permGen) #MemoryUsage init = 16777216(16384K) used = 11040088(10781K) committed = 16777216(16384K) max = 67108864(65536K) The thing to notice is that the used PermGen has grown by 1-2K with each run (I ran it many more times than I pasted, and that growth rate seems pretty steady). What I don't understand is why. If I understand PermGen correctly, it holds class definitions. In Clojure classes are only generated with calls to fn (see http://groups.google.com/group/clojure/browse_thread/thread/2c66650b9057f760/11a09103da821264?lnk=gstq=permgen#11a09103da821264), and I don't have any sort of nested function creation inside my (permGen) function. I don't have any anonymous function definitions in my function, so what is causing the used PermGen growth? thanks, Greg -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Binding values in a list of symbols and evaluating as code
On Sun, Jan 25, 2009 at 11:13 AM, Christophe Grand christo...@cgrand.net wrote: Zak Wilson a écrit : know the JVM very well at all. Are there any ways around this? Are techniques that generate a lot of short-lived functions just not practical in Clojure? Yes there are a way around this: permgen memory is released when the classloader is GCed so, if you use a transient classloader, your anonymous functions can be collected. There's just this caveat; All Objects have a reference to their Class, and all Classes have a reference to their ClassLoader, which in turn have references to all Classes that it has loaded. So, if an Object whose Class was loaded by loader A holds a reference to any Object whose Class was loaded by loader B, then you will not be able to GC loader B or any of its classes. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: PermGen growth
When the reader has a top-level expression in the REPL, it gets evaluated. Evaluation goes through the Compiler which generates bytecode from your forms. Before the bytecode can be executed, it needs to be loaded into the JVM, and that happens by wrapping it in a class and loading that. On Sun, Jan 25, 2009 at 3:08 PM, Greg Harman ghar...@gmail.com wrote: I believe you, but I don't understand why. I'm doing nothing but evaluate my test function over and over. Since no new functions are being defined, why would this evaluation use any PermGen? On Jan 25, 5:57 am, Christian Vest Hansen karmazi...@gmail.com wrote: Clojure creates class not for every function call, but for every function definition. The PermGen growth you see is the REPL compiling your input, most likely. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: PermGen growth
To clarify: On Sun, Jan 25, 2009 at 3:08 PM, Greg Harman ghar...@gmail.com wrote: I believe you, but I don't understand why. I'm doing nothing but evaluate my test function over and over. Exactly. This input is evaluated and compiled over and over. Since no new functions are being defined, The expression to call your function was being defined over and over, causing new classes to be generated. This is a side-effect of eval, which the REPL is based upon. why would this evaluation use any PermGen? On Jan 25, 5:57 am, Christian Vest Hansen karmazi...@gmail.com wrote: Clojure creates class not for every function call, but for every function definition. The PermGen growth you see is the REPL compiling your input, most likely. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Regarding (.keySet {:a :map})
I type this expression in the REPL (trunk 1228): user= (let [s (.keySet {:a 1})] [(set? s) (ifn? s)]) [false false] But I expected it to return [true true]. Is this an oversight, or is there a good reason for this behavior? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Regarding (.keySet {:a :map})
On Fri, Jan 23, 2009 at 11:06 PM, Rich Hickey richhic...@gmail.com wrote: On Jan 23, 1:47 pm, Christian Vest Hansen karmazi...@gmail.com wrote: I type this expression in the REPL (trunk 1228): user= (let [s (.keySet {:a 1})] [(set? s) (ifn? s)]) [false false] But I expected it to return [true true]. Why? keySet is specified to return a java.util.Set, and that is what it does. set? tests for IPersistentSet. I assumed the persistent properties caried over, and that IPersistentSet was a java.util.Set. I also assumed that IPersistentSet extended IFn. Looks like I got the implementation confused with the interfaces and was wrong on both accounts. Rich -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Agent as a processing queue
On Thu, Jan 22, 2009 at 2:52 PM, Greg Harman ghar...@gmail.com wrote: I like the example, and I should be able to adapt it. I do have one question about the example (probably not related to agents: ; queue up some work to be done (defn add-job [func] (let [a (agent nil)] (send a (fn [_] (func))) (swap! jobs #(conj %1 a What is the notation fn [_]? I can't seem to find any documentation for what _ as a function argument means... It's a conventional name for unused/ignored arguments. On Jan 22, 6:14 am, Greg Harman ghar...@gmail.com wrote: Thanks Tim, I'll have a look at that. To clarify my use case, I was thinking of events that can be processed sequentially but that may take a non-trivial amount of time to complete (both CPU and IO bound at different stages of processing) so it's ideal to have a thread pool to process different tasks in parallel, even though they are independent. (That's step one. Step two will be spreading that thread pool out over multiple JVMs running on different hardware). On Jan 22, 2:39 am, Timothy Pratley timothyprat...@gmail.com wrote: Hi Greg Here is a proof of concept of one approach you could take:http://groups.google.com/group/clojure/web/job-queue.clj A set of agents are maintained to represent computation jobs. When the results are gathered, the agent is thrown away. I think using multiple agents in this way could be quite convenient as it means the jobs can be done in parallel. If you run the script from the command line you should get something like this: C:\javaclj job-queue.clj (4 3) (0 nil Hi mum) Which are the results of multiple queued computations taken at two subsequent points in time. From your post it wasn't clear to me if your 'events' imply sequential processing (which could be achieved with a single agent). Regards, Tim. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Streams work
On Thu, Jan 22, 2009 at 2:18 PM, Rich Hickey richhic...@gmail.com wrote: Those are important things to think about. There are, in fact, thread semantics for the streams mechanism, as for the rest of Clojure. Currently, I've made it such that the stream/iter/ seq combination ensures serialized access to the generator, allowing use of generators over otherwise unsynchronized multi-step activities. Obviously, stream-backed seqs are safe, being persistent and immutable. but it is also currently the case that the stream iter is MT safe as well. All calls to next! on an iter are atomic re: its generator, i.e. no 2 threads can be in the generator code at once. That means that, within a private consumer, you could fire up multiple threads that share the same iter and coordinate to produce a result, and return the result or a stream upon it. Used correctly, this is a powerful feature. However, I'm reluctant to expose/guarantee it, lest people start using iters as connection points and invalidating the whole stream protection model. A well- written API should take/return streams/seqs, never iters, so MT use of an iter should always be an implementation detail of a single stream step. But I can't enforce that. Hmm... could we imagine a (synced-iter an-iter) that returned a wrapped iter that _did_ guarantee MT safety? Ofcourse this only makes sense if you end up not guaranteing MT safety of ordinary iters, and I don't know enough to prefer one approach over the other. For those looking to experiment with such things, feel free to try it now and provide feedback. Thanks, Rich -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Unexpected binding behavior
On Tue, Jan 20, 2009 at 10:54 PM, Hugh Winkler hwink...@gmail.com wrote: but why not make safe the default? i.e. use unsafe-binding if you know it's OK. Not all seqs are finite. Also, Clojure skews toward lazy-by-default. Once a function has run inside a `binding, I would assume that the result it delivers is exactly what it means to deliver. And `map means to deliver a lazy seq. If `binding, however, decided to do something with that result before returning, then I would consider that a side-effect of binding. It would mean that I cannot use `binding that produce a lazy-seq sources from some IO resource or any infinite seq. This safe would probably either do too much work in the wrong thread or blow my heap. From the interaction bellow, I'd probably prefer the style of the 'h function for this kind of situation: user= (def *num* 16) #'user/*num* user= (defn f [] (map (fn [_] *num*) [1])) #'user/f user= (defn g [] (map (constantly *num*) [1])) #'user/g user= (defn h [n] (map (constantly n) [1])) #'user/h user= (binding [*num* 1024] (f)) (16) user= (binding [*num* 1024] (g)) (1024) user= (binding [*num* 1024] (h *num*)) (1024) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: JScrollPane + JTextPane trouble.
Excellent! The getScrollableTracksViewportWidth() trick did it :) On Mon, Jan 19, 2009 at 3:26 PM, MikeM michael.messini...@invista.com wrote: This might be helpful: http://os-lists.sun.com/thread.jspa?messageID=457986 -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
JScrollPane + JTextPane trouble.
Hi! Now, I know this is more related to Swing than Clojure, but they won't be able to read my code in a general Java forum. I have a JTextPane [1] inside a JScrollPane [2] and I would like to have horizontal scrollbars rather than word-wrapping. I try to disable word-wrapping by overriding the JTextPane.setSize method such that the dimensions from the JTextPane.getPreferredSize is used instead of the dimension parameter parsed to .setSize. The consequence of this disabled word-wrapping but there is an unwanted side-effect: there is no horizontal scrollbar when the content is wide and even if I force the horizontal scrollbar through policy on the JScrollPane, they will have no effect. Any attempt to move the document using the forced horisontal scrollbars will see the document jumping right back to where it came from. Finally, it may be worth to mention that this JScrollPane is used in a JSplitPane [3], in the event that makes any difference. I hope someone can tell me what I'm doing wrong here. [1]: http://github.com/karmazilla/textjure/blob/b184f842686861a3b4a947a24ea92a610edd8b46/textjure.clj#L271 [2]: http://github.com/karmazilla/textjure/blob/b184f842686861a3b4a947a24ea92a610edd8b46/textjure.clj#L318 [3]: http://github.com/karmazilla/textjure/blob/b184f842686861a3b4a947a24ea92a610edd8b46/textjure.clj#L627 -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
Another thing you might want to test is the fairness of the rw-lock in your RWDict, because even a couple of very active readers can easily starve out any number of writers when the rw-lock is non-fair. The reason is simple: readers can interleave but writers cannot, and writers can only get in when noone is reading :) On Fri, Jan 16, 2009 at 4:21 AM, Stu Hood stuh...@gmail.com wrote: Ah! but a mere hash table is not bi-directional :-) Right =) I got the idea in a Channel 9 video about MS' efforts with STM: http://channel9.msdn.com/shows/Going+Deep/Software-Transactional-Memory-The-Current-State-of-the-Art/ (which reminds me, the spin-lock approach they try is probably fairly close to using an Atom in Clojure). I made the changes that Christophe suggested, and added type hints for the HashMaps used in CLJDict, and the speed improvement is very impressive. To see the scalability of the different approaches, I graphed with various numbers of threads and read percentages: http://github.com/stuhood/clojure-conc/tree/master/results Two conclusions: 1. The overhead for STM with low contention is very reasonable, 2. Optimism + MVCC + persistence fall down when faced with a majority of writes. (see the 100% write case in the writes graph.) Thanks, Stu On Thu, Jan 15, 2009 at 2:52 PM, Christian Vest Hansen karmazi...@gmail.com wrote: On Thu, Jan 15, 2009 at 8:47 PM, Christian Vest Hansen karmazi...@gmail.com wrote: On Thu, Jan 15, 2009 at 8:35 PM, Mark H. mark.hoem...@gmail.com wrote: On Jan 15, 1:38 am, stuhood stuh...@gmail.com wrote: The benchmark contains 4 bi-directional dictionary implementations: ... Doesn't Java already have a more optimized thread-safe hash table that works by locking individual buckets, rather than the whole table? Maybe I'm just confused ;-P Ah! but a mere hash table is not bi-directional :-) -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Mysterious performance anomalies
Here's my theory. In your when example, when is a macro that is expanded to an if special form. Your other examples, however, wrap your code in a function call. Now, functions in Clojure can't really take primitive arguments, so in spite of your coercion efforts Clojure introduces boxing in your loop and this is what slows you down. A work-around is to either use a (def variable ...) or something like this: (let [x (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) i)))] (prn x)) How does that sound? On Fri, Jan 16, 2009 at 5:43 AM, Jason Wolfe jawo...@berkeley.edu wrote: I was doing some microbenchmarking earlier, and I noticed some very very weird anomalies. If anyone could shed some light on what's going on that would be awesome. (I'm using the latest SVN, and have verified this on a totally clean repl). Simplified as much as possible, the heart of what I observed is: user (prn (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) i Elapsed time: 4247.477 msecs 3000 nil user (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) i))) Elapsed time: 128.37 msecs 3000 Weird, right? The prn is *outside* the loop, and yet it still affects the timing somehow. Maybe this is something specific to printing? Nope: user (first (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) [i] Elapsed time: 4264.847 msecs 3000 user (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) [i]))) Elapsed time: 130.099 msecs [3000] But, some other expressions around the time don't affect it in the same way: user (when (time (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) [i]))) 12) Elapsed time: 130.236 msecs 12 In case you were wondering, this has nothing to do with the time macro. user (first (loop [i (int 0)] (if ( i (int 3000)) (recur (inc i)) [i]))) ; ... 4 seconds pass on my stopwatch ... 3000 And the slowness is by a multiplicative, not additive factor: user (first (time (loop [i (int 0)] (if ( i (int 6000)) (recur (inc i)) [i] Elapsed time: 8576.649 msecs 6000 user (time (loop [i (int 0)] (if ( i (int 6000)) (recur (inc i)) [i]))) Elapsed time: 250.407 msecs [6000] I'm at a total loss for what's going on. Anyway, I'll stop here for now in case I'm missing something stupid or obvious. Thanks for your help! Jason -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
On Thu, Jan 15, 2009 at 8:35 PM, Mark H. mark.hoem...@gmail.com wrote: Welcome to the group! :-) On Jan 15, 1:38 am, stuhood stuh...@gmail.com wrote: The benchmark contains 4 bi-directional dictionary implementations: * MDict - Java implementation using the synchronized keyword, * RWDict - Java implementation using a ReadWriteLock, * CLJDict - Clojure implementation using the (locking x) macro on Java HashMaps, * STMDict - Clojure implementation using two refs on maps. Doesn't Java already have a more optimized thread-safe hash table that works by locking individual buckets, rather than the whole table? Maybe I'm just confused ;-P It does: http://java.sun.com/javase/6/docs/api/java/util/concurrent/ConcurrentHashMap.html Alternative implementations of concurrency-aware HashMaps also exists out on the 'nets (NBHashMap by Cliff Click and FashHashMap in Javolution). mfh -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Synchronization Benchmarks
On Thu, Jan 15, 2009 at 8:47 PM, Christian Vest Hansen karmazi...@gmail.com wrote: On Thu, Jan 15, 2009 at 8:35 PM, Mark H. mark.hoem...@gmail.com wrote: On Jan 15, 1:38 am, stuhood stuh...@gmail.com wrote: The benchmark contains 4 bi-directional dictionary implementations: ... Doesn't Java already have a more optimized thread-safe hash table that works by locking individual buckets, rather than the whole table? Maybe I'm just confused ;-P Ah! but a mere hash table is not bi-directional :-) -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Patch: Arbitrary Symbols between ||
On Wed, Jan 14, 2009 at 1:59 PM, Rich Hickey richhic...@gmail.com wrote: I am interested in symbols with arbitrary names, Why is this interesting? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Mon, Jan 12, 2009 at 6:41 AM, Mark P pierh...@gmail.com wrote: 1. Some of the algorithms I use have the potential to be parallelized. I am hoping that as the number of cores in PCs increase, at some point Clojure's performance will beat C++'s due to Clojure's superior utilization of multiple cores. (Any ideas on how many cores are needed for this to become true?) Asuming the right algorithm, single-threaded C++ and no reflection or boxing overhead in Clojure, then I think 2 will do. 2. The JVM is continually being improved. Hopefully in a year or two, the performance of HotSpot will be closer to that of C++. (But maybe this is just wishful thinking.) We're already there. As Konrad said, they optimize differently so objective testing is hard. I think that Java is behind on optimizing cache locality because the structure of the typical Java program makes this a harder problem, that's what I've heard anyway. Sun has some wiki pages on HotSpot specific optmization techniques, which might come in handy when you want to squeeze those last 5% of performance. 3. Maybe I can implement certain performance critical components in C++ via the JNI. (But I get the impression that JNI itself isn't particularly efficient. Also, the more I pull over into the C++ side, the fewer advantages to using Clojure.) JNA might be an alternative to JNI: https://jna.dev.java.net/ But I wouldn't know; haven't used either. But instead of interfacing with C++, you might find that simply interfacing with Java will provide enough of a boost in those super-critical sections. Unless, that is, if your C++ is using dirty tricks like CUDA and what-ever-the-AMD-version-is-called. :) If all else fails, maybe I could use Clojure as a prototyping language. Then when I get it right, I code up the actual programs in C++. But probably a lot would get lost in the translation from Clojure - C++ so would it be worth it? I'd love to be convinced that Clojure is a viable choice, but I need to be a realist too. So what do people think? How realistic are my three hopes? And are there any other performance enhancing possibilities that I have not taken into account? Thanks, Mark P. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: sort behavior question
On Thu, Jan 8, 2009 at 11:38 PM, Dmitri dmitri.sotni...@gmail.com wrote: I think the main issue is that sort should behave consistently. Possibly sort could check if the elements implement Comparable before attempting to sort them? I also don't see a reason as to why the lists shouldn't implement Comparable. Comparable implies that an Object can be reduced to a scalar value, if only for the purpose of comparing. How do you imagine this should work on list of arbitrary things? -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Cons.count overflows stack (with patch)
On Wed, Jan 7, 2009 at 2:10 PM, Chouser chou...@gmail.com wrote: On Wed, Jan 7, 2009 at 2:41 AM, Christian Vest Hansen karmazi...@gmail.com wrote: On Wed, Jan 7, 2009 at 5:26 AM, Chouser chou...@gmail.com wrote: Since I couldn't find any other class that uses this kind of recursion for count(), it may be impossible to build a seq that would still cause Cons.count() to overflow the stack, but I'm not completely certain. We're all allowed to implement our own IPersistentCollections, but if they break 'count, then that would be a different bug, no? Good question. If your new collection (FooColl) implements seq() by returning a new kind of Seq (FooColl$Seq) which in turn implements FooColl$Seq.count() recursively as Cons did, it will break for long chains of FooColl$Seq. This already strikes me as very unlikely, because it would only be tempting to do in collections that accept an unmodified ISeq as part of their contents. But regardless, this would be entirely your own new code and there's nothing I can do about it. However, if FooColl$Seq avoids that error by using code like in this patch, then we would have a more subtle issue. A FooColl$Seq that includes a Cons which in turn was cons'ed onto a FooColl$Seq that includes a Cons ... and continues alternating like that for sufficient depth would defeat this patch's fix. Cons.count() would see that it's 'rest' is not a Cons, and would delegate to RT.count(). FooColl$Seq, doing the same, would create a mutual recursion situation that could overflow the stack. I think we're now firmly off in the weeds far enough to declare we can cross that bridge when we get to it, happy in the belief that we never will. But even so, FooColl$Seq could push things a little further by checking for Cons *or* FooColl$Seq and avoid recursing into either one. This would then postpone the problem until someone makes an alternating chain of FooColl$Seq and BarColl$Seq. Or those people doing tricksy stuff like this could make a careful and considered decision to design their Seq types such that they are kinds of Cons, which, logically, I'd say they are. But considering your patch, my spidey-senses have also failed to unearth a way to use this approach to blow the stack. I suppose the right way to handle this would be a signal Interface (or perhaps just a method?) declaring if a seq's count() is fast or not. Then Cons.count() could check this: if 'rest' is fast, defer to RT.count(), otherwise inc in it's own loop. This sounds to me like a lot of work and a big patch for a problem nobody's likely to have. And when it does happen in a couple of years time, we can point to this discussion and ask the guy to kindly provide a patch :-P it reminds of a JRE bug that remain undescovered for something like five years, until someone had the audacity to try and Arrays.sort an array larger than half of Integer.MAX_VALUE :) --Chouser -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Cons.count overflows stack (with patch)
On Wed, Jan 7, 2009 at 5:26 AM, Chouser chou...@gmail.com wrote: As discovered by cmvkk in IRC: user= (count (reduce #(cons %2 %) [0] (range 4601))) java.lang.StackOverflowError (NO_SOURCE_FILE:0) This is because Cons.count() is recursive via RT.count(). Presumably it's to allow efficient counting of heterogeneous seqs, like: user= (def big-vec (into [] (range 1000))) ; this is slow #'user/big-vec user= (count (cons :a big-vec)) ; but this is fast 1001 I've attached a patch that keeps this latter efficiency, but won't blow the stack for pure chains of Cons's. However, it has Cons.count() still defer to RT.count() for non-Cons rests. Since I couldn't find any other class that uses this kind of recursion for count(), it may be impossible to build a seq that would still cause Cons.count() to overflow the stack, but I'm not completely certain. We're all allowed to implement our own IPersistentCollections, but if they break 'count, then that would be a different bug, no? An alternative, of course, would be to do a simple loop as ASeq.count() does, at the cost of the efficient vector counting demonstrated above. If you have comments or questions, don't hesitate or I'll move this to the issues page! --Chouser -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: terminating an app that uses agents
You need to remember to ... clojure.core/shutdown-agents ([]) Initiates a shutdown of the thread pools that back the agent system. Running actions will complete, but no new actions will be accepted nil On Tue, Jan 6, 2009 at 3:35 AM, Mark Volkmann r.mark.volkm...@gmail.com wrote: Why doesn't the following code terminate on its own? It outputs the number 6 as expected, but then just hangs. I'm guessing its related to non-daemon threads related to agents that are still running. What's the proper way to exit? (def my-agent (agent 1)) (defn sleep-and-multiply [old-state times ms] (Thread/sleep ms) (* old-state times)) (send-off my-agent sleep-and-multiply 2 1500) (send-off my-agent sleep-and-multiply 3 1000) (await my-agent) (println my-agent = @my-agent) -- R. Mark Volkmann Object Computing, Inc. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Exercise: words frequency ranking
Hehe, venlig hilsen is danish for kind regards :) On Sat, Jan 3, 2009 at 3:23 PM, Emeka emekami...@gmail.com wrote: Venlig hilsen and Timothy Prately Thanks so much. Emeka -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Bug in .hashCode for vectors/lists (Old subject: Bugs in contains? (?))
On Sat, Jan 3, 2009 at 10:30 PM, Jason jawo...@berkeley.edu wrote: You could put those three things in some kind of order of strictness : ==: the same thing == is only for numeric types. The Java == operator is called identical? in Clojure. contains? : has something of the same type and value = : the same value Thanks for your posts. I think I understand what happens now, but I still maintain that it's a bug. In particular, the Java API says: If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. This contract is clearly violated by the .hashCode and .equals methods for Clojure vectors and lists: user (.equals [1 2] '(1 2)) true user (list (.hashCode [1 2]) (.hashCode '(1 2))) (994 -1919631597) Cheers, Jason -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Bugs in contains? (?)
On Sat, Jan 3, 2009 at 11:51 PM, Stephen C. Gilardi squee...@mac.com wrote: On Jan 3, 2009, at 5:16 PM, Meikel Brandmeyer wrote: == is for numbers. That's correct. Now that = also handles numbers in an type-independent way, do well still need == in Clojure? Is it primarily a higher performance equality check when you know you're dealing with numbers? Yes. Using == instead of = when the arguments are guaranteed to be numbers can give you quite a bit of a performance boots if your loops are tight (according to a blog post I read the other day :p ) --Steve -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: recur with many parameters
Instead of throwing a1..aN around every time, you could use the result vector and use destructuring binding in your let clause to get a1..aN into that scope. Something like (let [[a1 a2 aN :as result] (your-func ...)] ...) On Sat, Jan 3, 2009 at 11:57 PM, TPJ tpri...@gmail.com wrote: Is there some better way to call recur than that: (loop [ arg1 value1 arg2 value2 ... argn valuen ] (...) ; some stuff here (let [ (...) ; some bindings here result (my-func ...) a1 (nth result 0) a2 (nth result 1) ... an (nth result (- n 1)) ] (recur a1 a2 ... an))) I'd like to get rid of this a1, a2, ..., an and call recur in some more convenient way. I've tried (apply recur result), but without any success (Unable to resolve symbol: recur in this context). -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: update-values for clojure.contrib.sql
Well, one thing that sticks out (particularly to me) is the fact that you forgot to put your doc-string *before* your [params*] list :) (ahem) On Fri, Jan 2, 2009 at 8:21 AM, budu nbudu...@gmail.com wrote: Hi, I was experimenting with clojure-contrib's sql features and found that there wasn't any update-values function. I've written my own and I'm sharing it here: (defn update-values [table where column-names values] Update columns of a table with values. columns-names is a vector of column names (strings or keywords) and the rest of arguments are the values for those columns. (let [columns (map #(str (the-str %) = ?) column-names) template (if (seq column-names) (apply str (interpose , columns)) )] (apply do-prepared (format update %s set %s where %s (the-str table) template where) [values]))) It only send one set of values to do-prepared because of the where clause that would have to change according to each sets. I'm ready for your commentaries and/or suggestions. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: literate snake
What is it that makes this code literate? On Fri, Jan 2, 2009 at 8:07 PM, Mark Volkmann r.mark.volkm...@gmail.com wrote: I've written a new version of the snake program that uses a more literate style and therefore, to my eyes, calls for far fewer comments. I think this code is very readable. Check it out at http://www.ociweb.com/mark/programming/ClojureLiterateSnake.html. Feedback is welcomed! The most controversial thing about this code is probably my use of def to change the state of the snake and the apple. It's not yet clear to me that using atoms is needed here, but I need to think about that more. This version has some features that weren't in the original such as: - automatically turning the snake in the clockwise direction when a board edge is reached - changing the color of the snake to black when it overlaps itself - announcing a win when the length of the snake reaches 10 - automatically restarting the game after an overlap or a win -- R. Mark Volkmann Object Computing, Inc. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Constant expression optimization
According to this page: http://wikis.sun.com/display/HotSpotInternals/PerformanceTechniques Sun HotSpot is able to recognize constants in local variables, and I recall to have read somewhere that most if not all Math.* functions are intrinsic, so it should theoretically be possible. However, I don't think it happens. Clojure stores the 0.5 constant as an Object that is the result of RT.readString(0.5). This Object then has to go through Number.doubleValue prior to the call to Math.log on every invocation of foo. I would *guess* that this is too much clutter for HotSpot to figure out that the result of the Math.log call is constant-foldable, but you'd probably need to look at the generated assembly to be sure - HotSpot is very aggressive with inlining, so it's possible that it can see through the type-boxing and the call to doubleValue. So much talk for not answering the question :) On Wed, Dec 31, 2008 at 5:49 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: Suppose I write (defn foo [x] (let [f (. Math log 0.5)] (* f x))) Does the Clojure compiler calculate the constant expression (. Math log 0.5) once, or at every function call? Can I check this somehow, i.e. look at the generated code, with reasonable effort? If it doesn't optimize it, I'd have to write (let [f (. Math log 0.5)] (defn foo [x] (* f x))) which is fine as well for this minimal example, but less clear in real-life code. I'd then rather write a small macro to evaluate the constant expression, but before doing so I'd like to know if I really have to. Konrad. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Local mutually recursive functions?
On Thu, Jan 1, 2009 at 11:48 PM, Chouser chou...@gmail.com wrote: On Thu, Jan 1, 2009 at 2:47 PM, Rock rocco.ro...@gmail.com wrote: Given that there's nothing like letrec in Clojure, and that let acts like let* in CL, I gather that local recursive functions are possible whereas local mutually recursive ones are not. Is that correct? If so, will they ever be in the future? I assume you meant are not possible. I think someone previously posted a letrec macro using something he called a Y* combinator. I don't know what that is, but he said it was slow. Here's another way. Nothing about it is pretty, but it is a possibility: (let [my-even-atom (atom nil) my-even? (fn [i] (@my-even-atom i)) my-odd? (fn [i] (if (zero? i) false (@my-even-atom (dec i] (swap! my-even-atom (constantly (fn [i] (if (zero? i) true (my-odd? (dec i)) (my-odd? 4)) I don't get this listing. You define my-even? but do not use it? Ick. But perhaps a macro could make style less terrible to use? --Chouser -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggestion: introduce (defn name attr-map? [params*] doc-string body) form.
Rich rest. I have gone through the process of implementing this in defn. The patch is inlined for commenting (if need be) and attached for accurate application. I declare my changes public domain, but I suppose I could fill out a CA if it helps. I can also make a similar change for defmacro, if you want. But if you don't want this at all, then I'll go weep in a corner and leave it at that. $ svn diff Index: src/clj/clojure/core.clj === --- src/clj/clojure/core.clj(revision 1188) +++ src/clj/clojure/core.clj(working copy) @@ -183,6 +183,7 @@ name (fn ([params* ] exprs*)+)) with any doc-string or attrs added to the var metadata :arglists '([name doc-string? attr-map? [params*] body] +[name attr-map? [params*] doc-string body] [name doc-string? attr-map? ([params*] body)+ attr-map?])} defn (fn defn [name fdecl] (let [m (if (string? (first fdecl)) @@ -197,6 +198,13 @@ fdecl (if (map? (first fdecl)) (rest fdecl) fdecl) + m (if (clojure.lang.Numbers/lt 2 (clojure.lang.RT/length fdecl)) + (if (vector? (first fdecl)) +(if (string? (second fdecl)) + (if (m :doc) m (assoc m :doc (second fdecl))) + m) +m) + m) fdecl (if (vector? (first fdecl)) (list fdecl) fdecl) On Fri, Dec 19, 2008 at 1:06 PM, Christian Vest Hansen karmazi...@gmail.com wrote: On Fri, Dec 19, 2008 at 12:46 PM, Michael Wood esiot...@gmail.com wrote: Where would it go when you have multiple parameter lists and bodies? (defn blah ([a] (do-something-with a)) ([a b] (do-something-with a b))) That case should be unchanged, and work as it does today. -- Michael Wood esiot...@gmail.com -- Venlig hilsen / Kind regards, Christian Vest Hansen. -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~--- doc-string.patch Description: Binary data