Re: sorted-map-by sample call
Hi Steve, I didn't know the difference between a keyfn and a comparator. Thanks for pointing that out! Kev On Jun 22, 3:50 pm, Stephen C. Gilardi squee...@mac.com wrote: On Jun 22, 2009, at 1:23 AM, kkw wrote: I had some fortune with the sorted-by function: 1:11 user= (sort-by (fn [e] (second e)) [[1 99] [3 4] [5 6] [7 8]]) ([3 4] [5 6] [7 8] [1 99]) You were using the form of sort-by that accepts a keyfn, not the one where you also provide a comparator. so I thought I'd have a go with sorted-map-by also: 1:13 user= (doc sorted-map-by) - clojure.core/sorted-map-by ([comparator keyvals]) keyval = key val Returns a new sorted map with supplied mappings, using the supplied comparator. 1:14 user= (sorted-map-by (fn [c] c) 1 2) {1 2} No comparisons were necessary, so your comparator function wasn't called. 1:16 user= (sorted-map-by (fn [c] c) 1 2 3 4) java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--85$fn (repl-1:16) sorted-map-by called your comparator, but comparators take two arguments and your function only accepts one. --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
On Mon, Jun 22, 2009 at 2:41 AM, liebke lie...@gmail.com wrote: Hi Anand, Try changing the INCANTER_HOME variable in the clj script to the absolute path to the incanter directory, instead of a relative path, like ./ or ../ Let me know if that doesn't work. Hi David, Didn't work, unfortunately. I can still import the required class directly, but (use '(incanter core)) fails. Thanks again, Anand --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure in Computing in Science and Engineering
On Jun 20, 2009, at 12:29, Jon Harrop wrote: The Task Parallel Library. It uses concurrent wait-free work- stealing queues to provide an efficient implementation of work items than can spawn other work items with automatic load balancing on shared memory machines. Cilk uses the same technology (well worth a look if you haven't already seen it!). I know about Cilk, and I agree that this approach is useful in practice. That makes it easy to write efficient parallel algorithms in any .NET language. In particular, it can sustain billions of work items (as opposed to thousands of threads or processes) and the time taken to spawn is ~30,000x faster than forking a process. Extremely useful stuff! Indeed! What are parallel map reduce etc. implemented upon in Clojure? Java threads, according to the documentation: clojure.core/future ([ body]) Macro Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block. The macro future is used in the implementation of pmap. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Another javadoc + clojure/slime integration
Hi all, Long time reader, first time poster. Thanks to Rich and the other contributors for all the great work on Clojure. I recently had a chance to use Clojure on a non-trivial project, which required integrating with a number of Java libraries. In the course of that I was getting tired of switching back and forth between developing in Emacs, and viewing Javadocs in Firefox. After looking at the other javadoc integration hacks, I decided I was looking for something else and built another one. Ideally, I wanted to be able able to put the cursor on any java class symbol in a clojure-mode buffer in emacs, execute M-x slime-javadoc, and have the api documentation popup in an adjacent emacs window. With the help of clojure, slime, and emacs/w3m, I was able to achieve nirvana. Anyway, I blogged about my approach (http://cynojure.posterous.com), and put up the code on github (http://github.com/kriyative/cynojure- swank/tree/master). Suggestions and comments are most welcome. -ram -- cynojure http://cynojure.posterous.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Another javadoc + clojure/slime integration
Hi all, Long time reader, first time poster. Thanks to Rich and the other contributors for all the great work on Clojure. I recently had a chance to use Clojure on a non-trivial project, which required integrating with a number of Java libraries. In the course of that I was getting tired of switching back and forth between developing in Emacs, and viewing Javadocs in Firefox. After looking at the other javadoc integration hacks, I decided I was looking for something else and built another one. Ideally, I wanted to be able able to put the cursor on any java class symbol in a clojure-mode buffer in emacs, execute M-x slime-javadoc, and have the api documentation popup in an adjacent emacs window. With the help of clojure, slime, and emacs/w3m, I was able to achieve nirvana. Anyway, I blogged about my approach (http://cynojure.posterous.com/ clojure-emacs-and-javadocs), and put up the code on github (http:// github.com/kriyative/cynojure-swank/tree/master). Suggestions and comments are most welcome. -ram -- cynojure http://cynojure.posterous.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to tweak *compile-path* ?
On Mon, Jun 22, 2009 at 7:15 AM, Thibaut Barrère thibaut.barr...@gmail.com wrote: I read that I should be able to change *compile-path* (I'd like to set it to the same folder where the .clj files is). Is it possible and how can I achieve that ? Yup, you can either using binding to create a thread-local value for *compile-path*, or use set! to alter the root binding. Usage of set! is usually discouraged outside of the REPL, I believe, but it's an option. user= *compile-path* classes user= (binding [*compile-path* src] *compile-path*) src user= *compile-path* classes user= (set! *compile-path* src) src user= *compile-path* src HTH, - J. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
Hi David, no worries, thanks for trying. I'll let you know if I find a solution. Cheers Anand On Mon, Jun 22, 2009 at 1:41 PM, liebke lie...@gmail.com wrote: Anand, you've stumped me! You can import the class directly, but you can't load incanter.core because it can't import the class? I'm not sure what would cause that behavior, and I can't reproduce it. Whenever I encounter weird errors like this, I try rebooting. You might also try cloning incanter in a fresh directory and see it if has the same behavior. Sorry, I can't be more helpful. good luck, David On Jun 22, 4:43 am, Anand Patil anand.prabhakar.pa...@gmail.com wrote: On Mon, Jun 22, 2009 at 2:41 AM, liebke lie...@gmail.com wrote: Hi Anand, Try changing the INCANTER_HOME variable in the clj script to the absolute path to the incanter directory, instead of a relative path, like ./ or ../ Let me know if that doesn't work. Hi David, Didn't work, unfortunately. I can still import the required class directly, but (use '(incanter core)) fails. Thanks again, Anand --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Dynamically accessing static fields
There's already a miglayout wrapper in contrib. It seemed usable when I looked at it. On Jun 22, 7:35 am, Laurent PETIT laurent.pe...@gmail.com wrote: Hi, BTW, if it can be an option for you, there's also the MigLayout layout manager (http://www.miglayout.com/) that allows to write constraints as Strings. It has already been mentioned on this ml, so maybe there's clojure stuff done for integrating it more closely with clojure ? HTH, -- Laurent 2009/6/18 James Koppel darmanith...@gmail.com: Thanks! Seems I forgot java.lang.reflect exists when I wrote that. On Wed, Jun 17, 2009 at 4:47 PM, Michael Reid kid.me...@gmail.com wrote: On Mon, Jun 15, 2009 at 9:13 AM, Parthparth.malwan...@gmail.com wrote: On Jun 15, 7:08 am, James Koppel darmanith...@gmail.com wrote: I am trying to write a function to simplify working with GridBagConstraints -- that is, instead of writing (let [c (GridBagConstraints.)] (set! (.weightx c) 2.0) (set! (.gridwidth c) GridBagConstraints/REMAINDER) (let [button (JButton. Hello, world!)] (.setConstraints (.getLayout *my-container*) button c) (.add *my-container* button))) I could simply write (gridbag-add *my-container* (JButton. Hello, world!) weightx=2.0;gridwith=GridBagConstraints/REMAINDER) A simple combination of regexes and read-string would easily allow me to extract the symbol 'GridBagConstraints/REMAINDER from the example string, but I'm having trouble actually converting it into its value. Using resolve simply returns nil, and getting . to work dynamically seems to be fruitless, as even this simple call (. (resolve 'GridBagConstraints) REMAINDER) throws an exception. So, the question is, how do I go dynamically from a string like GridBagConstraints/REMAINDER to the actual value of the static field? Of course, eval does the trick, but I'd rather not have to resort to it. One way to do that would be to use a map: user= (def m {Math/PI Math/PI Math/E Math/E}) #'user/m user= (defn foo [n s] [n (get m s :not-found)]) #'user/foo user= (foo 10 Math/PI) [10 3.141592653589793] user= You could also consider writing a function that takes these as parameters and returns the updated container. That way you can avoid the regex. Regards, Parth Not sure if this can be fit in with what you're trying to do, but you can accomplish this with a macro: user= (defmacro resolve-sym-str [s] (let [[ns sym] (.split s /)] (symbol ns sym))) #'user/resolve-sym-str user= (resolve-sym-str Math/PI) 3.141592653589793 user= However, looking at this further, it seems that the first part of what you have tried works: user= (import '(java.awt GridBagConstraints)) nil user= (resolve 'GridBagConstraints) java.awt.GridBagConstraints Now you can use Java's reflection API to grab the field you want: user= (- (resolve 'GridBagConstraints) (.getDeclaredField REMAINDER) (.get nil)) 0 So it would appear this is possible without a macro, which probably makes it easier to use. /mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
OK, figured it out... the problem was I had copied incanter.clj to /Library/Java/Extensions. When I removed that copy, everything worked as expected. Weird, but I'm glad it's not happening anymore. Anand On Mon, Jun 22, 2009 at 1:52 PM, Anand Patil anand.prabhakar.pa...@gmail.com wrote: Hi David, no worries, thanks for trying. I'll let you know if I find a solution. Cheers Anand On Mon, Jun 22, 2009 at 1:41 PM, liebke lie...@gmail.com wrote: Anand, you've stumped me! You can import the class directly, but you can't load incanter.core because it can't import the class? I'm not sure what would cause that behavior, and I can't reproduce it. Whenever I encounter weird errors like this, I try rebooting. You might also try cloning incanter in a fresh directory and see it if has the same behavior. Sorry, I can't be more helpful. good luck, David On Jun 22, 4:43 am, Anand Patil anand.prabhakar.pa...@gmail.com wrote: On Mon, Jun 22, 2009 at 2:41 AM, liebke lie...@gmail.com wrote: Hi Anand, Try changing the INCANTER_HOME variable in the clj script to the absolute path to the incanter directory, instead of a relative path, like ./ or ../ Let me know if that doesn't work. Hi David, Didn't work, unfortunately. I can still import the required class directly, but (use '(incanter core)) fails. Thanks again, Anand --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Is it possible to tweak *compile-path* ?
Hi, Yup, you can either using binding to create a thread-local value for *compile-path*, or use set! to alter the root binding. Usage of set! is usually discouraged outside of the REPL, I believe, but it's an option. It works! I just used: (set! *compile-path* .) The need for classes folder disappear. thanks! -- Thibaut --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Solving memory problems with Clojure code
I want to make it clear, that it probably isn't Clojure's memory problem but something with my code. Anyway, I was trying to figure out my heap memory goes up so much on various operations in my application. Sure, it could be anything but I know I am doing something wrong. Here is the application, a text editor in SWT. When I open files, the heap memory goes up 10 times the size of the file. So, if I open a 3MB file, that is 30MB of heap memory used. http://code.google.com/p/lighttexteditor/ There are also some bad designs I am using, still wouldn't explain a 10 fold increase in memory. http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojure/light/toolkit/ So far, I have done a couple of things. 1. Turned on warn on reflection and reduced some of the reflection calls by adding type hints. 2. Tried to reduce the number of calls to deref and not use global? defines. Here is the code that I think is the worst offender. Basically, a java oriented approach for opening a file. (defn open-file-util [file file-path] #^{:doc Use java oriented approach for loading a file into memory } ;; Java oriented approach for opening file (let [stream (new FileInputStream file-path) instr (new LineNumberReader (new InputStreamReader stream)) ;; Use type hints to ensure a character type. readBuffer #^[C (make-array (. Character TYPE) 2048) buf (new StringBuffer)] (loop [n (. instr read readBuffer)] (when ( n 0) (. buf append readBuffer 0 n) (recur (. instr read readBuffer ;; File info data has been collected, set some of the file properties (set-file-info (. file getName) (. file getAbsolutePath) (. file lastModified) (. instr getLineNumber) (. file getParent) (. file canWrite) (. file exists) (. file length)) (. instr close) (. buf toString))) http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojure/light/toolkit/light_file_utils.clj Here are some notes from my early analysis, also a google doc on the functions that are called. memory profiling clojure http://groups.google.com/group/clojure/browse_thread/thread/b44e25f23d36b08b/296e95f743651949?lnk=gstq=berlin+brown#296e95f743651949 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
On Jun 22, 2009, at 15:11, Anand Patil wrote: OK, figured it out... the problem was I had copied incanter.clj to / Library/Java/Extensions. When I removed that copy, everything worked as expected. Weird, but I'm glad it's not happening anymore. I have seen strange behaviour with Clojure code in Library/Java/ Extensions as well, including Clojure code inside jar files. I can't offer an explanation either, but I recommend all MacOS users not to put Clojure source in there at all. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
Excellent, I'm glad you figured it out. I'll note the problem with / Library/Java/Extensions, in case it happens to others in the future. Thanks, David On Jun 22, 9:11 am, Anand Patil anand.prabhakar.pa...@gmail.com wrote: OK, figured it out... the problem was I had copied incanter.clj to /Library/Java/Extensions. When I removed that copy, everything worked as expected. Weird, but I'm glad it's not happening anymore. Anand On Mon, Jun 22, 2009 at 1:52 PM, Anand Patil anand.prabhakar.pa...@gmail.com wrote: Hi David, no worries, thanks for trying. I'll let you know if I find a solution. Cheers Anand On Mon, Jun 22, 2009 at 1:41 PM, liebke lie...@gmail.com wrote: Anand, you've stumped me! You can import the class directly, but you can't load incanter.core because it can't import the class? I'm not sure what would cause that behavior, and I can't reproduce it. Whenever I encounter weird errors like this, I try rebooting. You might also try cloning incanter in a fresh directory and see it if has the same behavior. Sorry, I can't be more helpful. good luck, David On Jun 22, 4:43 am, Anand Patil anand.prabhakar.pa...@gmail.com wrote: On Mon, Jun 22, 2009 at 2:41 AM, liebke lie...@gmail.com wrote: Hi Anand, Try changing the INCANTER_HOME variable in the clj script to the absolute path to the incanter directory, instead of a relative path, like ./ or ../ Let me know if that doesn't work. Hi David, Didn't work, unfortunately. I can still import the required class directly, but (use '(incanter core)) fails. Thanks again, Anand --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure in Computing in Science and Engineering
On Sun, 21 Jun 2009 14:39:37 +0100, Jon Harrop j...@ffconsultancy.com wrote: I had not looked at Intel's offering because it does not (AFAIK) support accurate garbage collection. Also, it is worth noting that there is no difference between data and task parallelism in a genuine functional language. Well, I meant task parallelism vs. data parallelism in the design intent, rather than the implementation. I find that calling computational fluid dynamics data parallel, and a telecom switch task parallel is useful even if happens that solutions to both sorts of problems in genuine FP are somehow isomorphic. I feel that's because the problem domains, and the ways a typical programmer thinks about the solutions, are different enough that the isomorphism isn't likely to be astonishingly useful in practice. Well, maybe except for programming in the small. For instance, I don't see overwhelming practical applications of proving one could implement a telecom switch as parallel maps and reductions over a bunch of functions, unless (perhaps) you're a compiler writer and/or designing a DSL for the purpose. It's fun as a thought experiment, but I think that it would stray too far from the language of the problem without lots of sugar that would (it seems to me) just sort of take you back to where you started in terms of expressiveness. But then again, those sorts of visions aren't my forte :) Right. If you hand-roll your C++ very carefully then you can get decent performance but I was disappointed with the performance of the template libraries and quality of g++ back in 2004 and have never used C++ since. Yeah, g++ 4.1 and 4.2 seemed to have a reputation for being especially bad at optimizing away abstraction penalties of heavy template usage. I understand this is much better in recent releases, but I haven't measured it myself. For all it's warts, C++ (like Java) has interesting things happen to it here and there, if only by sheer volume and chance. And every so often a problem comes along that feels like a good fit. Maybe I'm just perverse, and I bet *nobody* here will agree with me, but sometimes I feel wrong when I use a language like a Lisp, with its symbolic and meta-everything sweet spot, to do something as brutish and mundane as picking apart awful binary formats and chewing through vectors of integers and floats. It feels like ruining expensive top shelf bourbon by pouring it in Coke :) -Kyle --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Incanter classpath difficulties
Just another 2¢ in case someone stumbles across this thread from a search… I've actually seen oddities like this on OpenSolaris and my Mac, too, when running from a jar: I'm a little hazy on the details (working late is not good for the memory!) but IIRC there was some unhappy interaction between the jar's Class-Path manifest entry and the command-line classpath (if there was one). One of the symptoms was that my jar would start to load, and I'd get a stack trace which reported the gen-classed class not found. (Very confusing, given that javap would happily print it for me!) Nowhere in the stack trace was the *real* cause, which was that one of the classes or interfaces that my class required wasn't in the run- time classpath. Particularly in the case of the servlets I'm building, the jar has to have a Class-Path entry to find the non-standard libraries it needs. I sometimes feel like half of my Java development time is spent debugging classpath problems! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Solving memory problems with Clojure code
Have you tried (.close stream) in the end of let block? On 22 јун, 16:10, BerlinBrown berlin.br...@gmail.com wrote: I want to make it clear, that it probably isn't Clojure's memory problem but something with my code. Anyway, I was trying to figure out my heap memory goes up so much on various operations in my application. Sure, it could be anything but I know I am doing something wrong. Here is the application, a text editor in SWT. When I open files, the heap memory goes up 10 times the size of the file. So, if I open a 3MB file, that is 30MB of heap memory used. http://code.google.com/p/lighttexteditor/ There are also some bad designs I am using, still wouldn't explain a 10 fold increase in memory. http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur... So far, I have done a couple of things. 1. Turned on warn on reflection and reduced some of the reflection calls by adding type hints. 2. Tried to reduce the number of calls to deref and not use global? defines. Here is the code that I think is the worst offender. Basically, a java oriented approach for opening a file. (defn open-file-util [file file-path] #^{:doc Use java oriented approach for loading a file into memory } ;; Java oriented approach for opening file (let [stream (new FileInputStream file-path) instr (new LineNumberReader (new InputStreamReader stream)) ;; Use type hints to ensure a character type. readBuffer #^[C (make-array (. Character TYPE) 2048) buf (new StringBuffer)] (loop [n (. instr read readBuffer)] (when ( n 0) (. buf append readBuffer 0 n) (recur (. instr read readBuffer ;; File info data has been collected, set some of the file properties (set-file-info (. file getName) (. file getAbsolutePath) (. file lastModified) (. instr getLineNumber) (. file getParent) (. file canWrite) (. file exists) (. file length)) (. instr close) (. buf toString))) http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur... Here are some notes from my early analysis, also a google doc on the functions that are called. memory profiling clojurehttp://groups.google.com/group/clojure/browse_thread/thread/b44e25f23... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure in Computing in Science and Engineering
Maybe I'm just perverse, and I bet *nobody* here will agree with me, but sometimes I feel wrong when I use a language like a Lisp, with its symbolic and meta-everything sweet spot, to do something as brutish and mundane as picking apart awful binary formats and chewing through vectors of integers and floats. It feels like ruining expensive top shelf bourbon by pouring it in Coke :) I do see your point (and as a bourbon enthusiast, I understand the analogy!). That's the nice thing about Clojure over other Lisps: more abstraction means more opportunity to hide these things, which at least means you can forget about the Pappy and Coke someone's drinking! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Shouldn't c.l.Namespace implement c.l.Named?
kedu pmf What about this (str *ns*)? I remember reading it from chouser's post. Regards, Emeka --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: why is io! not enforced?
On Jun 20, 4:59 pm, Rowdy Rednose rowdy.redn...@gmx.net wrote: On a side-note: I actually think it can make sense to do io in transactions in Clojure, and I believe (knowing that transactions can be replayed) it is possible to use that to e.g. implement a transaction log written to disk that could be used to rebuild the data in case of a crash. Use agents. When inside a running transaction, all agent dispatches are held until the transaction commits. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Solving memory problems with Clojure code
On Jun 22, 12:32 pm, Marko Kocić marko.ko...@gmail.com wrote: Have you tried (.close stream) in the end of let block? On 22 јун, 16:10, BerlinBrown berlin.br...@gmail.com wrote: I want to make it clear, that it probably isn't Clojure's memory problem but something with my code. Anyway, I was trying to figure out my heap memory goes up so much on various operations in my application. Sure, it could be anything but I know I am doing something wrong. Here is the application, a text editor in SWT. When I open files, the heap memory goes up 10 times the size of the file. So, if I open a 3MB file, that is 30MB of heap memory used. http://code.google.com/p/lighttexteditor/ There are also some bad designs I am using, still wouldn't explain a 10 fold increase in memory. http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur... So far, I have done a couple of things. 1. Turned on warn on reflection and reduced some of the reflection calls by adding type hints. 2. Tried to reduce the number of calls to deref and not use global? defines. Here is the code that I think is the worst offender. Basically, a java oriented approach for opening a file. (defn open-file-util [file file-path] #^{:doc Use java oriented approach for loading a file into memory } ;; Java oriented approach for opening file (let [stream (new FileInputStream file-path) instr (new LineNumberReader (new InputStreamReader stream)) ;; Use type hints to ensure a character type. readBuffer #^[C (make-array (. Character TYPE) 2048) buf (new StringBuffer)] (loop [n (. instr read readBuffer)] (when ( n 0) (. buf append readBuffer 0 n) (recur (. instr read readBuffer ;; File info data has been collected, set some of the file properties (set-file-info (. file getName) (. file getAbsolutePath) (. file lastModified) (. instr getLineNumber) (. file getParent) (. file canWrite) (. file exists) (. file length)) (. instr close) (. buf toString))) http://lighttexteditor.googlecode.com/svn/trunk/light_edit/src/clojur... Here are some notes from my early analysis, also a google doc on the functions that are called. memory profiling clojurehttp://groups.google.com/group/clojure/browse_thread/thread/b44e25f23... (. instr close) I have this, you say use stream close. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: why is io! not enforced?
This won't work unfortunately, because it means that the in-memory transaction has already commited before the disk write is performed by the agent. If the application crashed at that point, your write was not durable. -- Sent from my Palm Pre ataggart wrote: On Jun 20, 4:59 pm, Rowdy Rednose wrote: On a side-note: I actually think it can make sense to do io in transactions in Clojure, and I believe (knowing that transactions can be replayed) it is possible to use that to e.g. implement a transaction log written to disk that could be used to rebuild the data in case of a crash. Use agents. When inside a running transaction, all agent dispatches are held until the transaction commits. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: javafx
On Jun 21, 11:02 pm, Pinocchio cchino...@gmail.com wrote: CuppoJava wrote: I'm still not very clear about what JavaFX actually is and what's its relation to Java. Do you know of any links that explain it clearly? Its basically a way of declaring Swing GUI items and their layout. One of its cool features is that it allows binding code to changes in declared items, making it a reactive, event based system for handling GUIs. I have not used it though... Interop with Clojure is definitely an interesting intellectual exercise. Sorry, but I'd like to correct the record here. :) It's not Swing -- it's a completely new GUI toolkit. And interop with Clojure may necessary if you want to use Clojure to write web apps with video or animations in the near future. Some animations are eye candy, but when they are done right they can make a better UI. Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Solving memory problems with Clojure code
BerlinBrown napisał(a): I want to make it clear, that it probably isn't Clojure's memory problem but something with my code. Anyway, I was trying to figure out my heap memory goes up so much on various operations in my application. Sure, it could be anything but I know I am doing something wrong. I've been playing around recently with JMX in clojure in particular in context of heap memory usage. I created some simple function in Clojure and method in Java in order to be able to check heap memory usage (see code below). I used this code to check your function's memory consumption. Then I implemented something similar in Java and checked that as well. My quick and dirty tests show that there is no difference between Clojure and Java version regarding memory usage in this case. So maybe you're looking in wrong place. $ clojure test_io.clj test.xml TEST: test.xml (2,51MB) used: 1,23MB, reserved: 1,94MB, max: 63,56MB used: 13,89MB, reserved: 18,79MB, max: 63,56MB $ clojure test_io.clj test2.xml TEST: test2.xml (5,02MB) used: 1,23MB, reserved: 1,94MB, max: 63,56MB used: 26,93MB, reserved: 36,00MB, max: 63,56MB $ java TestIO test.xml TEST: test.xml (2,51MB) used: 0,21MB, reserved: 1,94MB, max: 63,56MB used: 13,20MB, reserved: 17,65MB, max: 63,56MB $ java TestIO test2.xml TEST: test2.xml (5,02MB) used: 0,21MB, reserved: 1,94MB, max: 63,56MB used: 26,24MB, reserved: 34,92MB, max: 63,56MB # test_io.clj (ns test_io (:import (java.io File FileInputStream InputStreamReader LineNumberReader) (java.lang.management ManagementFactory MemoryType))) (defn open-file [file-path] ;; Java oriented approach for opening file (let [stream (new FileInputStream file-path) instr (new LineNumberReader (new InputStreamReader stream)) ;; Use type hints to ensure a character type. readBuffer #^[C (make-array (. Character TYPE) 2048) buf (new StringBuffer)] (loop [n (. instr read readBuffer)] (when ( n 0) (. buf append readBuffer 0 n) (recur (. instr read readBuffer (. instr close) (. buf toString))) (defn memory-usage [] (let [pools (ManagementFactory/getMemoryPoolMXBeans) mb (* 1024.0 1024.0) step (fn [pools tu tr tm] (if (not (seq pools)) [(/ tu mb) (/ tr mb) (/ tm mb)] (let [pool (first pools) usage (. pool getUsage)] (recur (rest pools) (+ tu (. usage getUsed)) (+ tr (. usage getCommitted)) (+ tm (. usage getMax))] (step (filter #(= (. % getType) MemoryType/HEAP) pools) 0 0 0))) (defn dump-memory-usage [[used reserved max]] (println (format used: %.2fMB, reserved: %.2fMB, max: %.2fMB used reserved max))) (defn test-open-file [fname] (let [file (new File fname)] (println (format TEST: %s (%.2fMB) (. file getName) (/ (. file length) (* 1024.0 1024.0 (dump-memory-usage (memory-usage)) (open-file (. file getAbsolutePath)) (dump-memory-usage (memory-usage (test-open-file (first *command-line-args*)) # TestIO.java import java.util.List; import java.util.Formatter; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.InputStreamReader; import java.io.LineNumberReader; import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; import java.lang.management.MemoryType; public class TestIO { private double MB = 1024.0 * 1024.0; public String openFile(String filePath) throws IOException { FileInputStream stream = new FileInputStream(filePath); LineNumberReader instr = new LineNumberReader(new InputStreamReader(stream)); char[] readBuffer = new char[2048]; StringBuffer buf = new StringBuffer(); int n = 0; while ((n = instr.read(readBuffer)) 0) { buf.append(readBuffer, 0, n); } instr.close(); return buf.toString(); } public void testOpenFile(String fname) throws IOException { File file = new File(fname); System.out.println(String.format(TEST: %s (%.2fMB), file.getName(), file.length() / MB)); System.out.println(dumpMemory()); openFile(file.getAbsolutePath()); System.out.println(dumpMemory()); } private String dumpMemory() { StringBuilder sb = new StringBuilder(); long totalUsed = 0; long totalReserved = 0; long totalMax = 0; ListMemoryPoolMXBean pools = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean pool : pools) { MemoryUsage usage = pool.getUsage();
Re: Clojure in Computing in Science and Engineering
On Monday 22 June 2009 12:01:19 Konrad Hinsen wrote: Java threads, according to the documentation: clojure.core/future ([ body]) Macro Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block. The macro future is used in the implementation of pmap. If that is spawning a new thread every time a future is created then it is really for concurrent programming rather than parallel programming. -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure in Computing in Science and Engineering
On Monday 22 June 2009 22:33:24 Stephen C. Gilardi wrote: On Jun 22, 2009, at 5:53 PM, Jon Harrop wrote: If that is spawning a new thread every time a future is created then it is really for concurrent programming rather than parallel programming. The thread is from a cached thread pool provided by the Executors class: http://java.sun.com/javase/6/docs/api/java/util/concurrent/Executors.html#n ewCachedThreadPool%28%29 Ok, that will be reliable then but performance is quite a bit worse than it could be. Essentially the same as pre-TPL .NET, e.g. using asynchronous workflows in F# today. The migration occurs officially on the MS side with the release of .NET 4 next year. Is there a similar plan on the JVM side? -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Code generation at runtime
Dear all, I am quite new to clojure, and I can't find any good way to generate code at runtime. Of course, there is eval, but eval is not very competent in manipulating namespace and bindings at runtinme. For example, this: - (binding [*ns* *ns*] (eval '(do (ns Blop (:gen-class)) (println (def x 0)) )) (eval '(do (ns Blip (:use Blop)) (println Blop/x))) ) is unhappy because it can't see any .class for Blop. - (binding [*ns* *ns*] (eval '(do (ns Blop (:gen-class)) (println (def x 0)) )) (eval '(println clojure.core/x)) ) works in a compiled .class but not in the REPL - (binding [*ns* *ns*] (eval '(do (ns Blop (:gen-class)) (println (def x 0)) )) (eval '(println user/x)) ) Works in the REPL but not in a compiled .class. I tried also to play a bit with load-string, but without any luck. It must be possible to generate new bindings or even namespaces at runtime, as the REPL does just that. Is there a deep reason why it is difficult? Is there a lot of magic in the REPL? Would it be possible to pull this magic out in a reusable way? Can I try to do it or it is really difficult/impossible? I think, it would quite Lispy for Clojure to have very few differences between REPL and compiled runtime. Thanks a lot for your help, Best regards, Nicolas. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: leveraging Clojure STM in other JVM languages?
So Raoul, did you give it a try after all of this? On May 1, 7:40 pm, Raoul Duke rao...@gmail.com wrote: hi, has anybody experimented with using Clojure code from e.g. Scala, to get Clojure STM goodness in other languages? thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: leveraging Clojure STM in other JVM languages?
So Raoul, did you give it a try after all of this? in a word... no. :-} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: leveraging Clojure STM in other JVM languages?
On Jun 22, 2009, at 3:45 PM, Wilson MacGyver wrote: that seems very hard to do. I wrote some code that called Clojure from Jython just to see if it would work. All you have to do is use :gen-class to compile it and call it as though it's Java. I haven't used Scala so I'm not sure what its like calling Java from Scala but it shouldn't be any different than calling methods on any other Java object. I don't think this can interfere with Clojure's concurrency model, since it's implemented atop Java's concurrency primitives. How would you grantee no side effect from other languages? Not sure you have to. Clojure's variables/refs/atoms/agents/etc. do not expose their contents in a writeable way without going through their APIs. I'm pretty sure Clojure doesn't mind if calling external code results in side effects on the other side, and stuff on the other side can't manipulate Clojure's immutable types as though they are mutable due to Java's access protection mechanism. You would have to worry about side-effects happening on the other side during Clojure transactions that got replayed though. — Daniel Lyons --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
intro to mutation?
seems like Clojure has a range of choices when it comes to dealing with mutation. is there a great online tutorial that explains what the options are, and that suggests when to not/use them? many thanks. oh wait. http://stackoverflow.com/questions/1028318/clojure-mutable-storage-types :-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Compiling from command line (solved)
Hi, I found instructions about how to compile from the REPL very quickly, but it took me longer to manage to compile from the command-line. I'm sharing it here in case it's useful to someone else. To compile a .clj file, I've used this: java -cp libs/clojure-1.0.0.jar:. clojure.main -e (set! *compile- path* \.\) (compile 'Hello) (if Hello.clj is in current path) If you don't want to tweak *compile-path*, you'll have to create a classes folder first, then java -cp libs/clojure-1.0.0.jar:. clojure.main -e (compile 'Hello) btw - if there is a better way to achieve this, I'm ready to learn :) cheers, -- Thibaut --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
How can I stop leaking memory?
Dear all, I really love programming in Clojure, and have done so for the past couple of months, building my company's software recommendation engine in Clojure (not in production yet), which I originally wrote in Ruby. However I have run into the following a memory problem, which actually was pointed out by Christophe Grand in a response on stackoverflow (http://stackoverflow.com/questions/749911/how-can-i-leak-memory-in- clojure). In my case I want to calculate (usage) correlations between items, and pick for each item its most similar items. For example, If I compare one item with 1.000.000 others, and calculate their similarities, then next I sort the collection, and pick only the top (say 10) Artificial code example: (take 10 (sort (for [x (range 100)] (rand) Now the problem is the memory usage, as it does not merely uses memory space for 10 items, but it keeps a reference to the entire sequence. If I leave out the sort its all ok, and done lazily. Does anyone know how to sort and avoid large memory consumptions? Thanks in advance. (I'm running on Mac OSX with Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How can I stop leaking memory?
Does anyone know how to sort and avoid large memory consumptions? well, presumably the sort needs to look at all the data in order to be able to sort it, no?! so it is kinda just a tough cookie reality that the memory will be used. on the other hand, maybe you can do some form of the Schwartzian Transform. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
macroexpand question
I just wrote my first practice macro, first without and then with syntax quoting: (defmacro take-until1 [function sq] (list 'take-while (list 'fn (vector 'x) (list 'not (list function 'x))) sq)) (defmacro take-until2 [function sq] `(take-while (fn [x#] (not (~function x#))) ~sq)) Both seem to work, but macroexpand shows different formats: (macroexpand '(take-until1 #( % 10) (iterate inc 1))) - (take-while (fn [x] (not ((fn* [p1__502] ( p1__502 10)) x))) (iterate inc 1)) (macroexpand '(take-until2 #( % 10) (iterate inc 1))) (clojure.core/take-while (clojure.core/fn [x__405__auto__] (clojure.core/not ((fn* [p1__506] ( p1__506 10)) x__405__auto__))) (iterate inc 1)) While I prefer the syntax of macro 2, I like the expand format of macro 1. Is there any way to get the best of both worlds? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Question/Problem re (set! *warn-on-reflection* true)
Thank you for your help. I have posted a message on the Enclojure group yesterday and I am still waiting for it to show up... On Jun 22, 5:46 am, Stephen C. Gilardi squee...@mac.com wrote: On Jun 21, 2009, at 11:17 PM, arasoft wrote: When I enter the following function into the REPL it compiles and works without problems: (defn harmonic-number [n prec] (reduce + (map #(with-precision prec (/ 1 (bigdec %))) (range 1 (inc n ) After (set! *warn-on-reflection* true), in a normal REPL I get: Reflection warning, NO_SOURCE_PATH:3 - call to java.math.MathContext ctor can't be resolved. You can give the compiler a type hint on prec to avoid the reflection: (defn harmonic-number [n #^Integer prec] (reduce + (map #(with-precision prec (/ 1 (bigdec %))) (range 1 (inc n ) In Enclojure, it's worse: CompilerException java.lang.ClassCastException: java.io.OutputStreamWriter cannot be cast to java.io.PrintWriter (NO_SOURCE_FILE:8) (At least) some versions of Enclojure are binding *err* to an OutputStreamWriter rather than a PrintWriter. Clojure's default binding is to a PrintWriter and some of Clojure expects a PrintWriter. I consider binding *err* to an OutputStreamWriter to be a bug. I think the Enclojure developers know about it, so if there's a version of Enclojure you haven't upgraded to, I recommend trying that. If you're using the latest version, I suggest taking a look at their bug list (if it's public) and/or letting them know about it. --Steve smime.p7s 3KViewDownload --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Code generation at runtime
On Mon, Jun 22, 2009 at 5:11 PM, Nicolas Ourynicolas.o...@gmail.com wrote: Of course, there is eval, but eval is not very competent in manipulating namespace and bindings at runtinme. eval is exactly what the REPL uses, one call to eval per top-level form. In several examples you put an 'ns' form and others into a single 'do' form -- you can try that at a REPL to see how it will work before putting it into an eval call. - (binding [*ns* *ns*] I think you may be misunderstanind something about Vars or binding -- I can't think of a situation in which the above usage of 'binding' would have any purpose. Perhaps it would be worth your time to review http://clojure.org/vars --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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Compiling from command line (solved)
On Jun 23, 12:30 am, Thibaut Barrère thibaut.barr...@gmail.com wrote: btw - if there is a better way to achieve this, I'm ready to learn :) There's the main-proc in clojure.lang.Compile, which uses the system property clojure.compile.path to define the output directory and accepts a list of libs to compile. (I don't know whether this is the currently endorsed way or a legacy entry point, though.) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Code generation at runtime
I think the best way for me to approach this is to ask what you want to do. This is a generalization, but most code doesn't need to call eval - the REPL does, and some advanced uses of generating code at runtime based on data. The normal Lisp approach for code that generates code is macros (defmacro, not eval), so you might want to look into that first: http://clojure.org/macros. I see the repl in main.clj does something similar to you in its with-bindings, but the reason is to make those vars able to be set!, not to establish the external namespace for the eval. In your eval string, the ns is the default 'user ns. To use a different ns, you would need to establish that inside the string. I think the only difference between the REPL and the runtime you're seeing is precisely because the REPL is an environment for eval'ing code. There's no interpreter, only one compiler. Hope this helps. -Mike On Mon, Jun 22, 2009 at 5:38 PM, Chouser chou...@gmail.com wrote: On Mon, Jun 22, 2009 at 5:11 PM, Nicolas Ourynicolas.o...@gmail.com wrote: Of course, there is eval, but eval is not very competent in manipulating namespace and bindings at runtinme. eval is exactly what the REPL uses, one call to eval per top-level form. In several examples you put an 'ns' form and others into a single 'do' form -- you can try that at a REPL to see how it will work before putting it into an eval call. - (binding [*ns* *ns*] I think you may be misunderstanind something about Vars or binding -- I can't think of a situation in which the above usage of 'binding' would have any purpose. Perhaps it would be worth your time to review http://clojure.org/vars --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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: macroexpand question
On Jun 22, 8:24 pm, arasoft t...@arasoft.de wrote: I just wrote my first practice macro, first without and then with syntax quoting: (defmacro take-until1 [function sq] (list 'take-while (list 'fn (vector 'x) (list 'not (list function 'x))) sq)) (defmacro take-until2 [function sq] `(take-while (fn [x#] (not (~function x#))) ~sq)) Both seem to work, but macroexpand shows different formats: (macroexpand '(take-until1 #( % 10) (iterate inc 1))) - (take-while (fn [x] (not ((fn* [p1__502] ( p1__502 10)) x))) (iterate inc 1)) (macroexpand '(take-until2 #( % 10) (iterate inc 1))) (clojure.core/take-while (clojure.core/fn [x__405__auto__] (clojure.core/not ((fn* [p1__506] ( p1__506 10)) x__405__auto__))) (iterate inc 1)) While I prefer the syntax of macro 2, I like the expand format of macro 1. Is there any way to get the best of both worlds? The only real differences I see are the name-qualifying, p1_506 instead of p1_502, and x__405__auto__ instead of x. The only part I've ever found annoying was the name-qualifying. When I want to declutter the results of macroexpand, I just paste into a text editor and do a replace of clojure.core/ with the empty string. P.S. (complement f) has the same effect as (fn [foo] (not (f foo))). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: intro to mutation?
I'm going to bash my own Stack Overflow post by repeating my disclaimer about not learning from it. I literally learned about mutation today and picked up Clojure about 3 days ago (although I've used Lisp and Java before so the learning curve wasn't huge). Otherwise, I'm glad if it helps :) On Jun 22, 6:24 pm, Raoul Duke rao...@gmail.com wrote: seems like Clojure has a range of choices when it comes to dealing with mutation. is there a great online tutorial that explains what the options are, and that suggests when to not/use them? many thanks. oh wait.http://stackoverflow.com/questions/1028318/clojure-mutable-storage-types :-) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How can I stop leaking memory?
On Jun 22, 6:46 pm, beatle...@gmail.com beatle...@gmail.com wrote: (take 10 (sort (for [x (range 100)] (rand) Now the problem is the memory usage, as it does not merely uses memory space for 10 items, but it keeps a reference to the entire sequence. If I leave out the sort its all ok, and done lazily. Sort can't really be lazy without being unbelievably slow. I'm guessing what you want is for the long sequence produced by sort to be collectable garbage, aside from the ten items you take. Now the lazy nature of take 10 is biting you in the butt. If you make it eager with doall it *might* work. I'd instead do something like (vec (take 10 (sort ... ))) which constructs a whole new vector of ten items and drops any possible reference to the input. The GC should sweep away everything but the ten-element vector as soon as the memory is needed elsewhere. But this should not have been causing a stack overflow. If you're getting stack overflows, it's something else. Most likely you have very deep tail recursion and hoped it would be optimized like in Scheme. That won't work; you have to make tail recursion explicit in clojure using (recur args) instead of (fn-name args). You can also use recur together with loop to make a loop inside a function. It's functional in that, though the loop variables can be rebound each time around the loop, it's conceptually equivalent to defining and then calling a tail-recursive letfn, and a lot less syntactically messy. Someone here recently wrote a macro, I forget its name, to make lazy- seq similarly less messy to use. Search the site for lazy-seq. It's not as useful, because usually you've got something like take or take-while or map that can be used to make the lazy sequence you want, and rarely need to resort to lazy-seq itself. But for now, you probably just need to use recur at your tail calls to fix your stack overflows, unless you have multiple functions calling each other with circularities. That's messier to tail- optimize, unfortunately. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: macroexpand question
macro #2 is the idiomatic way of writing a macro. You generally shouldn't worry about the expanded form of the macro. All that extra clojure.core/ stuff is actually for your benefit. Imagine if you use that macro in a different namespace where take- while has been redefined. You probably intended for your macro to use the take-while that was defined when you first wrote the macro. The clojure/core/ prefix ensures that. -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How can I stop leaking memory?
Hi all, On Tue, Jun 23, 2009 at 4:16 AM, Four of Seventeen fsevent...@gmail.comwrote: On Jun 22, 6:46 pm, beatle...@gmail.com beatle...@gmail.com wrote: (take 10 (sort (for [x (range 100)] (rand) Now the problem is the memory usage, as it does not merely uses memory space for 10 items, but it keeps a reference to the entire sequence. If I leave out the sort its all ok, and done lazily. Sort can't really be lazy without being unbelievably slow. Selecting the top N out of n items is a O(n*sqrt(N)) operation so it's linear when n dominates N and thus must beat take + sort. Plus it won't retain the whole realized seq in memory. Maybe contrib already has something like that, else sorted-map and rseq are your friends :-) hth, Christophe -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How can I stop leaking memory?
On Jun 22, 2009, at 11:36 PM, Christophe Grand wrote: Selecting the top N out of n items is a O(n*sqrt(N)) operation so it's linear when n dominates N and thus must beat take + sort. Plus it won't retain the whole realized seq in memory. Just because I'm curious, I can see how to do max in O(N) time, so I can see how to do top-n in O(n*N) ≈ O(N) time, but I don't see how to do that in sqrt(N) time. What's this algorithm called or how does it work? — Daniel Lyons --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---