Re: Calling `str' on a LazySeq
Hi David, On Mar 22, 5:01 pm, David Sletten wrote: > On Mar 21, 2009, at 1:44 PM, Mark Triggs wrote: > > > user=> (str (filter even? (range 1 10))) > > "clojure.lang.lazy...@f1005" > > > Previously this would readably print the contents of the seq and some > > of my code was relying on this. Obviously it's not difficult to call > > `prn-str' myself, but I just wondered if this change was made > > consciously. > > According to the documentation for 'str': > With one arg x, returns x.toString(). > > So it looks like toString() on a sequence used to return its contents > and now doesn't. However, rather than relying on this behavior what > you probably should be doing is using 'apply': > (apply str (filter even? (range 1 10))) => "2468" > > If you want commas between those elements, use 'interpose': > (apply str (interpose ", " (filter even? (range 1 10 => "2, 4, 6, 8" Yep, that's fine. In my case I was actually relying on the fact that `str' was effectively doing a `prn-str' because I would later read it back using `read-string' elsewhere. Calling `prn-str' explicitly isn't a problem--I just thought I'd mention that the semantics have now changed a little. Thanks, Mark --~--~-~--~~~---~--~~ 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: Calling `str' on a LazySeq
On Mar 21, 2009, at 11:30 PM, Mark Triggs wrote: >> > > Yep, that's fine. In my case I was actually relying on the fact that > `str' was effectively doing a `prn-str' because I would later read it > back using `read-string' elsewhere. Calling `prn-str' explicitly > isn't a problem--I just thought I'd mention that the semantics have > now changed a little. > Sorry Mark. I guess I misunderstood what 'prn-str' does. I thought it was for I/O. I missed the print TO string part. Aloha, David Sletten --~--~-~--~~~---~--~~ 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: version of -> short-circuiting on nil
OK, Stephen checked this in, thank you very much ! Two new symbols: clojure.contrib.core/.?. clojure.contrib.core/-?> Regards, -- Laurent 2009/3/14 Laurent PETIT > Issue 34 ( http://code.google.com/p/clojure-contrib/issues/detail?id=34 ) > created with patch (both -?> and .?. defined in clojure.contrib.core, with > unit tests in clojure.contrib.core.tests > > -- > Laurent > > 3/13 Laurent PETIT > > OK, so I think the consensus is on the names .?. and -?> . No problem with >> me. >> >> I'm willing to write the patch, but which patch ? I mean, do these macros >> deserve their own file (maybe not) ? >> Maybe adding them to the existing clojure.contrib.macros ? >> Or else, I was thinking about creating a new file named >> clojure.contrib.core since these are slight variants of existing core >> functions ? >> >> 2009/3/13 Stephen C. Gilardi >> >> >>> On Mar 12, 2009, at 9:45 PM, Mark Volkmann wrote: >>> On Thu, Mar 12, 2009 at 5:04 PM, Stephen C. Gilardi wrote: > > I like these: > > .?. > -?> > >>> Given a choice between the two, I'd choose -?> >>> >>> The proposal was for naming "nil-safe" versions of the existing .. and -> >>> functions. >>> >>> (-> nil (. toString)) ==> NullPointerException >>> >>> (-?> nil (. toString)) ==> nil >>> >>> >>> (.. nil (toString)) ==> NullPointerException >>> >>> (.?. nil (toString)) ==> nil >>> >>> >>> Note: these are just simple examples. The point isn't the one argument, >>> literal nil case, but the case where many operations are "chained" or >>> "threaded" and at each point the propagated result may be nil. >>> >>> --Steve >>> >>> >> >> >> > > > --~--~-~--~~~---~--~~ 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: March 20th 2009 Rich Hickey Appreciation Day!
I join the crowd too, I was looking for a language to develop some projects. Then Clojure appeared, the light was there. Thank you Rich Hickey Stephane On Mar 20, 2:26 pm, Rayne wrote: > I Anthony Simpson, with the support of fellow Clojurists hereby > declare March 20th, the first day of spring, Rich Hickey appreciation > day! > > Rich Hickey has certainly done a lot for us, making this wonderful > language and continuing to take his time to work on it. He is > dedicated and he wants to bring Clojure along with it's users to > heights that Lisp has never been before. In just some 2 years, Rich > has gathered together a vibrant and large community of users and > contributors who believe in Clojure's future immensely . One such > contributor who believes in Clojure enough to write an entire book on > it! Clojure gains more attention and support everyday. > > I believe in the bright future that Rich Hickey believes exists for > Clojure. I believe that with this community, and with such a wonderful > creator as Rich Hickey, Clojure will achieve it's goals and meet the > destiny that Rich is writing for it. > > I thank you Rich Hicky for all your work on Clojure. I thank you for > all the time you've spent building this community and giving us one of > the most awesome languages that have existed. Thank you for caring > about us enough to listen to the community before making big changes, > I believe in Clojure and I will be here watching it evolve with you! > > If you would like to thank Rich Hickey for all he has done for us, you > can post in this thread, or tell him yourself in the #Clojure IRC > channel. :) > > March 20th 2009 Rich Hickey Appreciation Day > > -Rayne --~--~-~--~~~---~--~~ 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: atom/swap! question
Hi, Am 21.03.2009 um 23:26 schrieb Mark Volkmann: I'm looking for a suggestion on how I can get new-struct. The other aspects aside, here an answer for this question. (defn get-new-struct [the-new-map] (the-new-map (last (keys the-new-map Or, to be sure, (defn get-new-struct [the-new-map] (the-new-map (apply max (keys the-new-map This is of course ugly and O(n) as the last indicates. You could however change your b to take the atom instead of the map. (defn b [the-atom your-data] (let [new-id (get-new-id @the-atom) new-struct (make-new-struct new-id your-data)] (swap! the-atom assoc new-id new-struct) new-struct)) But now the deref and the swap! are not coordinated anymore. So one needs a Ref or an architecture, where all other users are only readers of the atom and one thread does sequentially add the new structs. Then the value of the atom wouldn't change between the deref and swap!. This maybe suggests an agent instead of an atom, but then you cannot return the new struct. And we would be back with the O(n) thing. So I agree with Laurent that you want a Ref here. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: atom/swap! question
Thanks for looking this over! It's interesting how often I find myself trying to use an Atom because I'm not coordinating changes multiple things, just one, but the solution still requires using a Ref. I guess it's wrong to think of what I'm doing as coordinating one value. I'm really coordinating two, a map and a thing inside the map (the last value added). On Sun, Mar 22, 2009 at 6:29 AM, Meikel Brandmeyer wrote: > Hi, > > Am 21.03.2009 um 23:26 schrieb Mark Volkmann: > >> I'm looking for a suggestion on how I can get new-struct. > > The other aspects aside, here an answer for this question. > > (defn get-new-struct > [the-new-map] > (the-new-map (last (keys the-new-map > > Or, to be sure, > > (defn get-new-struct > [the-new-map] > (the-new-map (apply max (keys the-new-map > > This is of course ugly and O(n) as the last indicates. > > You could however change your b to take the atom > instead of the map. > > (defn b > [the-atom your-data] > (let [new-id (get-new-id @the-atom) > new-struct (make-new-struct new-id your-data)] > (swap! the-atom assoc new-id new-struct) > new-struct)) > > But now the deref and the swap! are not coordinated > anymore. So one needs a Ref or an architecture, where > all other users are only readers of the atom and one > thread does sequentially add the new structs. Then > the value of the atom wouldn't change between the > deref and swap!. This maybe suggests an agent instead > of an atom, but then you cannot return the new struct. > And we would be back with the O(n) thing. > > So I agree with Laurent that you want a Ref here. > > Sincerely > Meikel -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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: Possible Bug In clojure.zip/remove
On Mar 19, 12:58 pm, Jason Sankey wrote: > Also, is there somewhere I can contribute test cases for this to > prevent a future regression? Tests for clojure.zip can from now on go to test-clojure.clojure-zip: http://code.google.com/p/clojure-contrib/source/browse/trunk/src/clojure/contrib/test_clojure/clojure_zip.clj On Mar 20, 1:24 pm, Jason Sankey wrote: > 3) Test-is reports results for all (is ...) expressions separately, but > there is no good way to name them separately. At the moment I am > reporting on each (is ...) as a separate test case by using the test > name plus line number, but this is clunky. I think combining the > results so one deftest == one JUnit report test case would be more sensible. If there are any troubles with test-is, you can consult Stuart Sierra (the author of test-is). Greetings, Frantisek --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
capturing stdout
I can't figure out why this function seems to work, but also produces a NullPointerException. (defn get-output [fn] (let [sw (StringWriter.)] (binding [*out* sw] (fn)) (.toString sw))) (get-output (println "foo")) -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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: capturing stdout
Never mind. I think I needed to make this a macro instead of a function like this: (defmacro get-output [fn] `(let [sw# (StringWriter.)] (binding [*out* sw#] ~fn) (.toString sw#))) On Mar 22, 9:34 am, Mark Volkmann wrote: > I can't figure out why this function seems to work, but also produces > a NullPointerException. > > (defn get-output [fn] > (let [sw (StringWriter.)] > (binding [*out* sw] (fn)) > (.toString sw))) > > (get-output (println "foo")) --~--~-~--~~~---~--~~ 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: March 20th 2009 Rich Hickey Appreciation Day!
Seriously, Rich, you are awesome. Great language. BTW. Does Rich have an Amazon wish list? On Mar 20, 11:26 am, Rayne wrote: > I Anthony Simpson, with the support of fellow Clojurists hereby > declare March 20th, the first day of spring, Rich Hickey appreciation > day! > > Rich Hickey has certainly done a lot for us, making this wonderful > language and continuing to take his time to work on it. He is > dedicated and he wants to bring Clojure along with it's users to > heights that Lisp has never been before. In just some 2 years, Rich > has gathered together a vibrant and large community of users and > contributors who believe in Clojure's future immensely . One such > contributor who believes in Clojure enough to write an entire book on > it! Clojure gains more attention and support everyday. > > I believe in the bright future that Rich Hickey believes exists for > Clojure. I believe that with this community, and with such a wonderful > creator as Rich Hickey, Clojure will achieve it's goals and meet the > destiny that Rich is writing for it. > > I thank you Rich Hicky for all your work on Clojure. I thank you for > all the time you've spent building this community and giving us one of > the most awesome languages that have existed. Thank you for caring > about us enough to listen to the community before making big changes, > I believe in Clojure and I will be here watching it evolve with you! > > If you would like to thank Rich Hickey for all he has done for us, you > can post in this thread, or tell him yourself in the #Clojure IRC > channel. :) > > March 20th 2009 Rich Hickey Appreciation Day > > -Rayne --~--~-~--~~~---~--~~ 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: Help with the dot operator special form
On Mar 21, 10:23 pm, Timothy Pratley wrote: > You may be able to achieve what you want by directly accessing > Clojure's reflector class instead of using the special form: You could also call Java's reflection API directly. -Stuart Sierra --~--~-~--~~~---~--~~ 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's a convenient way of calling super.method()?
On Mar 21, 4:38 pm, CuppoJava wrote: > For proxies, I haven't figured out a way yet. Proxies cannot call superclass methods. Classes generated with gen- class can. However, if you regularly need to call superclass methods instead of subclass methods, then you may want to rethink your design, perhaps by using different names for the "super" and "sub" methods. -Stuart Sierra --~--~-~--~~~---~--~~ 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: capturing stdout
On Mar 22, 10:34 am, Mark Volkmann wrote: > (defn get-output [fn] > (let [sw (StringWriter.)] > (binding [*out* sw] (fn)) > (.toString sw))) This is what clojure.core/with-out-str does. -Stuart Sierra --~--~-~--~~~---~--~~ 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: Method overloading & proxy method
On Mar 21, 6:13 pm, ronen wrote: > Hello there, > Iv been trying to implement a proxy on a class > (http://code.google.com/p/javaparser/source/browse/trunk/JavaParser/sr...) > that has multiple overloaded methods (same arity different types), > trying > > (defn create-visitor [] > (proxy [VoidVisitorAdapter] [] > (visit [method, arg] > (println method)) > (visit [exp, arg] > (println type > > This results with compilation error Caused by: > java.lang.IllegalArgumentException: Method 'visit' redefined. > > Type hints didn't help either: Proxy doesn't care about argument types. You need one method with a conditional: (defn create-visitor [] (proxy [VoidVisitorAdapter] [] (visit [arg1 arg2] (if (instance? MethodDeclaration arg1) ... You could also define a multimethod and call it from the proxy. -Stuart Sierra --~--~-~--~~~---~--~~ 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: The unshared part of two mostly-shared structures
On Mar 21, 6:01 pm, rapido wrote: > my programming language enchilada (www.enchiladacode.nl) has > hash=pointer equality build in. > i believe it shouldn't be to difficult to introduce some of > enchilada's internals to clojure. Hi Robbert, I imagine that hash-pointer equality would be difficult to impossible in Clojure, since it relies on Java's hash/pointer/equality semantics. But Enchilada looks interesting, and a hash-based data structure in Clojure would also be interesting. -Stuart Sierra --~--~-~--~~~---~--~~ 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's a convenient way of calling super.method()?
On Mar 22, 5:10 pm, Stuart Sierra wrote: > On Mar 21, 4:38 pm, CuppoJava wrote: > > > For proxies, I haven't figured out a way yet. > > Proxies cannot call superclass methods. Classes generated with gen- > class can. However, if you regularly need to call superclass methods > instead of subclass methods, then you may want to rethink your design, > perhaps by using different names for the "super" and "sub" methods. I think they can, using proxy-super. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
User contributed packages (Cabel, CPAN, etc)
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 --~--~-~--~~~---~--~~ 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: Help with the dot operator special form
Thanks all for the pointers, this looks like a workable approach. In my case I'm not bothered by the performance hit from reflection (CPS transformation creates an obscene number of anonymous functions anyway). However I am running into an issue. Here's my dot function: (def not-seq? (comp not seq?)) (defn dot [obj member-expr] (let [member (str (first member-expr)) arg-or-args(rest member-expr) args (if (not-seq? arg-or-args) [arg-or-args] arg-or-args)] (Reflector/invokeInstanceMethod obj member (to-array args This works fine for: (dot "Hello" (list 'substring 1 2)) But throws an exception for this: (let [myref (ref {})] (dot clojure.lang.LockingTransaction (list 'runInTransaction (fn [] (commute myref assoc :mykey :myval) I'm getting a instance method not found exception which seems odd. I looked at LockingTransaction.java and I see that runInTransaction does in fact take Callable, and fn's are Callable. Any thoughts? I knew I would have to really learn Java at some point ;) On Sun, Mar 22, 2009 at 12:06 PM, Stuart Sierra wrote: > > On Mar 21, 10:23 pm, Timothy Pratley wrote: > > You may be able to achieve what you want by directly accessing > > Clojure's reflector class instead of using the special form: > > You could also call Java's reflection API directly. > > -Stuart Sierra > > > --~--~-~--~~~---~--~~ 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: Help with the dot operator special form
> (let [myref (ref {})] > (dot > clojure.lang.LockingTransaction > (list 'runInTransaction (fn [] (commute myref assoc :mykey :myval) > I'm getting a instance method not found exception which seems odd. I looked > at LockingTransaction.java and I see that runInTransaction does in fact take > Callable, and fn's are Callable. Any thoughts? I haven't double checked the clojure code, but it looks like you are trying to call a static method, not an instance method, and that is what is causing the exception. --Eric Tschetter --~--~-~--~~~---~--~~ 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: version of -> short-circuiting on nil
On Sun, Mar 22, 2009 at 11:42 AM, Laurent PETIT wrote: > OK, Stephen checked this in, thank you very much ! > > Two new symbols: As was pointed out to me recently, http://clojure.org/reader says: "Symbols beginning or ending with '.' are reserved by Clojure." So, is .?. not a symbol (because it's called at compile time and at runtime there is no such thing as .?.)? i.e. what exactly is the definition of a symbol, and do the names of macros count? > clojure.contrib.core/.?. > clojure.contrib.core/-?> -- Michael Wood --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Behavior of clojure.set/union and hinting function arguments
Hello Rich & everybody! clojure.set/union currently accepts 'nil' as a valid argument: (union nil) => nil (union nil nil) => nil (union nil #{1 2}) => #{1 2} (union #{1 2} nil) => #{1 2} (union #{} nil) => #{} (union nil #{}) => nil ; not consistent Possible solution would be to ban 'nil' as an argument. While playing with type hinting, I discovered things that I don't understand: (defn f [#^Double x] (+ x 2)) => #'user/f (f 3) => 5 (f nil) => java.lang.NullPointerException (NO_SOURCE_FILE:0) ; why NPE? (f 2/3) => 8/3 ; why not an error that argument isn't java.lang.Double? (f "a") => java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) ; wants java.lang.Number, but I was hinting for java.lang.Double Thank you, Frantisek --~--~-~--~~~---~--~~ 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 had started on something like a package manager called Sauron ("one library to rule them all"). My idea was to be able to define dependencies with something like: (depends-on :name "clojure-json" :version "1.2.3") This would look into a ~/.sauron directory and either add a jar or a directory to the classpath. If clojure-json did not exist in ~/.sauron, the it would attempt to download it from a remote repository. The remote repositories would be either GitHub, or a Maven repo, and there would be a way to write a plugin for Sauron to add a new type of repository. I had thought that I would look into if it were possible to somehow plug this into the 'ns macro so that it could be declared with the namespace. Finally, I had thought that transitive dependencies could be handled by having a .sauron file in the root directory of a project so that Sauron would know how to find the dependencies for clojure-json, etc. http://github.com/pjstadig/sauron/tree/master I had thought through all of this, and started on some code, but it's not finalized. I had heard that dynamically adding to the classpath is not foolproof and somewhat dependent on the class loader. I'm not sure if I'm headed in the right direction, or if this is even possible, but it's worked for my limited testing, and I'm open to suggestions and contributions. Paul On Sun, Mar 22, 2009 at 12:57 PM, Bradbev 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 > > > --~--~-~--~~~---~--~~ 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: March 20th 2009 Rich Hickey Appreciation Day!
Clojure's great, thanks very much for making it available & supporting it! Anand On Fri, Mar 20, 2009 at 6:26 PM, Rayne wrote: > > I Anthony Simpson, with the support of fellow Clojurists hereby > declare March 20th, the first day of spring, Rich Hickey appreciation > day! > > Rich Hickey has certainly done a lot for us, making this wonderful > language and continuing to take his time to work on it. He is > dedicated and he wants to bring Clojure along with it's users to > heights that Lisp has never been before. In just some 2 years, Rich > has gathered together a vibrant and large community of users and > contributors who believe in Clojure's future immensely . One such > contributor who believes in Clojure enough to write an entire book on > it! Clojure gains more attention and support everyday. > > I believe in the bright future that Rich Hickey believes exists for > Clojure. I believe that with this community, and with such a wonderful > creator as Rich Hickey, Clojure will achieve it's goals and meet the > destiny that Rich is writing for it. > > I thank you Rich Hicky for all your work on Clojure. I thank you for > all the time you've spent building this community and giving us one of > the most awesome languages that have existed. Thank you for caring > about us enough to listen to the community before making big changes, > I believe in Clojure and I will be here watching it evolve with you! > > If you would like to thank Rich Hickey for all he has done for us, you > can post in this thread, or tell him yourself in the #Clojure IRC > channel. :) > > March 20th 2009 Rich Hickey Appreciation Day > > -Rayne > > > --~--~-~--~~~---~--~~ 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: version of -> short-circuiting on nil
On Mar 22, 2009, at 2:28 PM, Michael Wood wrote: As was pointed out to me recently, http://clojure.org/reader says: "Symbols beginning or ending with '.' are reserved by Clojure." So, is .?. not a symbol (because it's called at compile time and at runtime there is no such thing as .?.)? i.e. what exactly is the definition of a symbol, and do the names of macros count? clojure.contrib.core/.?. is a symbol. Thanks for pointing out that it is one that's reserved to Clojure. The reference you gave is the canonical documentation for symbols in Clojure. Symbols in Clojure are used to name things including macros. The name clojure.core/.. works and its name isn't a problem because it's part of Clojure. The case of ".?." is a little unusual (regarding using this kind of name) in that it's named as a variation of ".." for the purpose of proposing it as a possible addition to Clojure at some point. If we can't get Rich's blessing for this name to be part of contrib, we'll rename it. Rich, should we rename clojure.contrib.core/.?. to avoid using a name reserved to Clojure? --Steve smime.p7s Description: S/MIME cryptographic signature
Re: What's a convenient way of calling super.method()?
Thanks for the responses: I read into proxy-super, and it fulfills my needs. But I'm worried about my current approach for multi-methods now: As Mark put it: "Not only is it clumsy, but if mymethod returns a fresh object that is based off of this object in some way (e.g., a non-destructive "setter"), the return value will have this super-class tag rather than the original, which is probably not the desired behavior. : Which is a serious problem that hasn't occurred to me before. So, considering it seems that not many other people have run into this issue, can I assume that most people just haven't had a need to call a super multi-method? Is it a bad design choice to call your inherited methods? Thanks for the help -Patrick --~--~-~--~~~---~--~~ 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 need help tracking down a performance problem.
Vincent Foley a écrit : > The code is available at this URL: http://code.google.com/p/bwhf/ > (look at the hu.becliza.andras.bwhf.control.[BinRepParser, > BinReplayUnpacker] files) > > It is definitely not as dynamic, which helps quite a lot, but I wanted > to have something high level and declarative. > If you want to go high-level and declarative you can certainly implement this as a macro which will compile your declaration into fast static code. -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~-~--~~~---~--~~ 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 need help tracking down a performance problem.
How would I do that? Make a macro that expands into a map literal with the appropriate calls to .get, .getShort and .getInt? On Mar 22, 4:20 pm, Christophe Grand wrote: > Vincent Foley a écrit :> The code is available at this > URL:http://code.google.com/p/bwhf/ > > (look at the hu.becliza.andras.bwhf.control.[BinRepParser, > > BinReplayUnpacker] files) > > > It is definitely not as dynamic, which helps quite a lot, but I wanted > > to have something high level and declarative. > > If you want to go high-level and declarative you can certainly implement > this as a macro which will compile your declaration into fast static code. > > -- > Professional:http://cgrand.net/(fr) > On Clojure:http://clj-me.blogspot.com/(en) --~--~-~--~~~---~--~~ 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: version of -> short-circuiting on nil
Hi, Am 22.03.2009 um 20:45 schrieb Stephen C. Gilardi: clojure.contrib.core/.?. is a symbol. Thanks for pointing out that it is one that's reserved to Clojure. Rich, should we rename clojure.contrib.core/.?. to avoid using a name reserved to Clojure? I'd like to throw in another thought: Is .?. necessary? -> does the same job as .. by virtue of the .method notation, but is more general. So, why not get rid of .. and .?. completely? Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Help with the dot operator special form
That was it! At one point I knew these things. Thanks much. On Sun, Mar 22, 2009 at 2:18 PM, Eric Tschetter wrote: > > > (let [myref (ref {})] > > (dot > >clojure.lang.LockingTransaction > >(list 'runInTransaction (fn [] (commute myref assoc :mykey :myval) > > I'm getting a instance method not found exception which seems odd. I > looked > > at LockingTransaction.java and I see that runInTransaction does in fact > take > > Callable, and fn's are Callable. Any thoughts? > > I haven't double checked the clojure code, but it looks like you are > trying to call a static method, not an instance method, and that is > what is causing the exception. > > --Eric Tschetter > > > > --~--~-~--~~~---~--~~ 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 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: The unshared part of two mostly-shared structures
Thanks for the comments, folks. I may be able to raw some ideas from them. In my specific case, restrictive rules about the types of the objects may be quite workable. For example, I don't think I'd suffer if the state-preserving objects were all required to be hash-maps. I'll think some more about it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com 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: Method overloading & proxy method
Well it seems to be more complicated than that, defining a visit method overrides the call to the visit(CompilationUnit n, A arg) method which contains the basic visitation logic, what that I actually need is a way of overriding specific methods (like the visit (MethodDeclaration n, A arg) and not all of them. My best guess is that I should somehow manually map the proxy methods. On Mar 22, 6:19 pm, Stuart Sierra wrote: > On Mar 21, 6:13 pm, ronen wrote: > > > > > Hello there, > > Iv been trying to implement a proxy on a class > > (http://code.google.com/p/javaparser/source/browse/trunk/JavaParser/sr...) > > that has multiple overloaded methods (same arity different types), > > trying > > > (defn create-visitor [] > > (proxy [VoidVisitorAdapter] [] > > (visit [method, arg] > > (println method)) > > (visit [exp, arg] > > (println type > > > This results with compilation error Caused by: > > java.lang.IllegalArgumentException: Method 'visit' redefined. > > > Type hints didn't help either: > > Proxy doesn't care about argument types. You need one method with a > conditional: > > (defn create-visitor [] > (proxy [VoidVisitorAdapter] [] > (visit [arg1 arg2] > (if (instance? MethodDeclaration arg1) > ... > > You could also define a multimethod and call it from the proxy. > > -Stuart Sierra --~--~-~--~~~---~--~~ 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: Help with the dot operator special form
Thanks again to all for the help, clj-cont now supports the new and dot special forms. This also means that dosync, doto, .. all work perfectly fine from within a with-call-cc form. You can now write things like this: (let [cc (atom nil)] [(with-call-cc (. (let-cc k (reset! cc k) (k "Hello")) substring 2)) (@cc "Goodbye")]) -> ["llo" "odbye"] One caveat is that you can't use the let-cc form within a dosync block that's embedded in a with-call-cc. This is probably for the best anyway. Also since the dot and new forms are being transformed into a version that relies on reflection you can't expect this code to be super performant. That may or may matter depending on your use case ;) On Sun, Mar 22, 2009 at 5:28 PM, David Nolen wrote: > That was it! At one point I knew these things. Thanks much. > > > On Sun, Mar 22, 2009 at 2:18 PM, Eric Tschetter wrote: > >> >> > (let [myref (ref {})] >> > (dot >> >clojure.lang.LockingTransaction >> >(list 'runInTransaction (fn [] (commute myref assoc :mykey >> :myval) >> > I'm getting a instance method not found exception which seems odd. I >> looked >> > at LockingTransaction.java and I see that runInTransaction does in fact >> take >> > Callable, and fn's are Callable. Any thoughts? >> >> I haven't double checked the clojure code, but it looks like you are >> trying to call a static method, not an instance method, and that is >> what is causing the exception. >> >> --Eric Tschetter >> >> >> >> > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Java Posse exposure
Many of you may be familiar with the "Java Posse" podcast. Their website is http://javaposse.com/. Near the end of the most recent episode, #235, they mentioned my Clojure article and provided a link on their website. So more press for Clojure! BTW, I have made many updates to the article since I first announced it. Many of the updates were inspired by feedback I received from this list. Thank you very much for that! For a list of the updates that were made and a link to the latest version of the article, see http://ociweb.com/mark/clojure/. I'm always open to more suggestions and will continue improving it so it can remain a valuable resource for people that want to learn Clojure. -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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)
On Mar 22, 12:57 pm, Bradbev 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. Speaking as a contributor, I don't think it's big enough to qualify as a standard library yet. It's just odds and ends, plus a testing ground for possible new features in core. On Mar 22, 5:46 pm, Christian Vest Hansen wrote: > I was hoping that we could piggy-back on one of Java's packaging > ... the Maven repository system is pretty popular and even > supported by build tools other than Maven Maven is a big, complicated beast, but... it's there, it's widely deployed, and it's Java. That makes it a good choice in my book. The less new infrastructure Clojure requires, the better, I believe. -Stuart Sierra --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
contrib mmap/duck_streams for binary data
While playing around and implementing straight up Humman compression, I wrote a handful of utilities to conveinently play with byte and bit streams because I didn't see anything too helpful in the mmap and duck_stream files. What I wrote would need to be changed to better work with the existing code and to increase performance, but does anyone think that it would be helpful to add these things for playing with binary data into contrib? ; to exercise everything -- use this to copy a file -- obviously change the files (time (to-file "/Users/kaz/Desktop/Programming Clojure-copy.pdf" (bit- to-byte-stream (byte-to-bit-stream (to-byte-stream "/Users/kaz/Desktop/ Programming Clojure.pdf") ; to play with Huffman compress/decompression (compress-file "/Users/kaz/Desktop/onlisp.pdf" "/Users/kaz/Desktop/ onlisp.pdf.compress") (uncompress-file "/Users/kaz/Desktop/onlisp.pdf.compress" "/Users/kaz/ Desktop/onlisp2.pdf") ; ;-- setup files to act like streams at the bit level - ; (defn array-to-list [arr list-size] (loop [index 0 accum []] (if (or (= index (alength arr)) (= index list-size)) accum (recur (inc index) (conj accum (aget arr index)) (defn list-to-array [l array-type arr-size] (let [arr-size (min arr-size (count l)) arr (make-array array-type arr-size)] (loop [index 0 l l] (if (= index arr-size) arr (do (aset arr index (first l)) (recur (inc index) (rest l))) (defn num-to-bits [num size] (loop [num num size size accum nil] (if (= size 0) accum (let [next-n (bit-shift-right num 1) next-bit (bit-xor num (bit-shift-left next-n 1))] (recur next-n (dec size) (cons next-bit accum)) (import '(java.io FileInputStream FileOutputStream)) (defn to-byte-stream [filename] (let [bufsize 65536 is (FileInputStream. filename) read-buf (fn [] (let [buf (make-array (Byte/TYPE) bufsize) num-read (.read is buf 0 bufsize)] (if (= num-read -1) (do (.close is) nil) (array-to-list buf num-read read-all (fn read-all [] (let [next-buf (read-buf)] (if (nil? next-buf) nil (lazy-cat next-buf (read-all)] (read-all))) (defn byte-to-bit-stream [l] (if (nil? l) nil (lazy-cat (num-to-bits (first l) 8) (byte-to-bit-stream (rest l) (defn bits-to-num [l num-bit-size] (let [cnt (count (take num-bit-size l))] (if (< cnt num-bit-size) (bits-to-num (lazy-cat l (take (- num-bit-size cnt) (repeat 0))) num-bit-size) (loop [l l size num-bit-size accum 0] (if (= size 0) (list accum l) (recur (rest l) (dec size) (bit-or (bit-shift-left accum 1) (first l (defn bit-to-byte-stream [l] (if (nil? l) nil (let [[next-byte rst] (bits-to-num l 8)] (lazy-cons next-byte (bit-to-byte-stream rst) (defn to-file [filename byte-stream] (let [os (FileOutputStream. filename)] (loop [bytes byte-stream bytes-written 0] (if (nil? bytes) (do (.close os) bytes-written) (let [[bytes rest-bytes] (split-at 65536 bytes) buf (list-to-array (map byte bytes) (Byte/TYPE) 65536) wrote-now (alength buf)] (do (.write os buf 0 wrote-now) (recur rest-bytes (+ bytes-written wrote-now ; ;-- Using byte/bit streams to do huffman - ; (defn get-occurances [l] (loop [l l accum {}] (if (empty? l) accum (let [next (first l) current-count (if (nil? (accum next)) 0 (accum next)) next-accum (assoc accum next (inc current-count))] (recur (rest l) next-accum) (defn tree-has-children? [tree] (and (not (nil? tree)) (or (not (nil? (tree :left-child))) (not (nil? (tree :right-child)) (defn tree-has-lchild? [tree] (and (not (nil? tree)) (not (nil? (tree :left-child) (defn tree-has-rchild? [tree] (and (not (nil? tree)) (not (nil? (tree :right-child) (defn tree-count [tree] (if (nil? tree) 0 (+ 1 (if (tree-has-lchild? tree) (tree-count (tree :left-child)) 0) (if (tree-has-rchild? tree) (tree-count (tree :right-child)) 0 (defn get-hufftree [occurances] (let [build (fn build [occurances] (let [sorted-occurances (sort-by (fn [[tree val num-occur]] num- occur) occurances)]
Re: Behavior of clojure.set/union and hinting function arguments
On Mar 22, 2:34 pm, Frantisek Sodomka wrote: > (defn f [#^Double x] (+ x 2)) => #'user/f > (f 3) => 5 > (f nil) => java.lang.NullPointerException (NO_SOURCE_FILE:0) > ; why NPE? nil is Java null. The Clojure "+" function eventually compiles to Java "+", which throws an exception on null. > (f 2/3) => 8/3 > ; why not an error that argument isn't java.lang.Double? The type tag is just a hint, not a constraint. This might be an error in ahead-of-time compiled Clojure, but not at the REPL. > (f "a") => java.lang.ClassCastException: java.lang.String cannot be > cast to java.lang.Number (NO_SOURCE_FILE:0) > ; wants java.lang.Number, but I was hinting for java.lang.Double As above, the type tag is not a constraint. But "+" needs a number, and that *is* a constraint. -Stuart Sierra --~--~-~--~~~---~--~~ 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: version of -> short-circuiting on nil
On Mar 22, 2009, at 4:43 PM, Meikel Brandmeyer wrote: Is .?. necessary? -> does the same job as .. by virtue of the .method notation, but is more general. So, why not get rid of .. and .?. completely? That sounds right to me, Meikel. I'm in favor of keeping only -?> . --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Ant and debian 5.0 version issues
Michael Wood writes: > > Are you sure it's not trying to use gcj instead of Sun java? > > What do "java -version" and "javac -version" give you? And does > "update-alternatives --list java" or javac print anything? java -version: OpenJDK Runtime Environment (build 1.6.0_0-b11) OpenJDK Server VM (build 1.6.0_0-b11, mixed mode) javac -version: javac 1.6.0_0-internal update-alternatives --list java: /usr/bin/gij-4.3 /usr/lib/jvm/java-gcj/jre/bin/java /usr/lib/jvm/java-6-openjdk/jre/bin/java I'm stumped, I don't see anything as version 1.4. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
STM and useful concurrency
I'm trying to understand the degree to which Clojure's STM provides more concurrency than Java's blocking approach. I know it's difficult to make generalizations and that specific applications need to be measured, but I'll give it a go anyway. Clearly using STM (dosync with Refs) makes code easier to write than using Java synchronization because you don't have to determine up front which objects need to be locked. In the Clojure approach, nothing is locked. Changes in the transaction happen to in-transaction values and there is only a small amount of blocking that occurs at the end of the transaction when changes are being committed. Score one for Clojure! What concerns me though is how often the work done in two transactions running in separate threads turns out to be useful work. It seems that it will typically be the case that when two concurrent transactions access the same Refs, one of them will commit and the other will retry. The retry will discard the in-transaction changes that were made to the Refs, essentially rendering the work it did of no value. So there was increased concurrency, but not useful concurrency. Of course there is a chance that the transaction contains some conditional logic that makes it so the Refs to be accessed aren't always the same, but my speculation is that that's are rare occurrence. It's probably more typical that a transaction always accesses the same set of Refs every time it executes. This makes it seem that Java's locking approach isn't so bad. Well, it's bad that I have to identify the objects to lock, but it's good that it doesn't waste cycles doing work that will just be thrown away. I hope I'm missing some important details and will be set straight by someone! -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ 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: contrib mmap/duck_streams for binary data
Could you throw this on github, so we can easily follow along with improvements? On Mar 22, 8:25 pm, "zoglma...@gmail.com" wrote: > While playing around and implementing straight up Humman compression, > I wrote a handful of utilities to conveinently play with byte and bit > streams because I didn't see anything too helpful in the mmap and > duck_stream files. > > What I wrote would need to be changed to better work with the existing > code and to increase performance, but does anyone think that it would > be helpful to add these things for playing with binary data into > contrib? > > ; to exercise everything -- use this to copy a file -- obviously > change the files > (time (to-file "/Users/kaz/Desktop/Programming Clojure-copy.pdf" (bit- > to-byte-stream (byte-to-bit-stream (to-byte-stream "/Users/kaz/Desktop/ > Programming Clojure.pdf") > > ; to play with Huffman compress/decompression > (compress-file "/Users/kaz/Desktop/onlisp.pdf" "/Users/kaz/Desktop/ > onlisp.pdf.compress") > (uncompress-file "/Users/kaz/Desktop/onlisp.pdf.compress" "/Users/kaz/ > Desktop/onlisp2.pdf") > > ;-- > -- > ;-- setup files to act like streams at the bit level > - > ;-- > -- > (defn array-to-list [arr list-size] > (loop [index 0 accum []] > (if (or (= index (alength arr)) (= index list-size)) > accum > (recur (inc index) (conj accum (aget arr index)) > > (defn list-to-array [l array-type arr-size] > (let [arr-size (min arr-size (count l)) > arr (make-array array-type arr-size)] > (loop [index 0 l l] > (if (= index arr-size) > arr > (do > (aset arr index (first l)) > (recur (inc index) (rest l))) > > (defn num-to-bits [num size] > (loop [num num size size accum nil] > (if (= size 0) > accum > (let [next-n (bit-shift-right num 1) > next-bit (bit-xor num (bit-shift-left next-n 1))] > (recur next-n (dec size) (cons next-bit accum)) > > (import '(java.io FileInputStream FileOutputStream)) > (defn to-byte-stream [filename] > (let [bufsize 65536 > is (FileInputStream. filename) > read-buf > (fn [] > (let [buf (make-array (Byte/TYPE) bufsize) > num-read (.read is buf 0 bufsize)] > (if (= num-read -1) > (do > (.close is) > nil) > (array-to-list buf num-read > read-all > (fn read-all [] > (let [next-buf (read-buf)] > (if (nil? next-buf) > nil > (lazy-cat next-buf (read-all)] > (read-all))) > > (defn byte-to-bit-stream [l] > (if (nil? l) > nil > (lazy-cat (num-to-bits (first l) 8) (byte-to-bit-stream (rest > l) > > (defn bits-to-num [l num-bit-size] > (let [cnt (count (take num-bit-size l))] > (if (< cnt num-bit-size) > (bits-to-num (lazy-cat l (take (- num-bit-size cnt) (repeat > 0))) num-bit-size) > (loop [l l size num-bit-size accum 0] > (if (= size 0) > (list accum l) > (recur (rest l) (dec size) (bit-or (bit-shift-left accum 1) > (first l > > (defn bit-to-byte-stream [l] > (if (nil? l) > nil > (let [[next-byte rst] (bits-to-num l 8)] > (lazy-cons next-byte (bit-to-byte-stream rst) > > (defn to-file [filename byte-stream] > (let [os (FileOutputStream. filename)] > (loop [bytes byte-stream bytes-written 0] > (if (nil? bytes) > (do > (.close os) > bytes-written) > (let [[bytes rest-bytes] (split-at 65536 bytes) > buf (list-to-array (map byte bytes) (Byte/TYPE) 65536) > wrote-now (alength buf)] > (do > (.write os buf 0 wrote-now) > (recur rest-bytes (+ bytes-written wrote-now > > ;-- > -- > ;-- Using byte/bit streams to do huffman - > ;-- > -- > > (defn get-occurances [l] > (loop [l l accum {}] > (if (empty? l) > accum > (let [next (first l) > current-count (if (nil? (accum next)) 0 (accum next)) > next-accum (assoc accum next (inc current-count))] > (recur (rest l) next-accum) > > (defn tree-has-children? [tree] > (and (not (nil? tree)) (or (not (nil? (tree :left-child))) (not (nil? > (tree :right-child)) > (defn tree-has-lchild? [tree] > (and (not (nil? tree)) (not (nil? (tree :left-child) > (defn tree-has-rchild? [tree] > (and (not (nil? tree)) (not (nil? (tree :right-child
Re: version of -> short-circuiting on nil
On Sun, Mar 22, 2009 at 9:05 PM, Stephen C. Gilardi wrote: > > On Mar 22, 2009, at 4:43 PM, Meikel Brandmeyer wrote: > >> Is .?. necessary? -> does the same job as .. by >> virtue of the .method notation, but is more general. >> So, why not get rid of .. and .?. completely? > > That sounds right to me, Meikel. I'm in favor of keeping only -?> . Might I suggest "maybe->" ? This function has a strong similarity to the Maybe monad in Haskell and similar languages. "and->" would be another less Haskelly candidate, and is reminiscent of Scheme's "and-let*" which is also sort-of similar. Best, Graham --~--~-~--~~~---~--~~ 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)
Bradbev writes: > 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. I agree. The more I work with packages that have dependencies the more I realize that manually managing them will simply not scale. > 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 :) As Paul mentioned, adding to the classpath at runtime supposedly is fraught with peril, though I've never got a clear answer whether this applies to Clojure code or just Java code. I suspect it may be workable to have shell scripts that set up the classpath rather than calculating it from within Clojure code. This may be the trickiest part of the implementation since most languages with package managers have a load path mechanism that's much more flexible than the JVM's. I definitely think being able to read from the Maven repository format sounds like a good idea, though I haven't had too much interaction with the tool itself. It would probably be good to just start brainstorming about what features would be needed for such a tool: * Servers need to host jars as well as indices of metadata about jars that would indicate versions, descriptions, and dependencies between jars. * The client needs to be able to download jars and their dependent jars and store them on disk. Multiple versions of a library should be able to be installed at once. (apt-get doesn't support this natively, and a lot of unfortunate hacks are needed to work around this.) Packages should be able to specify which servers each dependency should come from. Jars should be able to be installed on a system-wide level as well as in a user's home directory. * Code needs to be able to state its dependencies, probably as part of the ns macro. Flexible version declarations will be necessary. (eg. I need exactly version 1.8.0 of a library, I need at least version 2.3.1 of a library, or I need any version in the 0.9 series starting with 0.9.1 but allowing in bugfix point-releases.) Anything else? I'd love to help out with implementation, whether by hacking Sauron or some other (hopefully less evil) alternative, but I think it's important that our efforts be unified. -Phil http://technomancy.us --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Mapping a function over a map's values
I often need to map a function over the values of a map while preserving keys--something like: [code] (defn mapmap [fn m] (let [k (keys m) v (map fn (vals m))] (zipmap k v))) (mapmap inc {:a 0, :b 1}) [/code] Is there a more concise way to do this in Clojure? If not, is this something that might be worth putting in the contrib? -Jon --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
What makes Clojure an easier Lisp?
I dove into Lisp and Scheme several times in the past, but only with Clojure did Lisp really "catch"? 1. Clojure abandons the 1950's cruft, with all-caps and abbreviations like SETQ and CDR. However, Scheme does this too, without achieving the ease of Clojure. 2. Clojure is typically illustrated with simple, practical examples. Other Lisps are often introduced as tools for theory. Not that there's anything wrong with that, like they said on Seinfeld. On the other hand, Clojure's examples are often, for better or worse, somewhat more sophisticated than the typical examples used for teaching other languages. 3. Clojure has some syntax choices that make it more readable. It specifies the use of fewer parentheses and uses three types brackets rather than just parentheses. However, some dialects of Lisp do allow the mixture of bracket types for visual variety. 4. The connection to Java, even if not essential to most introductory examples, provides a "lifeline" for the user. 5. Even though pure-functional is not what most programmers are used to, once you learn it, it makes everything else easier; in contrast to non-pure-functional Lisp dialects Any other thoughts on this? Joshua --~--~-~--~~~---~--~~ 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
i think it would be awesome if someone worked up a scenario . . . started using regular old java . . . and we could walk into a few gotchas, publicly/transparently, where a serious java guy could chime in ... and really see what the stm buys. Then we'd have an even richer appreciation for the STM model. Specifically, how learning STM is easier than learning concurrency as taught in a typical cs curriculum. On Sun, Mar 22, 2009 at 10:12 PM, Mark Volkmann wrote: > > I'm trying to understand the degree to which Clojure's STM provides > more concurrency than Java's blocking approach. I know it's difficult > to make generalizations and that specific applications need to be > measured, but I'll give it a go anyway. > > Clearly using STM (dosync with Refs) makes code easier to write than > using Java synchronization because you don't have to determine up > front which objects need to be locked. In the Clojure approach, > nothing is locked. Changes in the transaction happen to in-transaction > values and there is only a small amount of blocking that occurs at the > end of the transaction when changes are being committed. Score one for > Clojure! > > What concerns me though is how often the work done in two transactions > running in separate threads turns out to be useful work. It seems that > it will typically be the case that when two concurrent transactions > access the same Refs, one of them will commit and the other will > retry. The retry will discard the in-transaction changes that were > made to the Refs, essentially rendering the work it did of no value. > So there was increased concurrency, but not useful concurrency. > > Of course there is a chance that the transaction contains some > conditional logic that makes it so the Refs to be accessed aren't > always the same, but my speculation is that that's are rare > occurrence. It's probably more typical that a transaction always > accesses the same set of Refs every time it executes. > > This makes it seem that Java's locking approach isn't so bad. Well, > it's bad that I have to identify the objects to lock, but it's good > that it doesn't waste cycles doing work that will just be thrown away. > > I hope I'm missing some important details and will be set straight by > someone! > > -- > R. Mark Volkmann > Object Computing, Inc. > > > > --~--~-~--~~~---~--~~ 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: Mapping a function over a map's values
(defn mapmap [fn m] (into {} (map #(vector (first %) (fn (second %))) m))) On Sun, Mar 22, 2009 at 1:10 PM, Jon Nadal wrote: > > I often need to map a function over the values of a map while > preserving keys--something like: > > [code] > (defn mapmap [fn m] > (let [k (keys m) > v (map fn (vals m))] > (zipmap k v))) > > (mapmap inc {:a 0, :b 1}) > [/code] > > Is there a more concise way to do this in Clojure? If not, is this > something that might be worth putting in the contrib? > > -Jon > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: The unshared part of two mostly-shared structures
> > > my programming language enchilada (www.enchiladacode.nl) interesting. I was thinking today about how STM reminds me of version control. --~--~-~--~~~---~--~~ 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: Mapping a function over a map's values
Golf time! (defn mapmap [f m] (into {} (map (fn [[x y]] [x (f y)]) m))) On Mar 23, 2:51 pm, Kevin Downey wrote: > (defn mapmap [fn m] > (into {} (map #(vector (first %) (fn (second %))) m))) --~--~-~--~~~---~--~~ 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: Mapping a function over a map's values
On 22 March 2009 23:14, Timothy Pratley wrote: > Golf time! > > (defn mapmap [f m] > (into {} (map (fn [[x y]] [x (f y)]) m))) Ah, golf... :-) (defn mapmap [f m] (into {} (for [[k v] m] [k (f v)]))) --~--~-~--~~~---~--~~ 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)
Maven also downloads jars and dependencies automatically as a typical part of its functionality. It typically saves them in "${user.home}/.m2/repository-.jar" The naming is pretty consistent because maven strongly encourages everyone to use the same conventions. (javadoc would be in the same directory as -javadoc.jar and source code is often placed there as -sources.jar). All of this should be picked up from the "pom" (project object model) xml file, but most projects follow those conventions. is arbitrary but often follows something similar to the java package convention. All of that seems to pretty much describe what you'd want from a packaging system really. The only problem is that maven users sometimes have a tendency to demand everyone package stuff up in the format that would be convenient to them (though maven supports packaging 3rd-party libraries, some people prefer that the upstream does the packaging, and sometimes upstream doesn't actually want to be bothered with it). You can browse around on http://repo1.maven.org/maven2/ to get more of an idea how it looks in practice. Hypothetical clojure sytax might look like: (depends-on :group "antlr" :artifact "antlr" :version "2.7.1") or (depends-on :group "antlr" :artifact "antlr" :version "2.7.1" :repository " repository.example.com") Another alternative might be if the packaging system inter-operated with java web start. .jnlp files also provide much of the same version and authoritative source information. -- Aaron On Sun, Mar 22, 2009 at 10:59 PM, Phil Hagelberg wrote: > > Bradbev writes: > > > 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. > > I agree. The more I work with packages that have dependencies the more I > realize that manually managing them will simply not scale. > > > 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 :) > > As Paul mentioned, adding to the classpath at runtime supposedly is > fraught with peril, though I've never got a clear answer whether this > applies to Clojure code or just Java code. I suspect it may be workable > to have shell scripts that set up the classpath rather than calculating > it from within Clojure code. This may be the trickiest part of the > implementation since most languages with package managers have a load > path mechanism that's much more flexible than the JVM's. > > I definitely think being able to read from the Maven repository format > sounds like a good idea, though I haven't had too much interaction with > the tool itself. > > It would probably be good to just start brainstorming about what > features would be needed for such a tool: > > * Servers need to host jars as well as indices of metadata about jars > that would indicate versions, descriptions, and dependencies between > jars. > > * The client needs to be able to download jars and their dependent jars > and store them on disk. Multiple versions of a library should be able > to be installed at once. (apt-get doesn't support this natively, and a > lot of unfortunate hacks are needed to work around this.) Packages > should be able to specify which servers each dependency should come > from. Jars should be able to be installed on a system-wide level as > well as in a user's home directory. > > * Code needs to be able to state its dependencies, probably as part of > the ns macro. Flexible version declarations will be necessary. (eg. I > need exactly version 1.8.0 of a library, I need at least version 2.3.1 > of a library, or I need any version in the 0.9 series starting with > 0.9.1 but allowing in bugfix point-releases.) > > Anything else? I'd love to help out with implementation, whether by > hacking Sauron or some other (hopefully less evil) alternative, but I > think it's important that our efforts be unified. > > -Phil > http://technomancy.us > > > > --~--~-~--~~~---~--~~ 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: Mapping a function over a map's values
ooh for On Sun, Mar 22, 2009 at 9:27 PM, Jeff Valk wrote: > > On 22 March 2009 23:14, Timothy Pratley wrote: > >> Golf time! >> >> (defn mapmap [f m] >> (into {} (map (fn [[x y]] [x (f y)]) m))) > > Ah, golf... :-) > > (defn mapmap [f m] > (into {} (for [[k v] m] [k (f v)]))) > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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: New release 20090320
I'd like to remind people using Clojure and Maven that they can get nightly builds of Maven via the Tapestry360 maven snapshot repository: http://tapestry.formos.com/maven-snapshot-repository To access the nightly snapshot in Maven, you must update your pom.xml's element (creating it as necessary): tapestry-snapshots http://tapestry.formos.com/maven-snapshot-repository/ You can then add a for Clojure: org.clojure clojure-lang 1.0-SNAPSHOT Note that the repository includes a sources JAR (most IDEs will download it automatically, which may help with debugging). In addition, there's a "slim" variant, where the core library Clojure sources are NOT pre-compiled: org.clojure clojure-lang 1.0-SNAPSHOT slim On Fri, Mar 20, 2009 at 7:15 AM, Rich Hickey wrote: > > New release 20090320 - > http://clojure.googlecode.com/files/clojure_20090320.zip > > Incorporates all the recent additions - fully lazy seqs, :let option > for doseq/for, letfn for mutually recursive local fns, synchronous > watches, multi-arg set/union/difference/intersection, counted?, per- > defmulti hierarchies, #_ ignore form reader macro, future-calls, > future and pcalls/pvalues, defmulti docstrings and metadata, methods/ > prefers for multimethod reflection, uniform metadata handling for > atoms/refs/agents/vars/namespaces, condp, release-pending-sends, AOT > tweaks to support applets and Android, etc. All this in addition to > many fixes and enhancements. > > The API docs page is now current - changes to the rest of the site > will come soon. > > This release includes many patches from contributors, and input and > reports from many users - thanks all! > > Rich > > > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --~--~-~--~~~---~--~~ 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 makes Clojure an easier Lisp?
Clojure is not a pure functional programming language. It allows side- effects everywhere. On Mar 22, 3:26 pm, Joshua Fox wrote: > I dove into Lisp and Scheme several times in the past, but only with Clojure > did Lisp really "catch"? > 1. Clojure abandons the 1950's cruft, with all-caps and abbreviations like > SETQ and CDR. However, Scheme does this too, without achieving the ease of > Clojure. > > 2. Clojure is typically illustrated with simple, practical examples. Other > Lisps are often introduced as tools for theory. Not that there's anything > wrong with that, like they said on Seinfeld. On the other hand, Clojure's > examples are often, for better or worse, somewhat more sophisticated than > the typical examples used for teaching other languages. > > 3. Clojure has some syntax choices that make it more readable. It specifies > the use of fewer parentheses and uses three types brackets rather than just > parentheses. However, some dialects of Lisp do allow the mixture of bracket > types for visual variety. > > 4. The connection to Java, even if not essential to most introductory > examples, provides a "lifeline" for the user. > > 5. Even though pure-functional is not what most programmers are used to, > once you learn it, it makes everything else easier; in contrast to > non-pure-functional Lisp dialects > > Any other thoughts on this? > > Joshua --~--~-~--~~~---~--~~ 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: Mapping a function over a map's values
On Sun, 22 Mar 2009 at 23:27, Jeff Valk wrote: > Ah, golf... :-) > > (defn mapmap [f m] > (into {} (for [[k v] m] [k (f v)]))) For the record, I think the original approach is the most clear. And it's actually shorter. (defn mapmap [f m] (zipmap (keys m) (map f (vals m --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---