Idiomatic sub-hashmap
Hi, I have had need of a sub hash map function and implemented it as follows; (defn sub-hashmap Return a sub map of hmap containing the specified keys. [hmap ks] (reduce (fn [mm k] (assoc mm k (k hmap))) {} ks)) (sub-hashmap {:a 1 :b 2 :c 3} :a :c) ;= {:c 3, :a 1} Is there a similar existing function or a more idiomatic way of doing this? Thanks, Adrian. --~--~-~--~~~---~--~~ 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: Questions about the Enlive template library
Hi Tom, Tom Hickey a écrit : Snippets I think what you have suggested for snippets sounds perfect. I added defsnippet and defsnippets. Setting content escaping Thanks you for explaining the cases here. Having a better idea of what to expect will help in testing further. (I'm still trying to wrap my head around when I need to unquote or not.) You need to unquote to pass the matched element to a template-macro (at, show, set-attr, remove-attr, text, do-, xhtml-strict and select) but at the top level of the right hand form of a rule. Before I move on to the next section (which gets quite long) I had a quick question: How do I get/use an elements content? Say for instance I wanted a rule for all a tags that wrapped their content in an additional span so a href=blahmy link text/a would become a href=blahspanmy link text/span/a, how would I accomplish this? (I have a feeling I'm missing something obvious again like I did with set-attr!) You aren't missing anything, there's nothing like jQuery.wrap. But you can easily define your own template-macro: (html/deftemplate-macro wrap [xml tag attrs] {:tag tag :attrs (apply hash-map attrs) :content [xml]}) usage: (deftemplate wrap-links net/cgrand/enlive_html/example_links.html [] [:a] (wrap :span :title wrapper)) user= (apply str (wrap-links)) htmlbodyul lispan title=\wrapper\a href=\http://www.google.com\;google/a/span/li lispan title=\wrapper\a href=\http://www.cnn.com\; class=\news\cnn/a/span/li li class=\last\span title=\wrapper\a href=\http://www.apple.com\;apple/a/span span title=\wrapper\a href=\http://store.apple.com\; class=\store\apple store/a/span/li /ul/body/html Selector specificity I have an example below with a number of permutations but they show that any time an ancestor is updated in the hierarchy, no rules for decedents are applied (whether before or after). And also that once an element is updated, no further rule will be applied to it. Hmm, currently only one rule is applied per element BUT rules are applied on descendants before the update of the ancestor. Are you using an old version of Enlive? The current restriction of only one update per element can certainly be relaxed if I found a good policy for handling conflicting updates. Meanwhile, I added warnings (they can be disabled by setting *warn-on-rule-collision* to false): user= (deftemplate update-links2 net/cgrand/enlive_html/example_links.html [] [:.last :.store] (html/set-attr :type store) [:a] (html/set-attr :title links rock!)) Rule collision at: {:tag :a, :attrs {:href http://store.apple.com, :class store}, :content [apple store]} between: (html/set-attr :type store) (html/set-attr :title links rock!) #'user/update-links2 In my opinion, it would be great to have rules applied in the order they appear and that rules applied later would see all previous changes to the tree and could find/manipulate/update those elements as desired. Enlive is not that dynamic: the tree is modified and serialized at compile-time hence you can not see the result of changes depending on runtime data. Here is the output: net.cgrand.enlive-html.examples/ (apply str (update-links1)) htmlbodyullia title=\links rock!\ href=\http:// www.google.com\google/a/lilia title=\links rock!\ href= \http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a href=\http://www.apple.com\;apple/aa href= \http://store.apple.com\; class=\store\apple store/a/li/ul/ body/html It should work (descendants should be updates) on my box I get: user= (apply str (update-links1)) htmlbodyullia title=\links rock!\ href=\http://www.google.com\;google/a/lilia title=\links rock!\ href=\http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a title=\links rock!\ href=\http://www.apple.com\;apple/aa title=\links rock!\ href=\http://store.apple.com\; class=\store\apple store/a/li/ul/body/html net.cgrand.enlive-html.examples/ (apply str (update-links2)) htmlbodyullia title=\links rock!\ href=\http:// www.google.com\google/a/lilia title=\links rock!\ href= \http://www.cnn.com\; class=\news\cnn/a/lili class=\last \a title=\links rock!\ href=\http://www.apple.com\;apple/aa type=\store\ href=\http://store.apple.com\; class=\store\apple store/a/li/ul/body/html Only one update per element, first update wins. net.cgrand.enlive-html.examples/ (apply str (update-links3)) htmlbodyullia title=\links rock!\ href=\http:// www.google.com\google/a/lilia title=\links rock!\ href= \http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a href=\http://www.apple.com\;apple/aa href= \http://store.apple.com\; class=\store\apple store/a/li/ul/ body/html Here I get: htmlbodyullia title=\links rock!\ href=\http://www.google.com\;google/a/lilia title=\links rock!\ href=\http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a title=\links rock!\ href=\http://www.apple.com\;apple/aa
Re: Idiomatic sub-hashmap
Yup: select-keys user= (select-keys {:a 1 :b 2 :c 3} [:a :c]) {:c 3, :a 1} Regards, Tim. On Feb 13, 8:01 pm, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: Hi, I have had need of a sub hash map function and implemented it as follows; (defn sub-hashmap Return a sub map of hmap containing the specified keys. [hmap ks] (reduce (fn [mm k] (assoc mm k (k hmap))) {} ks)) (sub-hashmap {:a 1 :b 2 :c 3} :a :c) ;= {:c 3, :a 1} Is there a similar existing function or a more idiomatic way of doing this? Thanks, Adrian. --~--~-~--~~~---~--~~ 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: Idiomatic sub-hashmap
Thanks! On Fri, Feb 13, 2009 at 1:28 PM, Timothy Pratley timothyprat...@gmail.com wrote: Yup: select-keys user= (select-keys {:a 1 :b 2 :c 3} [:a :c]) {:c 3, :a 1} Regards, Tim. On Feb 13, 8:01 pm, Adrian Cuthbertson adrian.cuthbert...@gmail.com wrote: Hi, I have had need of a sub hash map function and implemented it as follows; (defn sub-hashmap Return a sub map of hmap containing the specified keys. [hmap ks] (reduce (fn [mm k] (assoc mm k (k hmap))) {} ks)) (sub-hashmap {:a 1 :b 2 :c 3} :a :c) ;= {:c 3, :a 1} Is there a similar existing function or a more idiomatic way of doing this? Thanks, Adrian. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
with-local-vars vs. let
What are some reasons to use with-local-vars instead of let or binding? -- 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 -~--~~~~--~~--~--~---
loop [#^Integer c 0] vs. loop [c (int 0)] and optimization question...
Hi guys, I'm optimizing a little benchmark called pnpoly, and I was wondering what is the proper way of hinting the compiler for types. In certain cases Clojure accepts for example loop [#^Integer c 0] and in others loop [c (int 0)] - I'm really trying to hint the compiler as best as I can. I'm synced to the latest SVN version (1162), and in the same source code, it seems like loop[#^Integer c 0] works for some cases, and not for others. Here is the code in question: http://paste.lisp.org/display/75370 Also please note, what I'm doing wrong in it, what could be achieved more. My next step is to parallelize it, and compare again. So on my machine Clojure gives this result: (-60 is okay, I was testing which one is better bit-not or subtracting 1 from the number). ; SLIME 2009-02-07 user (time (pnpoly/pnpolytest)) Elapsed time: 16075.309949 msecs -600 C version is about 0.8s, Lispworks 1.3s, other Common Lisps (SBCL, CMUCL) about 2.0s ABCL: 6sec (using Java 1.6_10 -server, much like what I'm using for clojure). 16seconds it's not really that bad, considering I won't be using Clojure for heavy math code, but still wanted to see what I can do more with it. For example the same example in Python, Ruby or Perl runs at least for 200s (same with CLISP, haven't tried ECL or GCL). Thanks, Dimiter malkia Stanev. --~--~-~--~~~---~--~~ 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: with-local-vars vs. let
On Feb 13, 2009, at 13:31, Mark Volkmann wrote: What are some reasons to use with-local-vars instead of let or binding? Let just creates bindings for a lexical scope. They cannot be modified at all. Binding and with-local-vars deal with vars, i.e. mutable references. Binding creates a dynamic scope for already existing vars that are accessible in some namespace. With-local-vars also creates a dynamic scope, but for newly created anonymous vars. So far for the theory. I have to admit that in my own experience, every time I considered using with-local-vars, I ended up realising that what I really wanted is atoms or refs. Which means that I cannot cite a use case for with-local-vars. I scanned through the source code of clojure and clojure-contrib to see if with-local-vars is used anywhere at all, but the answer is no. 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: loop [#^Integer c 0] vs. loop [c (int 0)] and optimization question...
Hello, I can't manage to get the code from the URL (server timeout) 2009/2/12 Dimiter malkia Stanev mal...@gmail.com Hi guys, I'm optimizing a little benchmark called pnpoly, and I was wondering what is the proper way of hinting the compiler for types. In certain cases Clojure accepts for example loop [#^Integer c 0] and in others loop [c (int 0)] - I'm really trying to hint the compiler as best as I can. I'm synced to the latest SVN version (1162), and in the same source code, it seems like loop[#^Integer c 0] works for some cases, and not for others. Here is the code in question: http://paste.lisp.org/display/75370 Also please note, what I'm doing wrong in it, what could be achieved more. My next step is to parallelize it, and compare again. So on my machine Clojure gives this result: (-60 is okay, I was testing which one is better bit-not or subtracting 1 from the number). ; SLIME 2009-02-07 user (time (pnpoly/pnpolytest)) Elapsed time: 16075.309949 msecs -600 C version is about 0.8s, Lispworks 1.3s, other Common Lisps (SBCL, CMUCL) about 2.0s ABCL: 6sec (using Java 1.6_10 -server, much like what I'm using for clojure). 16seconds it's not really that bad, considering I won't be using Clojure for heavy math code, but still wanted to see what I can do more with it. For example the same example in Python, Ruby or Perl runs at least for 200s (same with CLISP, haven't tried ECL or GCL). Thanks, Dimiter malkia Stanev. --~--~-~--~~~---~--~~ 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: loop [#^Integer c 0] vs. loop [c (int 0)] and optimization question...
Dimiter, The latest revision of Clojure is r1278; are you using the Google code trunk? Vincent On Feb 12, 5:35 pm, Dimiter \malkia\ Stanev mal...@gmail.com wrote: Hi guys, I'm optimizing a little benchmark called pnpoly, and I was wondering what is the proper way of hinting the compiler for types. In certain cases Clojure accepts for example loop [#^Integer c 0] and in others loop [c (int 0)] - I'm really trying to hint the compiler as best as I can. I'm synced to the latest SVN version (1162), and in the same source code, it seems like loop[#^Integer c 0] works for some cases, and not for others. Here is the code in question: http://paste.lisp.org/display/75370 Also please note, what I'm doing wrong in it, what could be achieved more. My next step is to parallelize it, and compare again. So on my machine Clojure gives this result: (-60 is okay, I was testing which one is better bit-not or subtracting 1 from the number). ; SLIME 2009-02-07 user (time (pnpoly/pnpolytest)) Elapsed time: 16075.309949 msecs -600 C version is about 0.8s, Lispworks 1.3s, other Common Lisps (SBCL, CMUCL) about 2.0s ABCL: 6sec (using Java 1.6_10 -server, much like what I'm using for clojure). 16seconds it's not really that bad, considering I won't be using Clojure for heavy math code, but still wanted to see what I can do more with it. For example the same example in Python, Ruby or Perl runs at least for 200s (same with CLISP, haven't tried ECL or GCL). Thanks, Dimiter malkia Stanev. --~--~-~--~~~---~--~~ 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: Issue request: RT.load's don't load if already loaded mechanism breaks :reload-all
Rich, May I please enter an issue to track the defect that require/use's :reload-all flag is not working properly in Clojure. --Steve On Feb 11, 2009, at 8:01 AM, Stephen C. Gilardi wrote: On Feb 6, 2009, at 8:45 AM, Laurent PETIT wrote: Hello, Does it also mean that the following use case will work with *reload-all* : - x.y.z is a lib that is made of two files : x/y/z.clj, and x/y/ z1.clj , and z.clj loads z1.clj - x.y.z is compiled - z1.clj is modified - x.y.z is compiled = even if x/y/z.clj nor x/y/z__init.class are in sync, the changes in z1.clj will be reloaded, because z1.clj will be forced to be reloaded from source file ? Is my understanding correct ? Yes, I tested it and for that case, the following will recompile x.y.z1: (binding [*reload-all* true] (compile 'x.y.z)) With *reload-all* in place, one could also provide clojure.core/ compile-all which calls load-all internally rather than load- one. This would recompile everything on which the given lib (directly or indirectly) depends without regard to mod-dates. (And because *loaded-libs* is still at work, each lib would only be compiled once.) If so, ++1 for this ! I'm glad the proposed change will help with the situation you asked about. The :reload-all mechanism is currently broken in Clojure and I would like to fix it. I'll be happy to include a clojure.core/ compile-all in that patch if it's welcome. (I think it would be useful.) --Steve 2009/2/6 Stephen C. Gilardi squee...@mac.com On Feb 6, 2009, at 8:28 AM, Stephen C. Gilardi wrote: When *reload-all* is true, RT.load() will (re)load all libs from their .clj files even if they're already loaded. To clarify: When *reload-all* is true, RT.load will (re)load any lib it is asked to load from the lib's .clj file even if the lib is already loaded. --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 -~--~~~~--~~--~--~--- smime.p7s Description: S/MIME cryptographic signature
Re: Reflection warnings starting at r1265
Should I add this to the list of issues in the Google Code tracker? Vincent. On Feb 12, 4:15 pm, Vincent Foley vfo...@gmail.com wrote: Hello, I was surprised today to see that my Starcraft replay program became slower when I updated my Clojure working copy. About a week ago, Chouser helped me adding type hints to avoid reflection in my functions. The warnings came back today. I started going through the different revisions of Clojure starting at r1260 and I found that the warnings (and slowness) appear starting at r1265: r1265 | richhickey | 2009-02-10 12:24:20 -0500 (Tue, 10 Feb 2009) | 1 line Changed paths: M /trunk/src/clj/clojure/core.clj added inlining on remaining coercions I have created a small demo program with my functions to show the difference. Here is the program and the output with r1264 and r1265. (set! *warn-on-reflection* true) (ns slowdemo (:import [java.nio ByteBuffer])) (defn get-byte [#^ByteBuffer buf] (let [x (byte (.get buf))] (short (bit-and x 0xff (defn get-short [#^ByteBuffer buf] (let [x (short (.getShort buf))] (int (bit-and x 0x (defn buf [] (ByteBuffer/wrap (into-array Byte/TYPE (map byte (range 256) (println get-byte) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 256] (get-byte b) (println get-short) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 128] (get-short b) $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj get-byte Elapsed time: 308.339245 msecs get-short Elapsed time: 188.635614 msecs real: 3.946s; user: 2.720s; sys: 1.064s; CPU: 95.89% $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj Reflection warning, line: 9 - call to and can't be resolved. Reflection warning, line: 14 - call to and can't be resolved. get-byte Elapsed time: 2765.621864 msecs get-short Elapsed time: 1134.288161 msecs real: 7.400s; user: 4.928s; sys: 2.196s; CPU: 96.27% --~--~-~--~~~---~--~~ 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: with-local-vars vs. let
Have a look at compojure - a good example of with-local-vars is where a servlet request is executed. Each (get, post) request occurs in its entirety on a single (jetty or tomcat) thread. The compojure call to the application service function binds the http headers, servlet request parameters, etc, using with-local-vars and then calls the app function. These values are all then in scope for the called service function _and_ any functions that it in turn calls. This is all safe without using refs/atoms as the values are all local-thread bound. Here's an application example... (declare *locs*) (declare my-service) (def my-servlet (proxy [HttpServlet] [] (service [request response] (binding [*locs* {:basedir .}] (my-service this request response) (defservice my- ; this is a compojure macro defining my-service (ANY * (var-set (var *locs*) (authenticate cookies request)) (if (nil? (:usr *locs*)) (frm-login No session) :next)) (GET /logged-in-app-call ... Here we declare *locs* as an unbound var in the namespace. Then my-servlet proxies the servlet class and the compojure service call has all the headers, etc bound in with-local-vars. Then for app purposes, we bind *locs* to some default app related stuff before the call to my-service. Then in my-service, the first thing we do is to authenticate the user using a cookie's information (cookies are local thread bound). Authentication then adds {:usr credentials or nil} to whatever was in *locs* and returns the new map. Var-set updates *locs* and either a login page is invoked or we drop through (:next) to the matching app path. All app functions then have access to the *locs* map and can use the :usr credentials, default stuff, etc. A bit contrived from the actual app and a bit complex to explain, but local vars are very useful in this situation. Regards, Adrian. On Fri, Feb 13, 2009 at 3:10 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: On Feb 13, 2009, at 13:31, Mark Volkmann wrote: What are some reasons to use with-local-vars instead of let or binding? Let just creates bindings for a lexical scope. They cannot be modified at all. Binding and with-local-vars deal with vars, i.e. mutable references. Binding creates a dynamic scope for already existing vars that are accessible in some namespace. With-local-vars also creates a dynamic scope, but for newly created anonymous vars. So far for the theory. I have to admit that in my own experience, every time I considered using with-local-vars, I ended up realising that what I really wanted is atoms or refs. Which means that I cannot cite a use case for with-local-vars. I scanned through the source code of clojure and clojure-contrib to see if with-local-vars is used anywhere at all, but the answer is no. 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: generated class with overloaded methods
Laurent PETIT a écrit : 2009/2/13 Christophe Grand christo...@cgrand.net mailto:christo...@cgrand.net Laurent PETIT a écrit : Hello, Thanks for having shared that, Do you know if there's a way to overload methods with the same arity, then ? I'm thinking about .read(char ) .read(byte ) .read(String ) .read(Integer ) ... for example, ? Create functions named -read-char -read-byte -read-String -read-Integer. Is it documented ? I can't find a reference to it. The documentation says: At runtime, a call to some method foo of the generated class will find the current value of the var implementing.namespace/prefixfoo and call it. The truth is that a call to some method foo will first try to find the current value of the var implementing.namespace/prefixfoo-arg1SimpleTypeName-arg2SimpleTypeName-... (or implementing.namespace/prefixfoo-void if no args) and if this current value is null, it will fallback to implementing.namespace/prefixfoo. Christophe --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
??? 2009/2/13 Craig McDaniel craig...@gmail.com I just tried it out to be sure. Overloaded methods with the same arity work as expected. Clojure picks the right method to call via reflection. package expmeth; public class ClassA { public void hello() { System.err.println(hello from Java!); } public void hello(int x) { System.err.println(hello from Java. int: + x); } public void hello(String x) { System.err.println(hello from Java. string: + x); } } (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello ([this] (.helloSuper this) (println hello from clojure!)) ([this x] (.helloSuper this x) (println hello from clojure... x))) --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
Christophe, you're right. I tried it and that method also works. I didn't know about that secret feature. (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello [this] (.helloSuper this) (println hello from clojure!)) (defn -hello-String [this x] (.helloSuper this x) (println hello-String from clojure x)) (defn -hello-int [this x] (.helloSuper this x) (println hello-int from clojure... x)) --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
Thanks Christophe, that's the answer I was hoping to get, If I was twenty years younger, I would just say Clojure roxxXXooRR :-) (well, I think this is supposed to say that clojure is really cool, hope I didn't misunderstood the rooxxXXooRR thing :-) -- Laurent 2009/2/13 Christophe Grand christo...@cgrand.net Laurent PETIT a écrit : 2009/2/13 Christophe Grand christo...@cgrand.net mailto:christo...@cgrand.net Laurent PETIT a écrit : Hello, Thanks for having shared that, Do you know if there's a way to overload methods with the same arity, then ? I'm thinking about .read(char ) .read(byte ) .read(String ) .read(Integer ) ... for example, ? Create functions named -read-char -read-byte -read-String -read-Integer. Is it documented ? I can't find a reference to it. The documentation says: At runtime, a call to some method foo of the generated class will find the current value of the var implementing.namespace/prefixfoo and call it. The truth is that a call to some method foo will first try to find the current value of the var implementing.namespace/prefixfoo-arg1SimpleTypeName-arg2SimpleTypeName-... (or implementing.namespace/prefixfoo-void if no args) and if this current value is null, it will fallback to implementing.namespace/prefixfoo. Christophe --~--~-~--~~~---~--~~ 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: Reflection warnings starting at r1265
On Feb 13, 9:06 am, Vincent Foley vfo...@gmail.com wrote: Should I add this to the list of issues in the Google Code tracker? No. Those hints were suspect to begin with. .get returns a byte already, and .getShort a short, so those hints shouldn't do anything useful. Similarly, coercing to primitive on return doesn't help much as the result is always boxed. The code should have been: (defn get-byte [#^ByteBuffer buf] (let [x (int (.get buf))] (bit-and x 0xff))) (defn get-short [#^ByteBuffer buf] (let [x (int (.getShort buf))] (bit-and x 0x but there weren't inline conversions from byte/short/char to int. I've added them in SVN 1279. get-byte Elapsed time: 13.051 msecs get-short Elapsed time: 10.747 msecs Thanks for the report. Rich On Feb 12, 4:15 pm, Vincent Foley vfo...@gmail.com wrote: Hello, I was surprised today to see that my Starcraft replay program became slower when I updated my Clojure working copy. About a week ago, Chouser helped me adding type hints to avoid reflection in my functions. The warnings came back today. I started going through the different revisions of Clojure starting at r1260 and I found that the warnings (and slowness) appear starting at r1265: r1265 | richhickey | 2009-02-10 12:24:20 -0500 (Tue, 10 Feb 2009) | 1 line Changed paths: M /trunk/src/clj/clojure/core.clj added inlining on remaining coercions I have created a small demo program with my functions to show the difference. Here is the program and the output with r1264 and r1265. (set! *warn-on-reflection* true) (ns slowdemo (:import [java.nio ByteBuffer])) (defn get-byte [#^ByteBuffer buf] (let [x (byte (.get buf))] (short (bit-and x 0xff (defn get-short [#^ByteBuffer buf] (let [x (short (.getShort buf))] (int (bit-and x 0x (defn buf [] (ByteBuffer/wrap (into-array Byte/TYPE (map byte (range 256) (println get-byte) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 256] (get-byte b) (println get-short) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 128] (get-short b) $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj get-byte Elapsed time: 308.339245 msecs get-short Elapsed time: 188.635614 msecs real: 3.946s; user: 2.720s; sys: 1.064s; CPU: 95.89% $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj Reflection warning, line: 9 - call to and can't be resolved. Reflection warning, line: 14 - call to and can't be resolved. get-byte Elapsed time: 2765.621864 msecs get-short Elapsed time: 1134.288161 msecs real: 7.400s; user: 4.928s; sys: 2.196s; CPU: 96.27% --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
Hello , Your example code below is not complete (where's helloSuper definition ?), but I think it does not answer my specific question ? Anyway, it seems that Christophe found the answer. But I don't know if we should use this knowledge, since it is not exposed as an API ? -- Laurent 2009/2/13 Craig McDaniel craig...@gmail.com I just tried it out to be sure. Overloaded methods with the same arity work as expected. Clojure picks the right method to call via reflection. package expmeth; public class ClassA { public void hello() { System.err.println(hello from Java!); } public void hello(int x) { System.err.println(hello from Java. int: + x); } public void hello(String x) { System.err.println(hello from Java. string: + x); } } (ns expmeth.TestMe (:gen-class :extends expmeth.ClassA :exposes-methods {hello helloSuper})) (defn -hello ([this] (.helloSuper this) (println hello from clojure!)) ([this x] (.helloSuper this x) (println hello from clojure... x))) --~--~-~--~~~---~--~~ 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: Issue request: RT.load's don't load if already loaded mechanism breaks :reload-all
On Feb 13, 9:04 am, Stephen C. Gilardi squee...@mac.com wrote: Rich, May I please enter an issue to track the defect that require/use's :reload-all flag is not working properly in Clojure. How does this interact with: http://code.google.com/p/clojure/issues/detail?id=3 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: loop [#^Integer c 0] vs. loop [c (int 0)] and optimization question...
On Feb 13, 5:35 am, Vincent Foley vfo...@gmail.com wrote: Dimiter, The latest revision of Clojure is r1278; are you using the Google code trunk? Vincent Thanks, Vincent! I kept wondering why I don't see any more versions, I was till on the sourceforge one. --~--~-~--~~~---~--~~ 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: Reflection warnings starting at r1265
Thanks Rich! On Feb 13, 10:01 am, Rich Hickey richhic...@gmail.com wrote: On Feb 13, 9:06 am, Vincent Foley vfo...@gmail.com wrote: Should I add this to the list of issues in the Google Code tracker? No. Those hints were suspect to begin with. .get returns a byte already, and .getShort a short, so those hints shouldn't do anything useful. Similarly, coercing to primitive on return doesn't help much as the result is always boxed. The code should have been: (defn get-byte [#^ByteBuffer buf] (let [x (int (.get buf))] (bit-and x 0xff))) (defn get-short [#^ByteBuffer buf] (let [x (int (.getShort buf))] (bit-and x 0x but there weren't inline conversions from byte/short/char to int. I've added them in SVN 1279. get-byte Elapsed time: 13.051 msecs get-short Elapsed time: 10.747 msecs Thanks for the report. Rich On Feb 12, 4:15 pm, Vincent Foley vfo...@gmail.com wrote: Hello, I was surprised today to see that my Starcraft replay program became slower when I updated my Clojure working copy. About a week ago, Chouser helped me adding type hints to avoid reflection in my functions. The warnings came back today. I started going through the different revisions of Clojure starting at r1260 and I found that the warnings (and slowness) appear starting at r1265: r1265 | richhickey | 2009-02-10 12:24:20 -0500 (Tue, 10 Feb 2009) | 1 line Changed paths: M /trunk/src/clj/clojure/core.clj added inlining on remaining coercions I have created a small demo program with my functions to show the difference. Here is the program and the output with r1264 and r1265. (set! *warn-on-reflection* true) (ns slowdemo (:import [java.nio ByteBuffer])) (defn get-byte [#^ByteBuffer buf] (let [x (byte (.get buf))] (short (bit-and x 0xff (defn get-short [#^ByteBuffer buf] (let [x (short (.getShort buf))] (int (bit-and x 0x (defn buf [] (ByteBuffer/wrap (into-array Byte/TYPE (map byte (range 256) (println get-byte) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 256] (get-byte b) (println get-short) (time (dotimes [i 100] (let [b (buf)] (dotimes [j 128] (get-short b) $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj get-byte Elapsed time: 308.339245 msecs get-short Elapsed time: 188.635614 msecs real: 3.946s; user: 2.720s; sys: 1.064s; CPU: 95.89% $ time java -server -cp $HOME/src/clojure-old/clojure.jar:. clojure.main slowdemo.clj Reflection warning, line: 9 - call to and can't be resolved. Reflection warning, line: 14 - call to and can't be resolved. get-byte Elapsed time: 2765.621864 msecs get-short Elapsed time: 1134.288161 msecs real: 7.400s; user: 4.928s; sys: 2.196s; CPU: 96.27% --~--~-~--~~~---~--~~ 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: with-local-vars vs. let
On Feb 13, 2009, at 15:35, Adrian Cuthbertson wrote: Have a look at compojure - a good example of with-local-vars is where a servlet request is executed. Each (get, post) request occurs in its entirety on a single (jetty or tomcat) thread. The compojure call to the application service function binds the http headers, servlet request parameters, etc, using with-local-vars and then calls the app function. These values are all then in scope for the called service function _and_ any functions that it in turn calls. This is all safe without using refs/atoms as the values are all local-thread bound. What I see in your example is binding, but I don't see with-local- vars anywhere. Or did I misunderstand something? 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: generated class with overloaded methods
On Feb 13, 9:59 am, Laurent PETIT laurent.pe...@gmail.com wrote: Your example code below is not complete (where's helloSuper definition ?), Yes, it is complete. See :exposes-methods under (doc gen-class). helloSuper is the exposed name for the hello method in the superclass. Clojure creates that method for you. -Craig --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
Didn't know, thank you again for this knowledge, -- laurent 2009/2/13 Craig McDaniel craig...@gmail.com On Feb 13, 9:59 am, Laurent PETIT laurent.pe...@gmail.com wrote: Your example code below is not complete (where's helloSuper definition ?), Yes, it is complete. See :exposes-methods under (doc gen-class). helloSuper is the exposed name for the hello method in the superclass. Clojure creates that method for you. -Craig --~--~-~--~~~---~--~~ 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: generated class with overloaded methods
Yes, but please note that Christophe's method also solves the problem of defining overloaded methods with different java signatures, but still same name and same arity. I still can't see how your proposed method solves this particular problem ? Regards, -- Laurent 2009/2/13 Craig McDaniel craig...@gmail.com Both my method (multi-arity) and Christophe's method (overridden method names contain arguments) do work. I tested them both with the code posted. -Craig --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: bug + patch: lazy branch take-while is broken
On Feb 12, 10:20 pm, Chouser chou...@gmail.com wrote: There's a misplaced paren in take-while in the lazy branch. Patch attached. --Chouser Fixed in SVN 1280 - thanks for the report. 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 -~--~~~~--~~--~--~---
Syslog
Has anyone done logging using syslog from clojure or java? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: A stupid beginners question about Compile
On Thu, Feb 12, 2009 at 5:09 PM, Laurent PETIT laurent.pe...@gmail.com wrote: In a nutshell (not tested, but nothing should miss, just typos if it doesn't work) : mkdir test-compile cd test-compile mkdir classes mkdir src mkdir src/echo echo (ns echo.test) (defn echo [msg] msg) src/echo/test.clj java -cp path/to/clojure.jar:src/:classes/ clojure.lang.Repl user (compile 'echo.test) echo.test user (echo.test/echo ECHHH!!!) ECHHH!!! user A classical error is to forget to put the classes/ folder in the classpath. This folder (as defined by default by the global var *compile-path*) is where clojure generates the class files, and where it the immediately tries to load them from : so it must be on the classpath. The steps above work for me. What if I have several source files with the namespace echo.test? Where do I need to put those so that all of them are compiled when I run (compile 'echo.test)? Do they need to be named specially? Maybe what I'm trying to do isn't possible. -- 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: Issue request: RT.load's don't load if already loaded mechanism breaks :reload-all
On Feb 13, 2009, at 10:12 AM, Rich Hickey wrote: On Feb 13, 9:04 am, Stephen C. Gilardi squee...@mac.com wrote: Rich, May I please enter an issue to track the defect that require/use's :reload-all flag is not working properly in Clojure. How does this interact with: http://code.google.com/p/clojure/issues/detail?id=3 I don't know enough to answer properly. Perhaps we can make it moot by fixing issue 3. I have ideas for things to try, but to test them I need to reproduce the problem that caused you to remove the throw on circular load from clojure.core/load. Here's what I tried to reproduce that problem: - restored the throw on circular load lines to clojure.core/load - compiled all of Clojure and contrib successfully - Compiled/loaded/ran this successfully from Clojure and by using hello as a java main: (ns hello (:gen-class)) (defn hello [] (prn hi)) (defn -main [] (hello)) I thought that the default of :load-impl-ns to true would trigger the problem, but it didn't. Could you please give me an example of code that triggers the undesired throw on circular load? --Steve smime.p7s Description: S/MIME cryptographic signature
Re: A stupid beginners question about Compile
2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com On Thu, Feb 12, 2009 at 5:09 PM, Laurent PETIT laurent.pe...@gmail.com wrote: In a nutshell (not tested, but nothing should miss, just typos if it doesn't work) : mkdir test-compile cd test-compile mkdir classes mkdir src mkdir src/echo echo (ns echo.test) (defn echo [msg] msg) src/echo/test.clj java -cp path/to/clojure.jar:src/:classes/ clojure.lang.Repl user (compile 'echo.test) echo.test user (echo.test/echo ECHHH!!!) ECHHH!!! user A classical error is to forget to put the classes/ folder in the classpath. This folder (as defined by default by the global var *compile-path*) is where clojure generates the class files, and where it the immediately tries to load them from : so it must be on the classpath. The steps above work for me. What if I have several source files with the namespace echo.test? Where do I need to put those so that all of them are compiled when I run (compile 'echo.test)? Do they need to be named specially? Maybe what I'm trying to do isn't possible. Hello, Normally, just one of those file will have the (ns ). Others will just be (load)ed from the ns-defining file (the one with the (ns)), and contain just (in-ns 'echo.test) at their top. Then, just sending (compile 'echo.test) will compile everything. It's now that things get a little bit much complicated. Currently, if you just modify a secondary file of ns echo.test , then sending (compile 'echo.test) will not work, because the ns-defining file has not been modified, and so it will not be recompiled (because recompilation of the secondary file of ns echo.test is a side-effect of calling 'compile on the ns-defining file). The current solution to this problem in clojuredev is a brute-force one : 'touch all files to be sure that everything gets recompiled. There is currently a discussion on providing this behaviour in a cleaner way by using a global var or :reload-all flag to (compile). Using it, you will be sure that by calling (compile 'echo.test :reload-all true) on a namespace/lib, all the files being part of the ns will be recompiled, and you will not have to use 'touch trick anymore. HTH, -- Laurent -- 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: A stupid beginners question about Compile
On Fri, Feb 13, 2009 at 10:18 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com On Thu, Feb 12, 2009 at 5:09 PM, Laurent PETIT laurent.pe...@gmail.com wrote: In a nutshell (not tested, but nothing should miss, just typos if it doesn't work) : mkdir test-compile cd test-compile mkdir classes mkdir src mkdir src/echo echo (ns echo.test) (defn echo [msg] msg) src/echo/test.clj java -cp path/to/clojure.jar:src/:classes/ clojure.lang.Repl user (compile 'echo.test) echo.test user (echo.test/echo ECHHH!!!) ECHHH!!! user A classical error is to forget to put the classes/ folder in the classpath. This folder (as defined by default by the global var *compile-path*) is where clojure generates the class files, and where it the immediately tries to load them from : so it must be on the classpath. The steps above work for me. What if I have several source files with the namespace echo.test? Where do I need to put those so that all of them are compiled when I run (compile 'echo.test)? Do they need to be named specially? Maybe what I'm trying to do isn't possible. Hello, Normally, just one of those file will have the (ns ). Others will just be (load)ed from the ns-defining file (the one with the (ns)), and contain just (in-ns 'echo.test) at their top. Ah ... I think I've seen this before. Is it a common convention to create a directory in the same location as the main source file with the same name as that source file and place the additional source files inside it? For example, you have src/echo/test.clj. Would you create the directory src/echo/test and put additional source files that have the same namespace in that directory? Then, just sending (compile 'echo.test) will compile everything. It's now that things get a little bit much complicated. Currently, if you just modify a secondary file of ns echo.test , then sending (compile 'echo.test) will not work, because the ns-defining file has not been modified, and so it will not be recompiled (because recompilation of the secondary file of ns echo.test is a side-effect of calling 'compile on the ns-defining file). The current solution to this problem in clojuredev is a brute-force one : 'touch all files to be sure that everything gets recompiled. There is currently a discussion on providing this behaviour in a cleaner way by using a global var or :reload-all flag to (compile). Using it, you will be sure that by calling (compile 'echo.test :reload-all true) on a namespace/lib, all the files being part of the ns will be recompiled, and you will not have to use 'touch trick anymore. Thanks for explaining that! -- 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: A stupid beginners question about Compile
That's really a matter of conventions. Both work, and you just have to correctly adjust the call to load : 1st layout : src/echo/test.clj src/echo/test/test-part2.clj Then you'll have (ns echo.test (:load test/test-part2) in src/echo/test.clj 2d layout: src/echo/test.clj src/echo/test-part2.clj Then you'll have (ns echo.test (:load test-part2) in src/echo/test.clj But that was not the point of my answer, though. Regards, -- Laurent 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com On Fri, Feb 13, 2009 at 10:18 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com On Thu, Feb 12, 2009 at 5:09 PM, Laurent PETIT laurent.pe...@gmail.com wrote: In a nutshell (not tested, but nothing should miss, just typos if it doesn't work) : mkdir test-compile cd test-compile mkdir classes mkdir src mkdir src/echo echo (ns echo.test) (defn echo [msg] msg) src/echo/test.clj java -cp path/to/clojure.jar:src/:classes/ clojure.lang.Repl user (compile 'echo.test) echo.test user (echo.test/echo ECHHH!!!) ECHHH!!! user A classical error is to forget to put the classes/ folder in the classpath. This folder (as defined by default by the global var *compile-path*) is where clojure generates the class files, and where it the immediately tries to load them from : so it must be on the classpath. The steps above work for me. What if I have several source files with the namespace echo.test? Where do I need to put those so that all of them are compiled when I run (compile 'echo.test)? Do they need to be named specially? Maybe what I'm trying to do isn't possible. Hello, Normally, just one of those file will have the (ns ). Others will just be (load)ed from the ns-defining file (the one with the (ns)), and contain just (in-ns 'echo.test) at their top. Ah ... I think I've seen this before. Is it a common convention to create a directory in the same location as the main source file with the same name as that source file and place the additional source files inside it? For example, you have src/echo/test.clj. Would you create the directory src/echo/test and put additional source files that have the same namespace in that directory? Then, just sending (compile 'echo.test) will compile everything. It's now that things get a little bit much complicated. Currently, if you just modify a secondary file of ns echo.test , then sending (compile 'echo.test) will not work, because the ns-defining file has not been modified, and so it will not be recompiled (because recompilation of the secondary file of ns echo.test is a side-effect of calling 'compile on the ns-defining file). The current solution to this problem in clojuredev is a brute-force one : 'touch all files to be sure that everything gets recompiled. There is currently a discussion on providing this behaviour in a cleaner way by using a global var or :reload-all flag to (compile). Using it, you will be sure that by calling (compile 'echo.test :reload-all true) on a namespace/lib, all the files being part of the ns will be recompiled, and you will not have to use 'touch trick anymore. Thanks for explaining that! -- 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: with-local-vars vs. let
What I see in your example is binding, but I don't see with-local- vars anywhere. Or did I misunderstand something? Sorry, I checked the compojure source again and the servlet headers, cookies, etc are wrapped in a with-servlet-vars macro (rather than with-local-vars) which just uses let. The html parameters are wrapped in *params* using binding rather than with-local-vars, so my example does not actually demonstrate with-local-vars, but rather just thread-local use of vars with binding. On Fri, Feb 13, 2009 at 5:19 PM, Konrad Hinsen konrad.hin...@laposte.net wrote: On Feb 13, 2009, at 15:35, Adrian Cuthbertson wrote: Have a look at compojure - a good example of with-local-vars is where a servlet request is executed. Each (get, post) request occurs in its entirety on a single (jetty or tomcat) thread. The compojure call to the application service function binds the http headers, servlet request parameters, etc, using with-local-vars and then calls the app function. These values are all then in scope for the called service function _and_ any functions that it in turn calls. This is all safe without using refs/atoms as the values are all local-thread bound. What I see in your example is binding, but I don't see with-local- vars anywhere. Or did I misunderstand something? 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 -~--~~~~--~~--~--~---
Useful memory profiling tool
Determining exactly how much memory objects are using is often desirable, especially since one of Clojure's few flaws (which is the JVM's fault, mostly) is that it can be fairly memory-hungry. So, I took the techniques described in http://www.javaworld.com/javaworld/javatips/jw-javatip130.html, and wrote a Clojure script that does basically the same thing. I have uploaded it to the files section, under sizeof.clj Read that article for how it works.The only thing I do different is that instead of specifying a class,you pass it a method that returns the object you want to measure. So, for example: user (sizeof/sizeof #(new Object)) 8 ;;the size of a java.lang.Object. user (sizeof/sizeof #(new Double 1.0001)) 16 ;;the size of a java.lang.Double user (sizeof/sizeof #(let [num (new Double 1.0001)] (fn [] (* num 10 32 ;;the size of a closure closing over a double There is alternative form of sizeof that takes a second parameter, which specifies how many times to run save the results. Larger numbers are by far more accurate, it defaults to 10,000. But if you want to check the size of the result from a function that might return something really huge, I provide this so that you can lower the count and run tests on megabyte-scale objects without causing an OutOfMemory exception. A few caveats: 1. This is only an estimate, not a guarentee. You may occasionally get a fluke result if the JVM does something weird. 2. You can, and will, get different results on different JVMs, particularly 64 bit vs 32 bit. 3. The JVM does clever optimizations that save space, but can make benchmarking difficult. For example, if you want to find how much space a five-character string takes, you might try the following: user (sizeof/sizeof #(str 12345)) 0 Something odd happened! The JVM must have detected a constant and optimized it in a string table, or something of the sort. But if we try: user (sizeof/sizeof #(str 1 2 3 4 5)) 48 We get something more believable. 4. If there is anything running in a separate thread in the same JVM, it can mess things up. 5. If the provided function has side effects, it will provide inaccurate results. Anyway, I hope it's useful. --~--~-~--~~~---~--~~ 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: More Swing Examples
http://clojure.googlegroups.com/web/2c-calculator.clj?gda=GfxNgEMAAAC2LrkjeC7f10uHiY7GOiyxomoTIbx5E_ZvCUIqi7LhkTsFONunm7BW3wPdbl53QhAytiJ-HdGYYcPi_09pl8N7FWLveOaWjzbYnpnkpmxcWg http://www.plt1.com/1070/even-smaller-snake/ --~--~-~--~~~---~--~~ 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: A stupid beginners question about Compile
I wonder what the rationale was for making it so namespaces need to be quoted when using in-ns. They don't need to be quoted when using ns. For example, I have (ns com.ociweb.talk (:gen-class)) in one file and (in-ns 'com.ociweb.talk) in another. I guess this is because it's conceivable one might want to use in-ns with a variable, but that's not the case with ns. That's certainly in the right ballpark. There was some discussion I saw recently of changing in-ns/require/use/refer into macros that accept unquoted names for the namespaces they deal with. The need for occasional use with evaluated symbols could be addressed by providing in-ns*, require*, use*, refer* as corresponding functions. I'm in favor of that change. I would also like to see :load take symbols (in addition to strings) as arguments especially now that the strings it takes no longer include a suffix. The usual .-/ and --_ translations would apply. (ns foo (:load foo.bar foo.baz foo.quux)) and then of course, the prefix list convenience: (ns foo (:load (foo bar baz quux)) --Steve smime.p7s Description: S/MIME cryptographic signature
Re: A stupid beginners question about Compile
2009/2/13 Stephen C. Gilardi squee...@mac.com I wonder what the rationale was for making it so namespaces need to be quoted when using in-ns. They don't need to be quoted when using ns. For example, I have (ns com.ociweb.talk (:gen-class)) in one file and (in-ns 'com.ociweb.talk) in another. I guess this is because it's conceivable one might want to use in-ns with a variable, but that's not the case with ns. That's certainly in the right ballpark. There was some discussion I saw recently of changing in-ns/require/use/refer into macros that accept unquoted names for the namespaces they deal with. The need for occasional use with evaluated symbols could be addressed by providing in-ns*, require*, use*, refer* as corresponding functions. I'm in favor of that change. I would also like to see :load take symbols (in addition to strings) as arguments especially now that the strings it takes no longer include a suffix. The usual .-/ and --_ translations would apply. (ns foo (:load foo.bar foo.baz foo.quux)) and then of course, the prefix list convenience: (ns foo (:load (foo bar baz quux)) Yes, and the prefix list convenience would also solve Stephen's problem with the violation of the DRY principle in this area :-) -- Laurent --~--~-~--~~~---~--~~ 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 Clojure functions from Java
On Fri, Feb 13, 2009 at 11:19 AM, Laurent PETIT laurent.pe...@gmail.com wrote: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com Can someone point me to documentation on how to invoke Clojure functions from Java? Thanks! That's interesting, but what I really want to do is call Clojure functions that have already been compiled into .class files from Java. Have you seen an example of that anywhere? I don't see it on that page. -- 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: Questions about the Enlive template library
Hi Christophe, I was not on the latest version (and I now know that the download button on github does not necessarily give you the latest!). I am now seeing the differences in output on descendent updates. I understand about only one rule being applied, and the warning definitely helps to see this more obviously. Part of me is thinking about the possibility of chaining templates together for multiple transformations, but that's just my mind wandering and not a real problem at the moment. (besides, my eyes tend to glaze over when the topic of compile-time versus runtime comes up ;) I still have to test out the selector updates as well as snippets. Thanks for getting these changes in so quickly! I hope to have some more feedback for you on Monday. Cheers, Tom On Feb 13, 4:36 am, Christophe Grand christo...@cgrand.net wrote: Hi Tom, Tom Hickey a écrit : Snippets I think what you have suggested for snippets sounds perfect. I added defsnippet and defsnippets. Setting content escaping Thanks you for explaining the cases here. Having a better idea of what to expect will help in testing further. (I'm still trying to wrap my head around when I need to unquote or not.) You need to unquote to pass the matched element to a template-macro (at, show, set-attr, remove-attr, text, do-, xhtml-strict and select) but at the top level of the right hand form of a rule. Before I move on to the next section (which gets quite long) I had a quick question: How do I get/use an elements content? Say for instance I wanted a rule for all a tags that wrapped their content in an additional span so a href=blahmy link text/a would become a href=blahspanmy link text/span/a, how would I accomplish this? (I have a feeling I'm missing something obvious again like I did with set-attr!) You aren't missing anything, there's nothing like jQuery.wrap. But you can easily define your own template-macro: (html/deftemplate-macro wrap [xml tag attrs] {:tag tag :attrs (apply hash-map attrs) :content [xml]}) usage: (deftemplate wrap-links net/cgrand/enlive_html/example_links.html [] [:a] (wrap :span :title wrapper)) user= (apply str (wrap-links)) htmlbodyul lispan title=\wrapper\a href=\http://www.google.com\;google/a/span/li lispan title=\wrapper\a href=\http://www.cnn.com\; class=\news\cnn/a/span/li li class=\last\span title=\wrapper\a href=\http://www.apple.com\;apple/a/span span title=\wrapper\a href=\http://store.apple.com\; class=\store\apple store/a/span/li /ul/body/html Selector specificity I have an example below with a number of permutations but they show that any time an ancestor is updated in the hierarchy, no rules for decedents are applied (whether before or after). And also that once an element is updated, no further rule will be applied to it. Hmm, currently only one rule is applied per element BUT rules are applied on descendants before the update of the ancestor. Are you using an old version of Enlive? The current restriction of only one update per element can certainly be relaxed if I found a good policy for handling conflicting updates. Meanwhile, I added warnings (they can be disabled by setting *warn-on-rule-collision* to false): user= (deftemplate update-links2 net/cgrand/enlive_html/example_links.html [] [:.last :.store] (html/set-attr :type store) [:a] (html/set-attr :title links rock!)) Rule collision at: {:tag :a, :attrs {:hrefhttp://store.apple.com, :class store}, :content [apple store]} between: (html/set-attr :type store) (html/set-attr :title links rock!) #'user/update-links2 In my opinion, it would be great to have rules applied in the order they appear and that rules applied later would see all previous changes to the tree and could find/manipulate/update those elements as desired. Enlive is not that dynamic: the tree is modified and serialized at compile-time hence you can not see the result of changes depending on runtime data. Here is the output: net.cgrand.enlive-html.examples/ (apply str (update-links1)) htmlbodyullia title=\links rock!\ href=\http:// www.google.com\google/a/lilia title=\links rock!\ href= \http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a href=\http://www.apple.com\;apple/aa href= \http://store.apple.com\; class=\store\apple store/a/li/ul/ body/html It should work (descendants should be updates) on my box I get: user= (apply str (update-links1)) htmlbodyullia title=\links rock!\ href=\http://www.google.com\;google/a/lilia title=\links rock!\ href=\http://www.cnn.com\; class=\news\cnn/a/lili last=\true\ class=\last\a title=\links rock!\ href=\http://www.apple.com\;apple/aa title=\links rock!\ href=\http://store.apple.com\; class=\store\apple store/a/li/ul/body/html net.cgrand.enlive-html.examples/ (apply str (update-links2)) htmlbodyullia title=\links rock!\ href=\http:// www.google.com\google/a/lilia title=\links rock!\
eliminating uses of nil punning
In the lazy branch, empty sequences don't always evaluate as false in a boolean context. Tracking down places you've made this assumption can be hard. Attached is a patch that helps by providing a flag, assert-if-lazy-seq. When this flag is on, 'if' is replaced with a new (slower) version that throws an exception if you're using a lazy-seq as the test expression. This is almost always an error in the lazy branch, and usually just requires wrapping the lazy-seq in a call to 'seq', as has been discussed elsewhere. To turn on the flag you need to rebuild clojure with an extra option, like this: ant -Dclojure.assert-if-lazy-seq=please Any non-empty string will do for the value. You will need to set the value at runtime as well. There may be a way to avoid this, but I haven't thought of how. So for now you'll want at the top of your code: (reset! *assert-if-lazy-seq* true) Now anytime you try to use nil punning, you should get an exception. user= (when (filter neg? [1 2]) :all-pos) java.lang.Exception: LazySeq used in 'if' (NO_SOURCE_FILE:0) user= (not (concat)) java.lang.Exception: LazySeq used in 'if' (NO_SOURCE_FILE:0) --Chouser --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- commit b0cec18fb925510502352d8fdcc0a4b93b28bd72 Author: Chouser chou...@n01se.net Date: Fri Feb 13 13:02:30 2009 -0500 Add assert-if-lazy-seq diff --git a/branches/lazy/build.xml b/branches/lazy/build.xml index 04583ba..bc5fcc7 100644 --- a/branches/lazy/build.xml +++ b/branches/lazy/build.xml @@ -11,6 +11,7 @@ property name=build location=classes/ property name=clojure_jar location=clojure.jar/ property name=slim_jar location=clojure-slim.jar/ + property name=clojure.assert-if-lazy-seq value=/ target name=init depends=clean tstamp/ @@ -28,6 +29,7 @@ java classname=clojure.lang.Compile classpath=${build}:${cljsrc} sysproperty key=clojure.compile.path value=${build}/ + sysproperty key=clojure.assert-if-lazy-seq value=${clojure.assert-if-lazy-seq}/ arg value=clojure.core/ arg value=clojure.main/ arg value=clojure.set/ diff --git a/branches/lazy/src/clj/clojure/core.clj b/branches/lazy/src/clj/clojure/core.clj index eb31005..8f2ec15 100644 --- a/branches/lazy/src/clj/clojure/core.clj +++ b/branches/lazy/src/clj/clojure/core.clj @@ -36,6 +36,10 @@ fn (fn* fn [ decl] (cons 'fn* decl))) (def + #^{:macro true} + if (fn* if [ decl] (cons 'if* decl))) + +(def #^{:arglists '([coll]) :doc Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.} @@ -291,6 +295,19 @@ (. (var defmacro) (setMacro)) +(def *assert-if-lazy-seq* + (let [x (System/getProperty clojure.assert-if-lazy-seq)] +(new clojure.lang.Atom (if x (if (.isEmpty x) false true) + +(defmacro if [tst etc] + (if* (.get *assert-if-lazy-seq*) +(let [tstsym 'no-gensym-for-me] + (list 'let [tstsym tst] + (list 'if* (list 'instance? clojure.lang.LazySeq tstsym) + (list 'throw (list 'new Exception LazySeq used in 'if')) + (cons 'if* (cons tstsym etc) +(cons 'if* (cons tst etc + (defmacro when Evaluates test. If logical true, evaluates body in an implicit do. [test body] @@ -1642,7 +1659,7 @@ ([coll] (sort compare coll)) ([#^java.util.Comparator comp coll] - (when (and coll (not (zero? (count coll + (when (seq coll) (let [a (to-array coll)] (. java.util.Arrays (sort a comp)) (seq a) diff --git a/branches/lazy/src/clj/clojure/core_proxy.clj b/branches/lazy/src/clj/clojure/core_proxy.clj index 8517e23..edbc78f 100644 --- a/branches/lazy/src/clj/clojure/core_proxy.clj +++ b/branches/lazy/src/clj/clojure/core_proxy.clj @@ -155,7 +155,7 @@ meths (concat (seq (. c (getDeclaredMethods))) (seq (. c (getMethods] -(if meths +(if (seq meths) (let [#^java.lang.reflect.Method meth (first meths) mods (. meth (getModifiers)) mk (method-sig meth)] diff --git a/branches/lazy/src/jvm/clojure/lang/Compiler.java b/branches/lazy/src/jvm/clojure/lang/Compiler.java index 664045f..b29876f 100644 --- a/branches/lazy/src/jvm/clojure/lang/Compiler.java +++ b/branches/lazy/src/jvm/clojure/lang/Compiler.java @@ -40,7 +40,7 @@ public class Compiler implements Opcodes{ static final Symbol DEF = Symbol.create(def); static final Symbol LOOP =
Re: calling Clojure functions from Java
Mark, If you use the #^{:static true} metadata on a :methods definition in a gen-class spec for your class' implementing namespace, then those fns appear as static functions in the generated Java class: Clojure: (ns bar.Foo (:gen-class :methods [#^{:static true} [stringLength [String] int]])) (defn -stringLength [s] (.length s)) -- compile, then in Java: bar.Foo.stringLength(blah) = 4 You can use this to gracefully expose clojure fns as Java static methods (e.g. the implementation of -stringLength above could just delegate to a more idiomatically-named clojure fn like string-length so that the fn can be pleasantly accessed by clojure and Java clients). Of course, you can access instance methods of classes written in clojure as well, but that requires also adding a constructor spec to :gen-class and tracking whatever state is appropriate for the class/method in question. - Chas On Feb 13, 2009, at 12:29 PM, Mark Volkmann wrote: On Fri, Feb 13, 2009 at 11:19 AM, Laurent PETIT laurent.pe...@gmail.com wrote: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com Can someone point me to documentation on how to invoke Clojure functions from Java? Thanks! That's interesting, but what I really want to do is call Clojure functions that have already been compiled into .class files from Java. Have you seen an example of that anywhere? I don't see it on that page. -- 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: calling Clojure functions from Java
Mark, In case you were asking how to call a Clojure function from Java without wrapping it, check out clojure.lang.IFn and AFn. For example, say you prefer to write a class in Java but need to accept a Clojure fn as an argument in one of the class methods: public int callFromClojure(IFn clojureFn) { ... Object result = clojureFn.invoke(arg1, arg2); ... } That's just a rough example and IFn may not be the correct abstraction to use. -Matt On Feb 13, 2009, at 2:19 PM, Chas Emerick wrote: Mark, If you use the #^{:static true} metadata on a :methods definition in a gen-class spec for your class' implementing namespace, then those fns appear as static functions in the generated Java class: Clojure: (ns bar.Foo (:gen-class :methods [#^{:static true} [stringLength [String] int]])) (defn -stringLength [s] (.length s)) -- compile, then in Java: bar.Foo.stringLength(blah) = 4 You can use this to gracefully expose clojure fns as Java static methods (e.g. the implementation of -stringLength above could just delegate to a more idiomatically-named clojure fn like string-length so that the fn can be pleasantly accessed by clojure and Java clients). Of course, you can access instance methods of classes written in clojure as well, but that requires also adding a constructor spec to :gen-class and tracking whatever state is appropriate for the class/method in question. - Chas On Feb 13, 2009, at 12:29 PM, Mark Volkmann wrote: On Fri, Feb 13, 2009 at 11:19 AM, Laurent PETIT laurent.pe...@gmail.com wrote: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java 2009/2/13 Mark Volkmann r.mark.volkm...@gmail.com Can someone point me to documentation on how to invoke Clojure functions from Java? Thanks! That's interesting, but what I really want to do is call Clojure functions that have already been compiled into .class files from Java. Have you seen an example of that anywhere? I don't see it on that page. -- 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 -~--~~~~--~~--~--~---
cljc?
Is there a reason why it would be inadvisable or particularly difficult to create a cljc script, short for Clojure compile, that would take a path to a Clojure source file and compile it to .class files? It seems tedious to have to add :gen-class to the source file, start a REPL, and enter a compile form. -- 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: cljc?
On Feb 13, 2009, at 3:47 PM, Mark Volkmann wrote: Is there a reason why it would be inadvisable or particularly difficult to create a cljc script, short for Clojure compile, that would take a path to a Clojure source file and compile it to .class files? It seems tedious to have to add :gen-class to the source file, start a REPL, and enter a compile form. The requirement that the destination dir exist and be in classpath at the time you launch the Clojure instance that does the compiling makes it a little difficult. It means you can't create the target, add it to classpath, and compile all in one Clojure instance. Should be a show- stopper though. I don't see any reason why it would be inadvisable. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: cljc?
On Fri, Feb 13, 2009 at 3:00 PM, Stephen C. Gilardi squee...@mac.com wrote: On Feb 13, 2009, at 3:47 PM, Mark Volkmann wrote: Is there a reason why it would be inadvisable or particularly difficult to create a cljc script, short for Clojure compile, that would take a path to a Clojure source file and compile it to .class files? It seems tedious to have to add :gen-class to the source file, start a REPL, and enter a compile form. The requirement that the destination dir exist and be in classpath at the time you launch the Clojure instance that does the compiling makes it a little difficult. It means you can't create the target, add it to classpath, and compile all in one Clojure instance. Should be a show-stopper though. I don't see any reason why it would be inadvisable. As far as I know, the classpath only needs clojure.jar, the src directory and the classes directory. Here's an idea. The locations of those could be command-line arguments to the cljc script. They could default to simply src and classes relative to the current directory. clojure.jar could be located via an environment variable like CLOJURE_HOME. Is there still a reason the compile can't be done in a single Clojure instances? -- 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: cljc?
It would perhaps be a lot more inefficient. From what I can understand, clojure loads the namespace in question and the actual command to the compiler is write this namespace to here. It checks symbols from other modules and does a very light sort of link step. This requires knowledge of other modules; something that can be gathered once and used repeatedly if the whole system is loaded once. I think Clojure's compile step is a long way beyond the single file compile system; whereas c++ moved into precompiled headers and lots of other nonsense, clojure just loads the system as it needs it and then writes out what you request written out. Is this an accurate characterization of the situation? Chris On Feb 13, 2:10 pm, Mark Volkmann r.mark.volkm...@gmail.com wrote: On Fri, Feb 13, 2009 at 3:00 PM, Stephen C. Gilardi squee...@mac.com wrote: On Feb 13, 2009, at 3:47 PM, Mark Volkmann wrote: Is there a reason why it would be inadvisable or particularly difficult to create a cljc script, short for Clojure compile, that would take a path to a Clojure source file and compile it to .class files? It seems tedious to have to add :gen-class to the source file, start a REPL, and enter a compile form. The requirement that the destination dir exist and be in classpath at the time you launch the Clojure instance that does the compiling makes it a little difficult. It means you can't create the target, add it to classpath, and compile all in one Clojure instance. Should be a show-stopper though. I don't see any reason why it would be inadvisable. As far as I know, the classpath only needs clojure.jar, the src directory and the classes directory. Here's an idea. The locations of those could be command-line arguments to the cljc script. They could default to simply src and classes relative to the current directory. clojure.jar could be located via an environment variable like CLOJURE_HOME. Is there still a reason the compile can't be done in a single Clojure instances? -- 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: A Clojure documentation browser
Please consider whether or not you'd like to send in a Contributor Agreement to enable that. If you hurry you could become the first registered Clojure contributor whose last name begins with A. :-) (clojure.org/contributing) OK, I've added the things I want to add, and sent in the agreement, which will probably make it to Rich next week. The code is on github [1] - if you want it somewhere else, let me know. I assume someone other than me will be committing it to Subversion, but if I'm wrong let me know. One other question: I don't monitor this list very closely at the moment, so what's the mechanism for me to hear about bugs? [1] http://github.com/candera/doc-browse/blob/master/gen_html_docs.clj --~--~-~--~~~---~--~~ 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: My SLIME installation diary
I have a small problem with clojure-mode in your setup. Since clojure-mode is autoloaded, it, and SLIME, aren't available until I load a '.clj' file. Starting SLIME, though, doesn't add the SLIME menu to the previously loaded '.clj' buffer (Newly loaded files get the menu, as they should). Thanks, -dms On Feb 12, 12:35 pm, Phil Hagelberg p...@hagelb.org wrote: bOR_ boris.sch...@gmail.com writes: (push /home/boris/.emacs.d load-path) This is actually already on the load-path by default; no need to add it. Standard load-path on ubuntu didn't include ~/.emacs.d for me. Not sure why not. You're right; my bad. 1. Creating a .emacs with the load-path .emacs.d 2. Downloading clojure-mode.el 3. replacing git:// with http:// to get past my proxy 4. The slime git kept failing (stalled somewhere near the end of downloading), so I removed that line from clojure-mode.el and installed a snapshot of slime myself. 5. The clojure git failed as well, I replaced it with the svn checkouthttp://clojure.googlecode.com/svn/trunk/clojure; in clojure- mode.el I can't reproduce these download problems... Has anyone else had trouble with these URLs? I think perhaps the best thing to do with the failing gits (for whatever reason) is to just let the script skip the downloading of new checkouts if an old checkout is present, and to let it give a message like this: Failed to checkout slime, please do so manually, install in ~/src and rerun M-x clojure-install. Yeah, not a bad idea. 1. It can't find M-x slime clojure-slime-config doesn't seem to be an option either to manually run with M-x clojuretab clojure-slime-config is a function, but it's not a command, so you can't invoke it via M-x. It should only be invoked from your .emacs file. I suspect you're missing the autoload that it mentions in the clojure-mode.el header: ;; (autoload 'clojure-mode clojure-mode A major mode for Clojure t) ;; (add-to-list 'auto-mode-alist '(\\.clj$ . clojure-mode)) That should go in your .emacs file. I should have mentioned that if you don't already have an Emacs config, you could try the Emacs Starter Kit, where clojure-mode is already installed for you. (You would still have to install Clojure though.) But the autoloads are all set up for you. http://github.com/technomancy/emacs-starter-kit (setq swank-clojure-jar-path (concat clojure-src-root /clojure/clojure.jar) swank-clojure-extra-classpaths (list (concat clojure-src-root /contrib/src/ This isn't right according to the default installation, but if you checked things out manually it could be different. -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: My SLIME installation diary
David dsieg...@yahoo.com writes: I have a small problem with clojure-mode in your setup. Since clojure-mode is autoloaded, it, and SLIME, aren't available until I load a '.clj' file. Starting SLIME, though, doesn't add the SLIME menu to the previously loaded '.clj' buffer (Newly loaded files get the menu, as they should). Yeah, I've thought about a hook that runs after SLIME loads to activate slime-mode for all pre-existing clojure-mode buffers; just haven't gotten around to it. If you're handy with elisp, I'd love a patch, otherwise I'll get around to it eventually. =) -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: cljc?
On Feb 13, 2009, at 4:10 PM, Mark Volkmann wrote: As far as I know, the classpath only needs clojure.jar, the src directory and the classes directory. Here's an idea. The locations of those could be command-line arguments to the cljc script. They could default to simply src and classes relative to the current directory. clojure.jar could be located via an environment variable like CLOJURE_HOME. Is there still a reason the compile can't be done in a single Clojure instances? If you don't mind your script depending on classes already existing, you can use one instance. In the general case, a complete cljc program (in my opinion) would need to: [1] create the dest dir if it doesn't already exist [2] launch a clojure instance with that dest dir in classpath [3] compile What doesn't work is: [1] Launch a clojure instance to run your script [2] create the dest dir using that clojure instance [3] compile using that clojure instance It's step 1 of the general case that has to be done outside of the clojure instance that does the compiling. That implies it's done by something else (e.g., bash, python, perl, C) or it's done by a separate instance of Clojure. Alternatively, if you want to use only one instance of Clojure, you could simply check if the directory exists and exit with a that dir doesn't exist message if it doesn't. --Steve smime.p7s Description: S/MIME cryptographic signature
run clojure on 5,832 cores?
http://sicortex.com/products --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: run clojure on 5,832 cores?
I see no mention of a JVM being available for those CPUs, but perhaps the no-asm HotSpot can be build with gcc on it. Otherwise, cool gear :) On Fri, Feb 13, 2009 at 11:47 PM, Raoul Duke rao...@gmail.com wrote: http://sicortex.com/products -- Venlig hilsen / Kind regards, Christian Vest Hansen. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: A Clojure documentation browser
Hi Craig, On Feb 13, 2009, at 4:21 PM, Craig Andera wrote: OK, I've added the things I want to add, and sent in the agreement, which will probably make it to Rich next week. The code is on github [1] - if you want it somewhere else, let me know. I assume someone other than me will be committing it to Subversion, but if I'm wrong let me know. One other question: I don't monitor this list very closely at the moment, so what's the mechanism for me to hear about bugs? [1] http://github.com/candera/doc-browse/blob/master/gen_html_docs.clj Sounds good, thanks! Github is fine. Once I see your name on clojure.org/contributing, I'll commit this to clojure.contrib. For changes going forward, once you're happy with some update on github, just let me know and I'll pull it into contrib. For bug reporting, I recommend you add a section to the comments at the top of the file letting folks know how you'd like to be contacted for that. If I see a question or issue raised and it looks like you're not aware, I'll also give you a heads up. I just did a run and I like the new output! Thanks, --Steve smime.p7s Description: S/MIME cryptographic signature
Re: run clojure on 5,832 cores?
On Feb 13, 6:13 pm, Christian Vest Hansen karmazi...@gmail.com wrote: I see no mention of a JVM being available for those CPUs, but perhaps the no-asm HotSpot can be build with gcc on it. Looks like they run Linux, so it would probably be possible. This article http://www.networkworld.com/news/2009/020509-sicortex.html says they use slower, cheaper processors that work best when you're doing lots of small computations in parallel. The part I get excited about is the 8 TB of memory. When can I get THAT on my desk? -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 -~--~~~~--~~--~--~---
New mod code is breaking the contrib unit tests
I just updated, and the unit tests for mod are breaking. It looks like the new mod only works for ints. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
how to emulate lisp's labels functionality?
Hi, do we have labels equiv. in clojure? The code below is from OnLisp. Trying to convert to clj file, but have minor difficulties. (defun count-instances (obj lsts) (labels ((instances-in (lst) (if (consp lst) (+ (if (eq (car lst) obj) 1 0) (instances-in (cdr lst))) 0))) (mapcar #’instances-in lsts))) (count-instances ’a ’((a b c) (d a r p a) (d a r) (a a))) (1 2 1 2) thanks sun --~--~-~--~~~---~--~~ 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: how to emulate lisp's labels functionality?
wubbie sunj...@gmail.com writes: Hi, do we have labels equiv. in clojure? The code below is from OnLisp. Trying to convert to clj file, but have minor difficulties. You can use let since variables and functions are kept in the same namespace. (defun count-instances (obj lsts) (labels ((instances-in (lst) (if (consp lst) (+ (if (eq (car lst) obj) 1 0) (instances-in (cdr lst))) 0))) (mapcar #’instances-in lsts))) ...becomes... (defn count-instances [obj lsts] (let [instances-in (fn [lst] (if (cons? lst) (+ (if (= (first lst) obj) 1 0) (instances-in (rest lst))) 0))] (map instances-in lsts))) This is a pretty direct translation; you could make it more idiomatic in other ways; I'm just trying to compare let to labels. -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: how to emulate lisp's labels functionality?
On Fri, Feb 13, 2009 at 8:01 PM, Phil Hagelberg p...@hagelb.org wrote: wubbie sunj...@gmail.com writes: Hi, do we have labels equiv. in clojure? The code below is from OnLisp. Trying to convert to clj file, but have minor difficulties. You can use let since variables and functions are kept in the same namespace. This is true, but this... (defn count-instances [obj lsts] (let [instances-in (fn [lst] (if (cons? lst) (+ (if (= (first lst) obj) 1 0) (instances-in (rest lst))) 0))] (map instances-in lsts))) ...doesn't work. You can't refer to the 'let' local from within the fn definition. You can however give the fn a name, like thisfn: (defn count-instances [obj lsts] (let [instances-in (fn thisfn [lst] (if (seq lst) (+ (if (= (first lst) obj) 1 0) (thisfn (rest lst))) 0))] (map instances-in lsts))) That works, but is not very Clojurey. Just for the record, I might do it more like: (defn count-instances [obj lsts] (map #(count (filter #{obj} %)) lsts)) --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: run clojure on 5,832 cores?
SiCortex had a nice booth at Supercomputing '08. They have desktop versions of their machines too. I've heard that the SiCortex machines have a fabulous communication network, but they expect you to use it via their MPI stack. I don't think they offer a shared memory abstraction that the JVM could exploit over all the cores in the machine; maybe it would work on a single (6-way parallel) node. The biggest problem would be that as well as the possible lack of a modern JVM for the MIPS processors. I've heard that Kaffe runs on MIPS but Kaffe doesn't support Java = 1.5 so you won't be able to run Clojure with it. mfh --~--~-~--~~~---~--~~ 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 mod code is broken
On Feb 13, 2009, at 7:40 PM, Jeffrey Straszheim wrote: I just updated, and the unit tests for mod are breaking. It looks like the new mod only works for ints. Thanks for the report. I removed the non-integer tests. The new mod isn't working properly though: Testing clojure.contrib.test-clojure.numbers FAIL in (test-mod) (numbers.clj:104) expected: (= (mod 9 -3) 0) actual: (not (= -3 0)) FAIL in (test-mod) (numbers.clj:104) expected: (= (mod -9 3) 0) actual: (not (= 3 0)) It will need a fix. This is nice test-clojure success case. Congratulations test-clojure team! --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Newbie at macros: Manipulating a vector of bindings
On Fri, Feb 13, 2009 at 11:17 PM, samppi rbysam...@gmail.com wrote: I'm trying to write a macro that expands from this: (product-context [n rule0, m rule1)] (rule-maker2 (+ n m)) rule3)) Into this (assume that conc-fn and conc-products are functions): (fn [tokens] (if-let [[remainder# n m] (conc-products [rule0 rule1] tokens)] (conc-fn [(rule-maker2 (+ n m)) rule3] remainder#))) ...but I can't figure out how to change [n rule0 m rule1] to (if-let [[remainder# n m] (conc-products [rule0 rule1] tokens)] ...). Try working it out outside of the macro context. (def bindvec '[n rule0, m rule1]) Now you've got something to work with. There are plenty of acceptible answers. Maybe you want to think of the vector as key/value pairs: (apply array-map bindvec) == {n rule0, m rule1} (keys (apply array-map bindvec)) == (n m) (vals (apply array-map bindvec)) == (rule0 rule1) Or just use some seq function: (take-nth 2 bindvec) == (n m) (take-nth 2 (rest bindvec)) == (rule0 rule1) Once you've got the pieces you need, try sticking them into a syntax-quote: user= `(if-let [[r# ~(take-nth 2 bindvec)] (cp ~(take-nth 2 (rest bindvec)))] ...) (clojure.core/if-let [[r__215__auto__ (n m)] (user/cp (rule0 rule1))] ...) Well, that's close by there are extra parens around (n m) and you want a vector not a list for the rules. So play with it until it looks right: user= `(if-let [[r# ~@(take-nth 2 bindvec)] (cp ~(vec (take-nth 2 (rest bindvec] ...) (clojure.core/if-let [[r__219__auto__ n m] (user/cp [rule0 rule1])] ...) Then you're ready to build the macro: (defmacro product-context [bindvec body] `(fn [tokens#] (if-let [[remainder# ~@(take-nth 2 bindvec)] (conc-products [~@(take-nth 2 (rest bindvec))] tokens#)] (conc-fn [...@body] remainder# --Chouser --~--~-~--~~~---~--~~ 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 mod code is broken
On Sat, Feb 14, 2009 at 12:45 AM, Stephen C. Gilardi squee...@mac.com wrote: The new mod isn't working properly though: Testing clojure.contrib.test-clojure.numbers FAIL in (test-mod) (numbers.clj:104) expected: (= (mod 9 -3) 0) actual: (not (= -3 0)) FAIL in (test-mod) (numbers.clj:104) expected: (= (mod -9 3) 0) actual: (not (= 3 0)) So true: http://groups.google.com/group/clojure/browse_thread/thread/2a0ee4d248f3d131/c4f79c5a7a7c20e2 It will need a fix. Indeed it will. Fortunately it already has one: http://code.google.com/p/clojure/issues/detail?id=23#c6 --Chouser --~--~-~--~~~---~--~~ 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: eliminating uses of nil punning
On Fri, Feb 13, 2009 at 1:30 PM, Chouser chou...@gmail.com wrote: To turn on the flag you need to rebuild clojure with an extra option, like this: ant -Dclojure.assert-if-lazy-seq=please Any non-empty string will do for the value. You will need to set the value at runtime as well. There may be a way to avoid this, but I haven't thought of how. Ok, I figured out a way. With the attached patch, all you need is the ant command-line option shown above when compiling Clojure. The property is checked once at compile time and stored as a constant in the 'if' macro itself. If you've built Clojure with that property set, all uses of 'if' will do the extra check. --Chouser --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~--- commit 6b44579229db019636cb3f122f87c439ae884ccf Author: Chouser chou...@n01se.net Date: Sat Feb 14 01:25:51 2009 -0500 [lazy] Add support for assert-if-lazy-seq property. diff --git a/branches/lazy/build.xml b/branches/lazy/build.xml index 04583ba..bc5fcc7 100644 --- a/branches/lazy/build.xml +++ b/branches/lazy/build.xml @@ -11,6 +11,7 @@ property name=build location=classes/ property name=clojure_jar location=clojure.jar/ property name=slim_jar location=clojure-slim.jar/ + property name=clojure.assert-if-lazy-seq value=/ target name=init depends=clean tstamp/ @@ -28,6 +29,7 @@ java classname=clojure.lang.Compile classpath=${build}:${cljsrc} sysproperty key=clojure.compile.path value=${build}/ + sysproperty key=clojure.assert-if-lazy-seq value=${clojure.assert-if-lazy-seq}/ arg value=clojure.core/ arg value=clojure.main/ arg value=clojure.set/ diff --git a/branches/lazy/src/clj/clojure/core.clj b/branches/lazy/src/clj/clojure/core.clj index eb31005..c15ba4d 100644 --- a/branches/lazy/src/clj/clojure/core.clj +++ b/branches/lazy/src/clj/clojure/core.clj @@ -36,6 +36,10 @@ fn (fn* fn [ decl] (cons 'fn* decl))) (def + #^{:macro true} + if (fn* if [ decl] (cons 'if* decl))) + +(def #^{:arglists '([coll]) :doc Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.} @@ -291,6 +295,20 @@ (. (var defmacro) (setMacro)) +(defmacro assert-if-lazy-seq? {:private true} [] + (let [prop (System/getProperty clojure.assert-if-lazy-seq)] +(if prop + (if (.isEmpty prop) nil true + +(defmacro if [tst etc] + (if* (assert-if-lazy-seq?) +(let [tstsym 'G__0_0] + (list 'let [tstsym tst] + (list 'if* (list 'instance? clojure.lang.LazySeq tstsym) + (list 'throw (list 'new Exception LazySeq used in 'if')) + (cons 'if* (cons tstsym etc) +(cons 'if* (cons tst etc + (defmacro when Evaluates test. If logical true, evaluates body in an implicit do. [test body] @@ -1642,7 +1660,7 @@ ([coll] (sort compare coll)) ([#^java.util.Comparator comp coll] - (when (and coll (not (zero? (count coll + (when (seq coll) (let [a (to-array coll)] (. java.util.Arrays (sort a comp)) (seq a) diff --git a/branches/lazy/src/clj/clojure/core_proxy.clj b/branches/lazy/src/clj/clojure/core_proxy.clj index 8517e23..edbc78f 100644 --- a/branches/lazy/src/clj/clojure/core_proxy.clj +++ b/branches/lazy/src/clj/clojure/core_proxy.clj @@ -155,7 +155,7 @@ meths (concat (seq (. c (getDeclaredMethods))) (seq (. c (getMethods] -(if meths +(if (seq meths) (let [#^java.lang.reflect.Method meth (first meths) mods (. meth (getModifiers)) mk (method-sig meth)] diff --git a/branches/lazy/src/jvm/clojure/lang/Compiler.java b/branches/lazy/src/jvm/clojure/lang/Compiler.java index 664045f..b29876f 100644 --- a/branches/lazy/src/jvm/clojure/lang/Compiler.java +++ b/branches/lazy/src/jvm/clojure/lang/Compiler.java @@ -40,7 +40,7 @@ public class Compiler implements Opcodes{ static final Symbol DEF = Symbol.create(def); static final Symbol LOOP = Symbol.create(loop*); static final Symbol RECUR = Symbol.create(recur); -static final Symbol IF = Symbol.create(if); +static final Symbol IF = Symbol.create(if*); static final Symbol LET = Symbol.create(let*); static final Symbol DO = Symbol.create(do); static final Symbol FN = Symbol.create(fn*);