Re: Enlive questions
Hi Phil! Phil Hagelberg a écrit : I'm using the Enlive library, and so far I've been pretty impressed. The way it separates templates out into their own files and doesn't allow any logic to get mixed up with them is great. Thanks for the kind words. One thing I noticed is that its templates escape all strings passed to them. In my case I have some strings that are already HTML and don't need to be escaped; is there any way to skip that? Tom gave you the answer. Also, I keep getting null pointer exceptions when I try to use deftemplate with a path to an HTML file that isn't on the classpath. This seems like an odd restriction. Is there a way to use a file in an arbitrary location as a template? You can pass an xml structure to deftemplate instead of the path, it's the only way to circumvent the classpath at the moment. I'll look into it. Christophe -- 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: Request Feedback on Clojure Blog Article
Great article! Although I’ve done only a little Ruby metaprogramming, my sense is that Clojure’s macros make it more powerful than Ruby in this respect It would be good to see a comparison of metaprogramming with macros. They sometimes are used for similar purposes, but of course are not the same thing. 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: Enlive questions
Phil Hagelberg a écrit : From what I can tell the difference seems to be that it goes inside the node if it's a string, and it replaces the node if it's a function call, even if the function call results in a string. This behaviour seems really strange. I feel like maybe there's some logic I'm missing and that it's not the string/function call difference that determines replacement vs insertion, but I can't figure out why it's behaving this way. Would appreciate any explanation I'm not quite happy with this behavior: I wanted to preserve the brevity of setting content from a parameter without resorting to (text my-parameter) but it makes things too irregular. This feature will certainly go away as I'm planning a redesign. Right now there are several cases: 1/ If the right hand side of a rule is a list and expands to a template-macro, it is applied without needing to unquote it. The matched element is replaced by the result of the template-macro. 2/ If the right hand side of a rule is a list and does not expand to a template-macro, it's random clojure code (which can apply template-macros on the matched element using unquote). The matched element is replaced. 3/ Otherwise the right hand side form is implicitly surrounded by the 'text template-macro and go to 1/ ('text replaces the content). Phil, what's your usecase for inserting raw html, where does it come from? Thanks, Christophe -- 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: Slash mystery
On 18.03.2009, at 19:03, Konrad Hinsen wrote: Why is user// an invalid token, whereas clojure.core// works perfectly well? I found out in the meantime that clojure.core// is indeed handled as a special case by the reader (line 276 in LispReader.java), but that still doesn't answer the question why. It is clear that the unqualified part of a symbol can contain a slash only at the beginning, as otherwise it could be taken for a qualified symbol. But I don't see a problem with any of the following: / (unqualified /) // (unqualified //) user// (/ in namespace user) /foo (unqualified /foo) user//foo (/foo in namespace user) But the reader allows only / and clojure.core// as special cases. Is this just a limitation of the current implementation, or is there a more fundamental reason? A workaround I found is to create the symbol on the fly with a macro: (defmacro qsym [ns sym] (symbol (str ns) (str sym))) That makes it possible to refer to user// as (qsym user /), except where the symbol would be an argument to another macro, in which case there seems to be no way around defining a specialized version of that macro, e.g. (defmacro defmethod* [ns name args] (let [qsym (symbol (str ns) (str name))] (prn qsym) `(defmethod ~qsym ~...@args))) Konrad. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can Clojure simulate Class?Lisp can do it!
Can Clojure simulate Class?Lisp can do it! Anyone know 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: Which Java book(s) to order
For the Java libraries, I like Java Cookbook 2ed by Ian Darwin. It doesn't spend much time on the language. It includes introductions to Swing, network clients and servers, regular expressions, introspection, and JDBC. It was published in 2004, so it doesn't cover Java 6. Todd Fincannon --~--~-~--~~~---~--~~ 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: Can Clojure simulate Class?Lisp can do it!
On 19.03.2009, at 07:54, Edward Shen wrote: Can Clojure simulate Class?Lisp can do it! Anyone know it? Clojure can do it as well. Look here for a library that does it: http://github.com/swannodette/spinoza/tree/master Konrad. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Possible Bug In clojure.zip/remove
Hi All, I've been teaching myself clojure and in the process am working on a small program to manipulate an XML file. I figured this was a good chance to try clojure.zip, but I'm having some difficulty. Being a newbie I strongly suspected myself - but when I posed the question on IRC the conclusion was there appears to be a bug. I boiled it down to the following: (require ['clojure.xml :as 'xml] ['clojure.zip :as 'zip]) (defn strip [root tag] (loop [loc root] (if (zip/end? loc) (zip/root loc) (recur (zip/next (if (= (:tag (zip/node loc)) tag) (zip/remove loc) loc)) (def data ?xml version=\1.0\?rootfoo/bar//root) (def xml-tree (xml/parse (java.io.ByteArrayInputStream. (.getBytes data (def zip-root (zip/xml-zip xml-tree)) (xml/emit (strip zip-root :foo)) (xml/emit (strip zip-root :bar)) The first call to strip :foo works as expected, but the following call to strip :bar throws an NPE within zip/remove. On further inspection we came clojure/zip.clj:234: (if (branch? loc) (recur (- loc down rightmost)) loc)) According to the docs, branch? can return true for a loc that does not currently have any children, so the suspicion is that it is an insufficient test before moving down as happens in the line below. I can fix this for my simple test cases by replacing the above with: (if (and (branch? loc) (not (empty? (children loc (recur (- loc down rightmost)) loc)) Being new to both clojure and zip I admit there's still a good chance that I have no idea what I'm talking about :). Cheers, Jason --~--~-~--~~~---~--~~ 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
Hi Christophe, On Mar 19, 11:22 am, Christophe Grand christo...@cgrand.net wrote: Jason Sankey a écrit : (if (and (branch? loc) (not (empty? (children loc (recur (- loc down rightmost)) loc)) Being new to both clojure and zip I admit there's still a good chance that I have no idea what I'm talking about :). No you are right and there's the same bug in prev. Here is a patch that fixes both bugs. (Rich, can I open an issue?) Thanks for the reply, and a patch which is (not surprisingly) far more elegant than my hack. Maybe this little bit of logic should be extract to its own function (alarms go off when an identical bug shows up in two places)? Also, is there somewhere I can contribute test cases for this to prevent a future regression? Btw, (not (empty? coll)) is not idiomatic, (seq coll) is the clojure way to test for non-emptiness. Thanks, I appreciate the tip. Thanks for the report, No problem, Jason --~--~-~--~~~---~--~~ 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: Can Clojure simulate Class?Lisp can do it!
On Thu, Mar 19, 2009 at 6:34 AM, Konrad Hinsen konrad.hin...@laposte.netwrote: On 19.03.2009, at 07:54, Edward Shen wrote: Can Clojure simulate Class?Lisp can do it! Anyone know it? Clojure can do it as well. Look here for a library that does it: http://github.com/swannodette/spinoza/tree/master Konrad. That library looks very useful, but if this is intended to be a repeat of the question asked one message ago, maybe ... is the question, how do you use closures to simulate a class? That library looks like it uses maps, which is nice, 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 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: Can Clojure simulate Class?Lisp can do it!
Doesn't On Lisp talk about simulating CLOS with closures? It's free online. I would like to add as the creator that I would not use Spinoza yet ;) And I've put it on hold as I'm currently obsessed with trying to port cl-cont. Spinoza still needs quite a bit of work, I started on that before a few things changed in Clojure. I will get back to it. Having now played with Clojure for a bit I'm not sure how useful Spinoza will turn out to be for anything beyond supporting widgets in a web framework. With Clojure's flexibility it's really tough to come up with reasons to resort to an object system. That said, it at least shows that building a more traditional class system is not very difficult in Clojure. David On Thu, Mar 19, 2009 at 8:01 AM, e evier...@gmail.com wrote: On Thu, Mar 19, 2009 at 6:34 AM, Konrad Hinsen konrad.hin...@laposte.netwrote: On 19.03.2009, at 07:54, Edward Shen wrote: Can Clojure simulate Class?Lisp can do it! Anyone know it? Clojure can do it as well. Look here for a library that does it: http://github.com/swannodette/spinoza/tree/master Konrad. That library looks very useful, but if this is intended to be a repeat of the question asked one message ago, maybe ... is the question, how do you use closures to simulate a class? That library looks like it uses maps, which is nice, 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 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 -~--~~~~--~~--~--~---
Complex numbers in clojure.contrib
I just checked in clojure.contrib.complex-numbers, a complex number library. For the moment it implements only comparison and arithmetic, but I intend to add maths functions later. Complex numbers are represented by struct maps with two keys, :real and :imag. The real and imaginary parts can be any number kind (or, in fact, anything for which implementations of clojure.contrib.generic exist). There is a specialized subtype representing pure imaginary numbers, which eliminates many of the useless operations with zero that complex libraries often suffer from. Feedback is welcome! Konrad. --~--~-~--~~~---~--~~ 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, 7:22 am, Christophe Grand christo...@cgrand.net wrote: Jason Sankey a écrit : (if (and (branch? loc) (not (empty? (children loc (recur (- loc down rightmost)) loc)) Being new to both clojure and zip I admit there's still a good chance that I have no idea what I'm talking about :). No you are right and there's the same bug in prev. Here is a patch that fixes both bugs. (Rich, can I open an issue?) Patch applied - svn 1335 - thanks! Rich --~--~-~--~~~---~--~~ 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: Slash mystery
On Wed, Mar 18, 2009 at 10:31 PM, Kevin Downey redc...@gmail.com wrote: Symbols starting and ending with . are reserved. see http://clojure.org/reader the section on Symbols Fair enough, but why does the (defn) succeed if these symbols are reserved? On Wed, Mar 18, 2009 at 12:58 PM, Michael Wood esiot...@gmail.com wrote: [...] user= (defn ... [] (print 'something)) #'user/... ^ user= (...) java.lang.IllegalArgumentException: Malformed member expression, expecting (.member target ...) (NO_SOURCE_FILE:4) user= -- Michael Wood esiot...@gmail.com --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Emacs: function for automatic symbols declaration
Hi, I managed to put together an Emacs Lisp function to automatically declare all defined symbols in a Clojure source file. The algorithm is crude: it doesn't understand syntax, it just parses lines beginning with either (def or (defn . A single line beginning with (declare macro must already be present. I wasn't able to match syntax of Clojure symbols inside the regex - it should have been (syntax symbol), shouldn't it? - therefore I resorted to: (any - a-z A-Z 0-9) which is incomplete. You could hook the function to file saving or something like that. It works for me. Cheers (require 'cl) (require 'rx) ;; WARNING: IMPLEMENTED BY A NEWBIE. NO WARRANTIES! (defun clj-auto-declare () (interactive *) ;; Buffer contents are going to change. (save-excursion (save-restriction (save-match-data ;; Scan buffer for defined symbols. (widen) (goto-char (point-min)) (let ((defined-symbols '())) (while (re-search-forward (rx line-start ( (or def defn) (one-or-more space) (group (one-or-more (any - a-z A-Z 0-9 nil t) (push (match-string 1) defined-symbols)) ;; Handle found symbols. (if defined-symbols ;; Scan buffer for 'declare' and update it. (progn (goto-char (point-min)) (unless (re-search-forward (rx line-start (declare (group (zero-or-more (or space (any - a-z A-Z 0-9 )) nil t) (error Global 'declare' not found. Have you entered it as a single line?)) (let ((uptodate-declare (concat (declare (mapconcat 'identity defined-symbols ) (replace-match uptodate-declare) (message Declarations have been updated.))) (message Nothing to declare, sir.))) --~--~-~--~~~---~--~~ 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 ja...@zutubi.com wrote: Also, is there somewhere I can contribute test cases for this to prevent a future regression? In order to contribute, you must fill-in and send The Contributor Agreement (CA) to Rich Hickey: http://clojure.org/contributing Tests for clojure.core are currently in clojure-contrib in test- clojure: http://code.google.com/p/clojure-contrib/source/browse/#svn/trunk/src/clojure/contrib/test_clojure There is no place yet where to put clojure.xml tests, but it shouldn't be hard to create something for it. After Rich receives your CA, you can create an issue and post a patch for it: http://code.google.com/p/clojure-contrib/issues/list An example issue: http://code.google.com/p/clojure-contrib/issues/detail?id=15 Your help with testing Clojure is very welcome! 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: Slash mystery
On Mar 19, 2009, at 11:33 AM, Michael Wood wrote: Fair enough, but why does the (defn) succeed if these symbols are reserved? Clojure does not always enforce all the rules. It may come to pass that Clojure will never enforce all the rules as the performance cost and complexity added by doing so may outweigh the potential benefits. This is something that tools can help with. One could write a program to do more detailed checking and notification of rule violations while still keeping Clojure proper tuned for executing correct programs well and quickly. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Slash mystery
Why not have two behaviours from the same code base ? There could be a strict mode versus an optimized mode. That could allow more optimizations at run time while having a clear trace in the code of these optimizations. The strict mode would be slower but that should be fine when testing. Going back to the age of lint does not look to me a progress, more like a regression... Luc On Thu, 2009-03-19 at 11:53 -0400, Stephen C. Gilardi wrote: On Mar 19, 2009, at 11:33 AM, Michael Wood wrote: Fair enough, but why does the (defn) succeed if these symbols are reserved? Clojure does not always enforce all the rules. It may come to pass that Clojure will never enforce all the rules as the performance cost and complexity added by doing so may outweigh the potential benefits. This is something that tools can help with. One could write a program to do more detailed checking and notification of rule violations while still keeping Clojure proper tuned for executing correct programs well and quickly. --Steve Luc Préfontaine Armageddon was yesterday, today we have a real problem... --~--~-~--~~~---~--~~ 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: Request Feedback on Clojure Blog Article
On Mar 19, 8:22 am, Rich Hickey richhic...@gmail.com wrote: So far it seems like sequential let has proven a useful default, and I'd rather have one let than two. Agreed - sequential let is a better default. -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: Enlive questions
Christophe Grand christo...@cgrand.net writes: I'm not quite happy with this behavior: I wanted to preserve the brevity of setting content from a parameter without resorting to (text my-parameter) but it makes things too irregular. This feature will certainly go away as I'm planning a redesign. Yeah, I'm all for brevity, but it seems that in this case it makes the rules harder to understand. Please keep the mailing list informed as to the progress of your redesign. I notice you use with-test to mix your tests in together with your implementation. This seems to be less common than storing the tests in their own file; I'm wondering if you are happy with this approach? One advantage of keeping things in their own file is that it's easier for the test suite to serve as a usage example, but keeping it together may be more convenient for other reasons. I haven't tried it myself. Right now there are several cases: 1/ If the right hand side of a rule is a list and expands to a template-macro, it is applied without needing to unquote it. The matched element is replaced by the result of the template-macro. 2/ If the right hand side of a rule is a list and does not expand to a template-macro, it's random clojure code (which can apply template-macros on the matched element using unquote). The matched element is replaced. 3/ Otherwise the right hand side form is implicitly surrounded by the 'text template-macro and go to 1/ ('text replaces the content). Thanks for explaining. Also, I keep getting null pointer exceptions when I try to use deftemplate with a path to an HTML file that isn't on the classpath. This seems like an odd restriction. Is there a way to use a file in an arbitrary location as a template? You can pass an xml structure to deftemplate instead of the path, it's the only way to circumvent the classpath at the moment. I'll look into it. I can see the benefit of looking on the classpath since it means you can store your template inside a jar and distribute everything that way. But I think it would be convenient if it could check for the existence of the file relative to the current directory first. Phil, what's your usecase for inserting raw html, where does it come from? I'm processing a number of feeds, and I want to output their contents. But I could think of many others; perhaps people would want to use an HTML-generating library like Markdown to turn user input into HTML before inserting it into the template. It's definitely less common though. -Phil --~--~-~--~~~---~--~~ 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: Enlive questions
Phil Hagelberg a écrit : I notice you use with-test to mix your tests in together with your implementation. This seems to be less common than storing the tests in their own file; I'm wondering if you are happy with this approach? One advantage of keeping things in their own file is that it's easier for the test suite to serve as a usage example, but keeping it together may be more convenient for other reasons. I haven't tried it myself. I see two advantages to using with-test: * documentation/usage examples as you pointed out, * and that makes me feel guiltier for nor updating them. I can see the benefit of looking on the classpath since it means you can store your template inside a jar and distribute everything that way. But I think it would be convenient if it could check for the existence of the file relative to the current directory first. I'll add support for java.io.File and java.net.URL as an argument to template/deftemplate/snippet/defsnippet in complement of String and xml tree. -- 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: Emacs: function for automatic symbols declaration
The code is entirely misaligned. Reposted it as in the files section: http://groups.google.com/group/clojure/web/clj-auto-declare.el Tabs are too wide, I use four spaces wide tabs. --~--~-~--~~~---~--~~ 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: Improving the test suite
Test-clojure is updated and ready for new tests :-) Frantisek On Mar 17, 5:03 am, Phil Hagelberg p...@hagelb.org wrote: OK, so I've posted a fair amount of smack talk about test suites and how important they are--I figure it's time to help out. What are some ways in which test-clojure is lacking? How can I help improve the coverage? -Phil --~--~-~--~~~---~--~~ 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: Can Clojure simulate Class?Lisp can do it!
On Mar 19, 7:17 am, David Nolen dnolen.li...@gmail.com wrote: Doesn't On Lisp talk about simulating CLOS with closures? It's free online. Building either class-based or prototype-based object systems on closures is pretty straightforward. A closure carries abritrary state around in the closed-over lexical environment. Make the closure function a suitable dispatching function, and you can then use it as a building block to build any sort of object system you like. Probably you then want to write some macros to provide a graceful syntax for interacting with whatever object system it is you've invented. I would like to add as the creator that I would not use Spinoza yet ;) And I've put it on hold as I'm currently obsessed with trying to port cl-cont. Spinoza still needs quite a bit of work, I started on that before a few things changed in Clojure. I will get back to it. Having now played with Clojure for a bit I'm not sure how useful Spinoza will turn out to be for anything beyond supporting widgets in a web framework. With Clojure's flexibility it's really tough to come up with reasons to resort to an object system. That said, it at least shows that building a more traditional class system is not very difficult in Clojure. And, as you suggest, probably not needed. After experimenting with data structures in my application, I'm satisfied with maps and sequences, though I have added a few utilities for making expected and required fields and arguments more explicit in my source. The part of CLOS that I actually want is generic functions. I also experimented with making my own gf implementation, then switched my app back and forth between that and Clojure's multifns a few times to see whether I really prefer gfs. Turns out I do, so I'm plowing some more work into the gf implementation. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Problem with SwingWorker and proxy-super
I am trying to understand how to use SwingWorker to do time-consuming work that needs to update a Swing GUI. The following makes a frame with a button (which starts a SwingWorker on the first click). Thereafter, clicking the button increments an integer n that is displayed in the first JTextField (Event Dispatch thread). Meanwhile the worker thread running the method doInBackground() increments an integer m and sleeps for 2s. On each increment it calls publish(m) which is supposed to run in the Event Dispatch thread and show the current value of m in the second JTextField. When it has done this ten times, the exit from doInBackground() causes the done() method to be called (in the Event Displatch thread), which sets the checkbox. However the code (proxy-super publish m) throws this exception: #IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: publish for class clojure.proxy.javax.swing.SwingWorker Can anyone tell me what I am doing wrong? (import '(javax.swing JFrame JPanel JButton JTextField JCheckBox SwingWorker) '(java.awt FlowLayout) '(java.awt.event ActionListener) ) (def startIt (atom true)) (def n (atom 0)) (def tf1 (doto (JTextField. 5) (. setEditable false))) (def tf2 (doto (JTextField. 5) (. setEditable false))) (def cb (JCheckBox.)) (def worker (proxy [SwingWorker] [] (doInBackground [] (try (loop [m 0] (prn (str doInBackground1: m= m)) (proxy-super publish m) (Thread/sleep 2000) (if ( m 10) (recur (inc m)) (prn (str doInBackground2: m= m (catch Exception e (prn e (process [val] (prn (str process: val= val)) (. tf2 (setText (str val (done [] (prn (str done)) (. cb (setSelected true) (def buttonAction (proxy [ActionListener] [] (actionPerformed [e] (when @startIt (. worker execute) (swap! startIt not)) (dosync (swap! n inc)) (. tf1 (setText (str @n)) (def button (doto (JButton. Press me) (. addActionListener buttonAction))) (def frame (doto (JFrame. SwingWorker test) (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE) (. add (doto (JPanel. (FlowLayout.)) (. add button) (. add tf1) (. add tf2) (. add cb))) (. pack) (. setVisible true))) --~--~-~--~~~---~--~~ 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: Can Clojure simulate Class?Lisp can do it!
On Mar 19, 2009, at 2:14 PM, mikel wrote: On Mar 19, 7:17 am, David Nolen dnolen.li...@gmail.com wrote: Doesn't On Lisp talk about simulating CLOS with closures? It's free online. Building either class-based or prototype-based object systems on closures is pretty straightforward. A closure carries abritrary state around in the closed-over lexical environment. Make the closure function a suitable dispatching function, and you can then use it as a building block to build any sort of object system you like. Probably you then want to write some macros to provide a graceful syntax for interacting with whatever object system it is you've invented. This style of 'object' system is somewhat complicated/precluded by the fact that, in Clojure, locals are immutable, thus any such object would be immutable too. That's not what you'll see in the books, where closed-over locals act as mutable fields of the object. Closing over individually mutable things like refs or atoms, while possible, would really be missing the point of Clojure's approach to programming with values. If someone's going to do an object system for Clojure, it should be one in which the entire state of an object is available as a value. http://clojure.org/state I would like to add as the creator that I would not use Spinoza yet ;) And I've put it on hold as I'm currently obsessed with trying to port cl-cont. Spinoza still needs quite a bit of work, I started on that before a few things changed in Clojure. I will get back to it. Having now played with Clojure for a bit I'm not sure how useful Spinoza will turn out to be for anything beyond supporting widgets in a web framework. With Clojure's flexibility it's really tough to come up with reasons to resort to an object system. That said, it at least shows that building a more traditional class system is not very difficult in Clojure. And, as you suggest, probably not needed. After experimenting with data structures in my application, I'm satisfied with maps and sequences, though I have added a few utilities for making expected and required fields and arguments more explicit in my source. The part of CLOS that I actually want is generic functions. I also experimented with making my own gf implementation, then switched my app back and forth between that and Clojure's multifns a few times to see whether I really prefer gfs. Turns out I do, so I'm plowing some more work into the gf implementation. What specifically about gfs do you miss/prefer? Rich --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
test-is: new feature suggestion
Hello Stuart all! As discussed in this thread: test-is: generating and processing testing data http://groups.google.com/group/clojure/browse_frm/thread/3e84efefd7c0bebc/3652a4a9a124cc6b , sometimes it is necessary to test each value against each value. Example is zeros-are-equal (as you suggested): (deftest zeros-are-equal (doall (map (fn [[a b]] (is (= a b))) (combinations [0 0.0 0M] 2 Truth is that these combinations are more common than I thought. For example, when testing equality of maps (test-equality in data_structures.clj in test_clojure), values of maps equal, but their classes are not. (= (sorted-map :a 1) (hash-map :a 1) (array-map :a 1)) = true (class (sorted-map :a 1)) = clojure.lang.PersistentTreeMap (class (hash-map :a 1)) = clojure.lang.PersistentHashMap (class (array-map :a 1)) = clojure.lang.PersistentArrayMap To test for this property, we can either write down all combinations (as I did) or write deftest function for each case (equality and non-equality). Each of these seem too verbose to me. I see 2 different solutions: 1) Allow deftest (new version of it?) to accept parameters: (deftest each-equals-each [parameter] (doall (map (fn [[a b]] (is (= a b))) (combinations parameter 2 This way we could call it: (each-equals-each [0 0.0 0M]) and (each-equals-each [(sorted-map :a 1) (hash-map :a 1) (array-map :a 1)]) 2) Create new version of 'are' - 'are-combinations' or more preferably 'are-all', which uses 'combinations' in itself: (are-all (= _1 _2) 0 0.0 0M) = (is (= 0 0.0)) (is (= 0 0M)) (is (= 0.0 0M)) This way we can easily do: (are-all (= _1 _2) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) and (are-all (not= _1 _2) (class (sorted-map :a 1)) (class (hash-map :a 1)) (class (array-map :a 1)) ) or combined? ;-) (are-all (and (= _1 _2) (not= (class _1) (class _2))) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) Personally, I prefer the second solution. It looks really elegant. The first solution - tests with parameters - is useful too and we could use it under different conditions. Thank you, Frantisek PS: What is the status of 'are' macro? Documentation still says Experimental. May be removed in the future.. Do you have any plans for it? I really like it and use it heavily in test-clojure. --~--~-~--~~~---~--~~ 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: Problem with SwingWorker and proxy-super
However the code (proxy-super publish m) throws this exception: #IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: publish for class clojure.proxy.javax.swing.SwingWorker publish is a protected method, and I don't think proxy (even with proxy-super) lets you access it. Also, even if it was public, it is a var-arg method, so you would need to supply an array. --~--~-~--~~~---~--~~ 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: Enlive questions
Christophe Grand christo...@cgrand.net writes: I see two advantages to using with-test: * documentation/usage examples as you pointed out, Actually I meant that it's nicer for documentation to have the tests in a separate file since when you're trying to learn how to use the library initially, you don't care about the implementation. So it's easier to focus just on the behaviour when you only see the tests before you. But that's a minor point. * and that makes me feel guiltier for nor updating them. Well that's a downside; if they are stored somewhere else it could be easier to ignore them. =) Depending on your editing style it may be annoying if your editor doesn't support having the two files open side-by-side. But I did notice you have the use test-is line commented out in the implementation; it seems a bit unfortunate to have to uncomment that to run the tests and hope you remember to re-comment it before you commit. I'll add support for java.io.File and java.net.URL as an argument to template/deftemplate/snippet/defsnippet in complement of String and xml tree. Sounds great; thanks. -Phil --~--~-~--~~~---~--~~ 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: Can Clojure simulate Class?Lisp can do it!
On Thu, Mar 19, 2009 at 2:13 PM, Rich Hickey richhic...@gmail.com wrote: http://clojure.org/state This is a great essay that I hadn't read before! I think it was written before Atoms were added to Clojure or they would be mentioned along with Refs and Agents. -- 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: Request Feedback on Clojure Blog Article
On Wed, Mar 18, 2009 at 10:40 PM, Stephen C. Gilardi squee...@mac.com wrote: Because parallel bindings are also useful Could you explain? I don't understand the justification for let in Lisp, when let* seems so much more useful. 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: Can Clojure simulate Class?Lisp can do it!
On Mar 19, 2:13 pm, Rich Hickey richhic...@gmail.com wrote: On Mar 19, 2009, at 2:14 PM, mikel wrote: On Mar 19, 7:17 am, David Nolen dnolen.li...@gmail.com wrote: Doesn't On Lisp talk about simulating CLOS with closures? It's free online. Building either class-based or prototype-based object systems on closures is pretty straightforward. A closure carries abritrary state around in the closed-over lexical environment. Make the closure function a suitable dispatching function, and you can then use it as a building block to build any sort of object system you like. Probably you then want to write some macros to provide a graceful syntax for interacting with whatever object system it is you've invented. This style of 'object' system is somewhat complicated/precluded by the fact that, in Clojure, locals are immutable, thus any such object would be immutable too. That's not what you'll see in the books, where closed-over locals act as mutable fields of the object. Yep, that's true, and a good point. I glossed over it as more-or-less obvious, but that's a mistake on my part. Closing over individually mutable things like refs or atoms, while possible, would really be missing the point of Clojure's approach to programming with values. If someone's going to do an object system for Clojure, it should be one in which the entire state of an object is available as a value. There's more than one reason to build an object system. Building a production object system on closures might not be the best approach for a number of reasons, depending on what your goals are, but for someone experimenting with object-system semantics in order to learn more or experiment with some ideas, implementing objects as closures over Refs might be a perfectly reasonable approach. The part of CLOS that I actually want is generic functions. I also experimented with making my own gf implementation, then switched my app back and forth between that and Clojure's multifns a few times to see whether I really prefer gfs. Turns out I do, so I'm plowing some more work into the gf implementation. What specifically about gfs do you miss/prefer? Implicit specialization on all arguments. Eql specializers. A completely deterministic method-dispatch algorithm (no need for prefer- method; the need for hand-tweaking dispatch has been a pain when trying to design extensible APIs). CALL-NEXT-METHOD. Method- combination (especially :before and :after methods). No requirement to separately specify a dispatch function. I've added a couple of modest extensions to CLOS-style GFs. Although you don't have to specify a dispatch function, you may if you wish. There's also a simpler means of customizing dispatch: you can supply a sequence of matching functions, ordered from least- to most-specific, and the default dispatch algorithm will use those instead of the standard ones. CLOS parameter matches include wildcard (any value matches), class, and eql specializers (a parameter matches if and only if it's equal to a specified value). I add matches on user- specified test functions (the so-called predicate dispatch). I also add the option to specify matching with isa? on a user-supplied hierarchy, per parameter. Maybe I've misunderstood how best to use multifns; that would be a happy discovery. I would cheerfully abandon my gf implementation if I discovered ways to use multifns that made me stop missing gfs. --~--~-~--~~~---~--~~ 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: test-is: new feature suggestion
Hi Frantisek! I can see where this is useful, and the only reason I haven't implemented something like it for a test-is already is that I don't expect it would be very commonly used outside of the very specific case of testing the language itself. Where else, other than a language specification or a math library, are you going to be testing every combination of arguments? Secondly, remember that tests are just functions, with a little extra metadata. I thought about allowing them to accept arguments, but then I didn't know how to call them in run-tests. But you can define ordinary functions and use them in your tests. It turns out to be pretty easy to define all-all are this way: (defn all-are [pred args] (doseq [[x y] (combinations args 2)] (is (pred x y (deftest equality (all-are = 0 0.0 0M 0/1) (all-are #(and (= %1 %2) (not= (class %1) (class %2))) (sorted-map :a 1) (array-map :a 1) (hash-map :a 1))) The only disadvantage to this is that you won't get some of the nice error reporting features, like individual line numbers, that you get when you use is by itself. But you would have the same problem if all-all are were a macro. So I guess, overall, I'm saying you shouldn't feel limited to using just the basic constructs that the library provides. They're just building blocks for your own, larger abstractions. If there's a particular abstraction that shows up repeatedly in lots of different contexts, then I'll want to add it to the library. As for the fate of are, I've always been a little uncertain about it because it relies heavily on the templates library. And I've always been uncertain about templates because they rely heavily on code walking and code transformation. For example, in early versions of the lazy branch, are didn't work, and I never could figure out why. Fundamentally, I think anonymous functions are a more robust abstraction than templates, and my future work will probably rely more on functions than templates. Still, several people have said they like are, so I wouldn't drop it lightly. Peace, love, and happy testing... -Stuart Sierra On Mar 19, 3:28 pm, Frantisek Sodomka fsodo...@gmail.com wrote: Hello Stuart all! As discussed in this thread: test-is: generating and processing testing datahttp://groups.google.com/group/clojure/browse_frm/thread/3e84efefd7c0... , sometimes it is necessary to test each value against each value. Example is zeros-are-equal (as you suggested): (deftest zeros-are-equal (doall (map (fn [[a b]] (is (= a b))) (combinations [0 0.0 0M] 2 Truth is that these combinations are more common than I thought. For example, when testing equality of maps (test-equality in data_structures.clj in test_clojure), values of maps equal, but their classes are not. (= (sorted-map :a 1) (hash-map :a 1) (array-map :a 1)) = true (class (sorted-map :a 1)) = clojure.lang.PersistentTreeMap (class (hash-map :a 1)) = clojure.lang.PersistentHashMap (class (array-map :a 1)) = clojure.lang.PersistentArrayMap To test for this property, we can either write down all combinations (as I did) or write deftest function for each case (equality and non-equality). Each of these seem too verbose to me. I see 2 different solutions: 1) Allow deftest (new version of it?) to accept parameters: (deftest each-equals-each [parameter] (doall (map (fn [[a b]] (is (= a b))) (combinations parameter 2 This way we could call it: (each-equals-each [0 0.0 0M]) and (each-equals-each [(sorted-map :a 1) (hash-map :a 1) (array-map :a 1)]) 2) Create new version of 'are' - 'are-combinations' or more preferably 'are-all', which uses 'combinations' in itself: (are-all (= _1 _2) 0 0.0 0M) = (is (= 0 0.0)) (is (= 0 0M)) (is (= 0.0 0M)) This way we can easily do: (are-all (= _1 _2) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) and (are-all (not= _1 _2) (class (sorted-map :a 1)) (class (hash-map :a 1)) (class (array-map :a 1)) ) or combined? ;-) (are-all (and (= _1 _2) (not= (class _1) (class _2))) (sorted-map :a 1) (hash-map :a 1) (array-map :a 1) ) Personally, I prefer the second solution. It looks really elegant. The first solution - tests with parameters - is useful too and we could use it under different conditions. Thank you, Frantisek PS: What is the status of 'are' macro? Documentation still says Experimental. May be removed in the future.. Do you have any plans for it? I really like it and use it heavily in test-clojure. --~--~-~--~~~---~--~~ 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: Request Feedback on Clojure Blog Article
On Mar 19, 2009, at 4:42 PM, Joshua Fox wrote: Because parallel bindings are also useful Could you explain? I don't understand the justification for let in Lisp, when let* seems so much more useful. As I mentioned, I like how Clojure's let works. I'm also fully on board with Rich's suggestion that before figuring out how to do something, we should first be sure it's important to do. I have not come up with any compelling reason for Clojure's let to provide more support for parallel binding than Mark Engleberg pointed out it provides already. Since Rich's comment, I've done some reading about this and I saw two justifications for the behavior of Common Lisp's let: [a] if one implements let in terms of lambda expressions, parallel binding produces one lambda expression while sequential binding produces nested lambdas, one per binding. Parallel binding implemented this way is simpler and uses less resources. In cases where you don't require the benefits of let*, use let because it's more efficient. [b] when reading the expressions bound to names in a let expression in Common Lisp, you know that each expression stands alone. In particular you know that it has not been affected by any previous bindings in the same let. I recall (perhaps imperfectly) that Rich has commented on [a] in the past with something like nobody implements let that way and Clojure's sequential let is efficient. Justification [b] sounds like it would be only a minor convenience for me, but does seem like a decent argument. Regarding Clojure's binding operation, if we were not constrained by history, I think using a map for its bindings would be an improvement. The bindings it makes are different in several key ways from those made by the binding vectors used everywhere else in Clojure: - the expressions are evaluated sequentially, but the binding is done in parallel - binding doesn't introduce new names, rather it must work with vars that already exist - the bindings it makes are thread-local and have dynamic scope rather than lexical scope - binding doesn't support destructuring Using a map would serve as a clear marker that these bindings are not like anything else in Clojure. I think the case for this became stronger when Clojure changed to require vectors wherever let-like bindings were done (e.g., dotimes) some months ago. binding uses a vector, but its bindings are not let-like. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Possible Bug In clojure.zip/remove
Hi Frantisek, Frantisek Sodomka wrote: On Mar 19, 12:58 pm, Jason Sankey ja...@zutubi.com wrote: Also, is there somewhere I can contribute test cases for this to prevent a future regression? In order to contribute, you must fill-in and send The Contributor Agreement (CA) to Rich Hickey: http://clojure.org/contributing Thanks, I have one printed out, and hope to mail it off at the start of next week. Tests for clojure.core are currently in clojure-contrib in test- clojure: http://code.google.com/p/clojure-contrib/source/browse/#svn/trunk/src/clojure/contrib/test_clojure There is no place yet where to put clojure.xml tests, but it shouldn't be hard to create something for it. After Rich receives your CA, you can create an issue and post a patch for it: http://code.google.com/p/clojure-contrib/issues/list An example issue: http://code.google.com/p/clojure-contrib/issues/detail?id=15 Your help with testing Clojure is very welcome! I appreciate the information, and will be happy to chip in with some tests when I am all CA'd up. In the mean time, as mentioned on IRC I am setting up another (unofficial) build server. I have it building both clojure and contrib already, and in the latter it runs the test suites. I would like to take this to the next step by generating reports from the tests which the server can read and thus report on the test results nicely in the UI. I am aiming to generate JUnit-compatible XML output, as this is the most widely-supported format by a variety of tools. I pretty much have it working for the test-clojure suite now, although I'm sure the code could use review by a more experienced eye. I've been looking at adding the other two top-level suites (test-contrib and datalog) too, but their test clojure scripts are structured slightly differently such that requiring them leads them to run their tests immediately. It would be nice if some convention could be established for a top-level suite to be defined/exposed, and in such a way that I could wrap them with my script which defines special reporting methods to spit out XML. Cheers, Jason --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
clojure.inspector/inspect-tree doesn't work on sets; patch attached
I was debugging with inspect-tree and noticed that it errors when it encounters a set (it thinks it's not atomic, but then nth produces an UnsupportedOperationException). I made a small patch (below) that makes inspect-tree work on java.util.Sets, and also anything else that implements clojure.lang.Seqable. If this is of interest, please let me know and I can create an issue. Cheers, Jason Index: src/clj/clojure/inspector.clj === --- src/clj/clojure/inspector.clj (revision 1335) +++ src/clj/clojure/inspector.clj (working copy) @@ -20,8 +20,10 @@ (defn collection-tag [x] (cond (instance? java.util.Map$Entry x) :entry - (instance? java.util.Map x) :map + (instance? java.util.Map x) :seqable + (instance? java.util.Set x) :seqable (sequential? x) :seq + (instance? clojure.lang.Seqable x) :seqable :else :atom)) (defmulti is-leaf collection-tag) @@ -42,11 +44,15 @@ (defmethod get-child-count :entry [e] (count (val e))) -(defmethod is-leaf :map [m] +(defmethod is-leaf :seqable [parent] false) -(defmethod get-child :map [m index] - (nth (seq m) index)) +(defmethod get-child :seqable [parent index] + (nth (seq parent) index)) +(defmethod get-child-count :seqable [parent] + (count (seq parent))) (defn tree-model [data] (proxy [TreeModel] [] (getRoot [] data) --~--~-~--~~~---~--~~ 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: Problem with SwingWorker and proxy-super
It would be a great pity if there was no way to do this, as SwingWorker is the 'proper' way for long-running code to interact with Swing objects. Any ideas for how to achieve this would be appreciated. On Mar 19, 7:35 pm, MikeM michael.messini...@invista.com wrote: However the code (proxy-superpublish m) throws this exception: #IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: publish for class clojure.proxy.javax.swing.SwingWorker publish is a protected method, and I don't think proxy (even withproxy-super) lets you access it. Also, even if it was public, it is a var-arg method, so you would need to supply an array. --~--~-~--~~~---~--~~ 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: Problem with SwingWorker and proxy-super
http://clojure.org/java_interop Note that while method fns can be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied. However this solution might be adequate: (proxy [SwingWorker] [] (doInBackground [] (try (loop [m 0] (prn (str doInBackground1: m= m)) (javax.swing.SwingUtilities/ invokeLater (fn [] (prn (str process: val= m)) (. tf2 (setText (str m) (Thread/sleep 2000) (if ( m 10) (recur (inc m)) (prn (str doInBackground2: m= m (catch Exception e (prn e (done [] (prn (str done)) (. cb (setSelected true) ie: don't use the publish/process part but instead put updates on the Event Thread explicitly. On Mar 20, 5:56 am, timc timgcl...@gmail.com wrote: I am trying to understand how to use SwingWorker to do time-consuming work that needs to update a Swing GUI. The following makes a frame with a button (which starts a SwingWorker on the first click). Thereafter, clicking the button increments an integer n that is displayed in the first JTextField (Event Dispatch thread). Meanwhile the worker thread running the method doInBackground() increments an integer m and sleeps for 2s. On each increment it calls publish(m) which is supposed to run in the Event Dispatch thread and show the current value of m in the second JTextField. When it has done this ten times, the exit from doInBackground() causes the done() method to be called (in the Event Displatch thread), which sets the checkbox. However the code (proxy-super publish m) throws this exception: #IllegalArgumentException java.lang.IllegalArgumentException: No matching method found: publish for class clojure.proxy.javax.swing.SwingWorker Can anyone tell me what I am doing wrong? (import '(javax.swing JFrame JPanel JButton JTextField JCheckBox SwingWorker) '(java.awt FlowLayout) '(java.awt.event ActionListener) ) (def startIt (atom true)) (def n (atom 0)) (def tf1 (doto (JTextField. 5) (. setEditable false))) (def tf2 (doto (JTextField. 5) (. setEditable false))) (def cb (JCheckBox.)) (def worker (proxy [SwingWorker] [] (doInBackground [] (try (loop [m 0] (prn (str doInBackground1: m= m)) (proxy-super publish m) (Thread/sleep 2000) (if ( m 10) (recur (inc m)) (prn (str doInBackground2: m= m (catch Exception e (prn e (process [val] (prn (str process: val= val)) (. tf2 (setText (str val (done [] (prn (str done)) (. cb (setSelected true) (def buttonAction (proxy [ActionListener] [] (actionPerformed [e] (when @startIt (. worker execute) (swap! startIt not)) (dosync (swap! n inc)) (. tf1 (setText (str @n)) (def button (doto (JButton. Press me) (. addActionListener buttonAction))) (def frame (doto (JFrame. SwingWorker test) (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE) (. add (doto (JPanel. (FlowLayout.)) (. add button) (. add tf1) (. add tf2) (. add cb))) (. pack) (. setVisible true))) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
I need help tracking down a performance problem.
Hello, For the past few days, I've been trying, unsuccessfully, to make an application I wrote faster. A Java program that performs, more or less, the same task takes 12 seconds (on my machine) to parse 1000 files; my Clojure program takes nearly 3 minutes. This more than an order of magnitude slower! Using the profiling tools available with the JVM, I quickly determined which function was the costliest. I copied it into a simple script file to profile it in isolation. I have made the script and the profile results (long!) available at this URL: http://gist.github.com/82136 I'm finding the results puzzling: is dereferencing a var *that* expensive? Can anyone tell me if they see something fundamentally wrong with my approach that would explain this abysmal performance? Thank you, Vincent. P.S.: I am using Sun's JVM 1.6.0_10 as shipped in Ubuntu Ibex. My machine is an Athlon 64 X2 4200+ with 3 GB of RAM. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ANN: Delimited Continuations for Clojure
You can get it here: http://github.com/swannodette/clj-cont/tree/master So over the past week I've been porting cl-cont ( http://common-lisp.net/project/cl-cont/) originally written by Slava Akhmechet to Clojure. I've now ported most of the functionality that's translatable from Common Lisp though it would be great to hear if something blatant seems to be missing. You can now do things like the following: (let [cc (atom nil)] [(with-call-cc (letfn [(a [i j] (+ i j)) (b [i j] (* (a i j) 3))] (+ (b 1 2) (let-cc k (reset! cc k) (k 0) (@cc 1)]) - [9 10] Currently these forms are supported: quote do if let letfn apply cl-cont also defines defn/cc (defn-cc) for creating functions to be used from within a with-call/cc (with-call-cc) form. It also has without-call/cc (without-call-cc) to prevent CPS transformation. These have also been ported. There are 61 tests as of now (all taken from cl-cont's test suite). Again this port only supports the shared functionality between Common Lisp and Clojure, support for Clojure specific forms is mostly missing and this is what people can help on if they like. The big questions are which Clojure special forms should be supported and how (if possible). Clearly trying to support lazy sequences isn't a goal, but supporting the STM forms (dosync, commute) as well the forms that don't rely on side-effects is just a matter of time. forks and feedback appreciated. David --~--~-~--~~~---~--~~ 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: Request Feedback on Clojure Blog Article
Tim - If you're running Windows or Linux/Unix (anything other than Mac OS X), then I think the ctrl-x key binding for the shortcut will be overridden by the text field's ctrl-x key binding, which is to the 'cut to clipboard' action. Try selecting some text and pressing ctrl- x to see. Keyboard stuff can be tricky in Swing. This one was my fault though...I should probably not have used 'x'. Regards, Keith On Mar 17, 9:03 am, Timothy Pratley timothyprat...@gmail.com wrote: I have another question! I've found your article very interesting. I really like how you have buttons and keybindings to the same AbstractAction. However when I run your app if I press ctrl-x while in a textbox nothing happens... If I'm not in a textbox it exits. I believe this is because the textboxes have DocumentListeners which swallow the ctrl-x. What would be the best way to overcome this limitation? Regards, Tim. On Mar 17, 2:44 pm, Keith Bennett keithrbenn...@gmail.com wrote: All - I am a relative newcomer to Clojure, but have been really enjoying learning and using it. I've published an article on my blog athttp://snipurl.com/dyxz7. It's about some of my impressions of Clojure based on my studies and porting of a Swing app to Clojure (a previous article discussed a JRuby port of it). It's kind of intended for newcomers to Clojure from the more conventional languages. If any of you could check it for accuracy I would appreciate it. Of course, feel free to comment on it too. Thanks, Keith Bennett --~--~-~--~~~---~--~~ 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: Request Feedback on Clojure Blog Article
I like the sequential let too. For one thing, it allows for the breaking apart of complex expressions into more comprehensible parts, with well named intermediate variables resulting in self documenting code. For another, if a calculated value is used more than once, then using an intermediate variable eliminates the code duplication that might otherwise be necessary. - Keith On Mar 19, 12:21 pm, Stuart Sierra the.stuart.sie...@gmail.com wrote: On Mar 19, 8:22 am, Rich Hickey richhic...@gmail.com wrote: So far it seems like sequential let has proven a useful default, and I'd rather have one let than two. Agreed - sequential let is a better default. -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 -~--~~~~--~~--~--~---