Re: Reducers
There's a right parenthesis missing at http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html : Now: (reduce + 0 (map inc [1 2 3 4])) ;;becomes (reduce + 0 (reducer [1 2 3 4] (mapping inc)) MISSING PAREN under the heading Reducers sincerely, --Robert McIntyre, Dylan Holmes On Tue, May 15, 2012 at 1:58 PM, Rich Hickey richhic...@gmail.com wrote: I've written another post which goes into the reducers in more detail: http://clojure.com/blog/2012/05/15/anatomy-of-reducer.html Rich On May 10, 2012, at 1:26 PM, Christian Romney wrote: On Thursday, May 10, 2012 8:02:09 AM UTC-4, Nicolas Oury wrote: I can describe the background to understand my last email. Thank you very much for taking the time to post all of that–I've got some reading to do for sure. -- -- You 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 -- You 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: Literate Programming in Emacs?
Here's a pew literate programs I've written, as well as the website on which they are hosted. http://hg.bortreb.com/abomination/ http://hg.bortreb.com/aurellem/ http://hg.bortreb.com/cortex/ http://www.aurellem.com I use some emacs scripts to automate tangling and weaving. http://hg.bortreb.com/org-tools/ http://hg.bortreb.com/repl/ sincerely, --Robert McIntyre On Tue, Nov 29, 2011 at 7:31 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: Haven't done any recently. A long, long time ago I wrote a Common Lisp FFI tool using a Literate Programming tool called noweb. It's so old it predates GitHub: http://stuartsierra.com/software/perl-in-lisp -S -- You 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 -- You 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
should partial accept a single argument?
I'm curious why something like (partial *) doesn't work. reading the docstring, user (doc partial) - clojure.core/partial ([f arg1] [f arg1 arg2] [f arg1 arg2 arg3] [f arg1 arg2 arg3 more]) Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args. It seems like fewer than the normal arguments to f could reasonably include 0 arguments. why not have (partial f) return f? it would be consistent with (* n) == n, (+ n) == n etc, and would help when using partial recursively. sincerely, --Robert McIntyre -- You 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: Literate programming
I've found org-mode in emacs quite acceptable for literate programming in clojure. http://orgmode.org/ git://orgmode.org/org-mode.git Here are some things I've used it for: http://aurellem.com/abomination/html/no_parens.html http://aurellem.com/pokemon-types/html/lpsolve.html http://aurellem.com/thoughts/html/man-years.html It's possible to automatically monitor the org files in a project, regenerate the html and source code whenever they are changed, and get a very tight write-debug-test cycle. Try it out it's fun! sincerely, --Robert McIntyre On Thu, Oct 27, 2011 at 8:52 PM, daly d...@axiom-developer.org wrote: On Thu, 2011-10-27 at 20:11 -0400, Larry Johnson wrote: My two favorite articles on Literate Programming are both from Donald Knuth's book Literate Programming. One is Computer Programming as an Art, and the other is Literate Programming. When I was preparing to interview Knuth a bit over a year ago I re-read the entire book. I expected it to be a somewhat outdated description of WEB, TANGLE, and WEAVE. On the contrary it was wonderfully timeless. When I mentioned that to Knuth he sort of grumbled something to the effect of Well, yes, some things in computer science have a long shelf life (that's a paraphrase, but it was something like that). Knuth's invention of literate programming is one of the unrecognized pearls of computer science. I have yet to see a programming team that has an Editor-in-Chief who does patch-review for clarity, sentence structure, punctuation, relevance, location in the book, proper citations and index terms, etc. Maybe someday. I haven't been working with it for awhile, but I did a somewhat primitive modification to the XML Docbook markup language (I just added a few appropriate tags for tangling the executable source code, and weaving the well formatted article documenting the code) which I used as the source language, then wrote a tangle and weave in perl. I got the idea from Norman Walsh's article Literate Programming in XML which can be found at http://nwalsh.com/docs/articles/xml2002/lp/paper.html The advantage of this was that given the array of tools for rendering Docbook weaving was a piece of cake, and perl had a good range of modules for doing the tangle. Any means of publication can be the medium for literate programming. As I rule I prefer Latex but anything will do. All you need is a distinguished means of quoting and naming the chunks. In html this could be as simple as: pre id=somename your code /pre and you need a program, often called tangle, to extract the chunk tangle mywebpage.html somename mysomename.file The machinery of literate programming is dirt simple. Poof! You're done. The hardest part of literate programming is the mindset. In order to do literate programming you need to change your focus from traditional programming to writing for humans and, as a side effect, writing for the machine. As I stated, I'm very new to clojure, but I've always been fascinated with LP, and I'm very happy to see this discussion going on here. Java has taken the PDP 11/40 sand files to their logical extreme where we have wired the name of the tiny file to the name of the tiny object. We have packaged the automobile into a crate with labeled bags of screws, hoses, switches, etc. and are expected to understand the car. Clojure is a very early adoptive, open minded community willing to challenge old assumptions. It helps to highlight what those old assumptions are, as Rich has done for Lisp, since they can be difficult to see and hard to displace. I am hoping the community will disrupt the tiny-files, javadoc, IDE, code-for-the-machine, mindset and start communicating with humans. Rich has great ideas in Clojure and all we get is the dried bones of source code. We can do so much better. Tim Daly -- You 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 -- You 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
documentation problem with Atom
Just wanted to report that the documentation for atom misspells become as be come --Robert McIntyre -- You 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: [noob] porting an old project - where to begin?
You might want to take a look at jMonkeyEngine (http://jmonkeyengine.org/) It's a 3D java screengraph library with quite good performance. I've found it to be fun to use in the past, and it has a good userbase and lots of tutorials online. Even if it's not what you want exactly, many people have tried to use it for a pseudo 2D/3D sort of game and if anyone could tell you what really works in java/clojure it's the people on the message boards there. sincerely, --Robert McIntyre On Sat, Jun 4, 2011 at 3:24 AM, Daniel doubleagen...@gmail.com wrote: I suppose the noob tag is appropriate ie I was around sometime last year and earlier but RLing got in the way of doing anything useful with this lovely language. Anyway, I've got this old project (https://github.com/doubleagent/ Magic--legacy- ) which I've recently gained a renewed interest in, and simultaneously am less concerned about the potential legal issues which made me disinterested enough to drop it 4 years ago. I'm proud that it still builds and runs, but don't take the readme too seriously, and I highly doubt the perl scripts work anymore. The intent was to write a program which assisted MTG (Magic: The Gathering) players by providing them with robust deck building tools and a way to compete over a network using the honor system. Several features are still unimplemented, and some were removed in this version because the java2d worked too poorly to accommodate them. I'd like to port it to Clojure, but in the process I'd also like to solve some fundamental problems. More specifically, real estate. In a real game you would not be able to see any of the cards in great detail, but get an overall view of the board, and be able to inspect cards more closely by zooming and panning (over the whole board - I find Wotc's way of zooming on individual cards undesirable). This is even more critical when there are a lot of cards on the field eg some decks can blast tokens onto the field which number into the hundreds. I'm unsure how to approach this core problem in Clojure. clj- processing looks interesting, but I would prefer something more high level b/c 3d graphics is difficult for me to wrap my head around. In particular, mapping a mouse click to the nearest movable object in 3d space and ensuring proper draw updates on the object with dragging *head asplode* But I'm sure to be missing plenty. Suggestions? -- You 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 -- You 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: Get digits of a number
I normally use (defn digits [n] (map #(Integer/parseInt (str %)) (seq (str n You can adapt it to read in different bases easily. sincerely, --Robert McIntyre On Thu, Feb 17, 2011 at 9:45 PM, Matthew Boston matthew.bos...@gmail.com wrote: How about using the Java api Character/getNumbericValue, like so: (defn explode-to-digits [number] (map #(Character/getNumericValue %) (str number))) user = (explode-to-digits 12345) (1 2 3 4 5) On Feb 17, 4:45 pm, Mike Meyer m...@mired.org wrote: On Thu, 17 Feb 2011 15:27:47 -0600 Michael Gardner gardne...@gmail.com wrote: On Feb 17, 2011, at 1:36 PM, Mike Meyer wrote: My turn... (defn to-digits Create a seq of digits from a number. [i] ^{:user/comment For Euler Problems (Specifically 16)} (map {\0 0 \1 1 \2 2 \3 3 \4 4 \5 5 \6 6 \7 7 \8 8 \9 9} (str i))) Why not use Character/digit, as Saul suggested? Because I'm not a java programmer, so my natural inclination is to use Clojure tools (like the hashmap) rather than Java tools. Since I hadn't seen a solutions using the hashamp - but had seen some more complex variants - I thought this one might be of interest. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Software developer/SCM consultant, email for more information. O ascii ribbon campaign - stop html mail -www.asciiribbon.org -- You 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 -- You 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: Matrix transform
Could you possibly put up a minimal example of code that shows the problem? I'm having a hard time following exactly what you're doing but would like to help. :) sincerely, --Robert McIntyre On Fri, Feb 4, 2011 at 10:20 AM, Nick npatric...@gmail.com wrote: I've got a matrix transformation that I'm doing which is really slow. I'm looking for ways to speed it up. source is a NxD matrix (seqs of seqs of values). I will set and read this matrix. dest is a NxN transformation of f in which indices are mapped to specific indices of f. I will only read this matrix, not set it. If I place a value in one cell of source, it may show up in 30 other places in dest due to a mapping function. I then use dest for some simple matrix operations. The mapping that I use is generated once, however it has to be applied to the source very frequently. Is there any way I could define dest with memory locations that correspond to the mapped locations of source? This would allow me to define the mapping once. Subsequently I could simply set source and read dest with the changes already propagated. I've thought about using seqs of seqs of refs in source, then assigning those same refs to the mapped locations of dest, but I'm not sure if there is some other overhead hit I would take from setting and reading the refs. What is the right solution? -- You 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 -- You 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: Transpose
That's a good one, on par with the one line low-pass filter: ;; filter noise ;;(http://clojure-log.n01se.net/date/2009-10-13.html by ambient ;;this is such a cool transform!!! (defn lo-pass [d coll] (reductions #(+ (* %2 d) (* %1 (- 1.0 d))) coll)) sincerely, --Robert McIntyre On Thu, Feb 3, 2011 at 4:46 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Feb 3, 2011 at 4:33 PM, Base basselh...@gmail.com wrote: Thats the one! Now I just have to understand it... The first apply is throwing me a little. Start with (map foo [1 2 3] [4 5 6] [7 8 9]) That calls foo with the first elements of the collections (so, 1 4 7), then again with the second (2 5 8), and then the third (3 6 9). Now, if foo is vector the return values will be [1 4 7], [2 5 8], and [3 6 9]. Which are the rows of your transposed matrix. (apply map vector matrix) does (map foo row1 row2 row3) in the case of a three-row matrix, for instance, and more generally should extract the columns of any matrix. (vec ...) wrapped around it converts the seq return value into a vector. Note that (vec '(1 2 3)) = [1 2 3]; (vector 1 2 3) = [1 2 3], i.e. (vec foo) = (apply vector 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 -- You 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
question about gen-class
I was recently using gen-class and ran into this problem: (def strcat (partial apply str)) (defn rev-reverse [s] (strcat (reverse s))) (defn rev-reverseWords [s] (strcat (interpose (reverse (.split s ) (defn rev-isWordPalindrome [s] (if (nil? s) true (= s (rev-reverseWords s (gen-class :name functional.Scrambler :methods [#^{:static true} [reverse [String] String] #^{:static true} [reverseWords [String] String] #^{:static true} [isWordPalindrome [String] Boolean]] :prefix rev-) when I call Scrambler.isWordPalindrome(null) I get a null pointer error. How can I make a null safe function with gen-class? sincerely, --Robert McIntyre -- You 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 to disallow unlisted optional argument keys?
You win sir. That is the most beautiful way. sincerely, --Robert McIntyre On Sun, Jan 30, 2011 at 7:59 PM, Bill James w_a_x_...@yahoo.com wrote: Alexander Yakushev wrote: Why not use a constraint? It looks much cleaner. (defn hello [ {:keys [a b] :as input}] {:pre [(= (set (keys input)) #{:a :b})]} hello) You can learn more about constraints here: http://vimeo.com/channels/fulldisclojure#8399758 {:pre [(clojure.set/subset? (set (keys input)) #{:a :b})]} -- You 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 -- You 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: Ridiculously massive slowdown when working with images
That's excellent. Thank you everyone. Maybe someone could compile all these let's speed up this clojure code threads and put it somewhere as a valuable resource we could point to when things like this come up again? sincerely, --Robert McIntyre On Sun, Jan 30, 2011 at 1:01 PM, David Nolen dnolen.li...@gmail.com wrote: On Sat, Jan 29, 2011 at 10:37 AM, GrumpyLittleTed grumpylittle...@gmail.com wrote: Part of the difference (under 1.2) is due to the (substantial) overhead of accessing the buffer-size var on every iteration. I ran a quick check and using David's version of the code result averaged 17.2ms. Just changing buffer-size to a local with using (let [buffer-size (int 192)]...) the time dropped to an average 3.4ms. Yes, putting buffer-size in a let makes the performance in 1.3.0 identical to Java with long loop arithmetic. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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 to disallow unlisted optional argument keys?
you could do something like this, but I'm curious --- why do you want to restrict the function's inputs in this way? (defn hello [ {:keys [a b] :as input}] (assert (= (set (keys input)) #{:a :b})) hello) sincerely, --Robert McIntyre On Sat, Jan 29, 2011 at 1:19 PM, Shantanu Kumar kumar.shant...@gmail.com wrote: Hi, Given this example: (defn hello [ {:keys [a b]}] hello) = (hello :foo bar) ; :foo isn't listed! hello How can I disallow all keys except :a and :b in this example? Regards, Shantanu -- You 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 -- You 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 to disallow unlisted optional argument keys?
I see, so you wanted to allow some subset of the optional arguments. Might I recommend the following? Sets are already functions that check for inclusion of the objects on which you call them, so instead of (contains? some-set ele) just (some-set ele) will work. Also, upon actually making a typo you just get the statement that (contains? #{:a :b} each) has failed, while I think it would be nicer if it actually showed the offending misspelled keyword. Unfortunately implementing this proved harder than I expected and the best I could come up with was: (defn hello [ {:keys [a b] :as input}] (dorun (map #(eval `(assert (#{:a :b} (quote ~% (keys input))) hello) I'd be curious what the right way to to this is. sincerely, --Robert McIntyre On Sat, Jan 29, 2011 at 4:15 PM, Shantanu Kumar kumar.shant...@gmail.com wrote: On Jan 30, 1:26 am, Robert McIntyre r...@mit.edu wrote: you could do something like this, but I'm curious --- why do you want to restrict the function's inputs in this way? As they are optional arguments, it's possible that somebody might misspell a key and spend time debugging. The intention is to avoid that. (defn hello [ {:keys [a b] :as input}] (assert (= (set (keys input)) #{:a :b})) hello) Thanks, I realized I need something like the following: (defn hello [ {:keys [a b] :as input}] (doseq [each (keys input)] (assert (contains? #{:a :b} each))) hello) Regards, Shantanu -- You 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 -- You 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
Ridiculously massive slowdown when working with images
I tried to convert this java code line for line to clojure to compare the speed differences, and boy was I surprised! public static void ConvertToAWT(byte[] cpuArray){ // Given an array of bytes representing a c-style bgra image, // converts to a java style abgr image int len = java.lang.reflect.Array.getLength(cpuArray); for (int i = 0; i len; i+=4){ byte b = cpuArray[i+0]; byte g = cpuArray[i+1]; byte r = cpuArray[i+2]; byte a = cpuArray[i+3]; cpuArray[i+0] = a; cpuArray[i+1] = b; cpuArray[i+2] = g; cpuArray[i+3] = r; }} (defn java-like [] (loop [i (int 0)] (if ( i buffer-size) (let [ + clojure.core/unchecked-add b (aget cpuArray i) g (aget cpuArray (+ 1 i)) r (aget cpuArray (+ 2 i)) a (aget cpuArray (+ 3 i))] (aset-byte cpuArray i a) (aset-byte cpuArray (+ 1 i) b) (aset-byte cpuArray (+ 2 i) g) (aset-byte cpuArray (+ 3 i) r) (recur (int (+ i 4))) (defn clojure-like [] (doall (flatten (map (fn [[b g r a]] [a b g r]) (partition 4 4 cpuArray) for a byte-array of size 192, the java-like clojure function, a line for line translation, takes several minutes, while the java method takes around 3 milliseconds. the clojure-like one takes 6 seconds. Why is the clojure function so much more obnoxiously slow than its java counterpart? Can anyone shed some light on what I'm doing wrong? sincerely, --Robert McIntyre -- You 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: Ridiculously massive slowdown when working with images
And the plot thickens: This: (defn convert-image [#^bytes cpuArray] (let [unchecked-add clojure.core/unchecked-add len (int (count cpuArray))] (loop [i (int 0)] (if ( i len) (let [ b (byte (aget cpuArray i)) g (byte (aget cpuArray (unchecked-add 1 i))) r (byte (aget cpuArray (unchecked-add 2 i))) a (byte (aget cpuArray (unchecked-add 3 i)))] (aset-byte cpuArray i a) (aset-byte cpuArray (unchecked-add 1 i) b) (aset-byte cpuArray (unchecked-add 2 i) g) (aset-byte cpuArray (unchecked-add 3 i) r) (recur (int (unchecked-add i 4 vs this. (defn convert-image [#^bytes cpuArray] (let [len (java.lang.reflect.Array/getLength cpuArray)] (loop [i (int 0)] (if ( i len) (let [i2 (unchecked-add 1 i) i3 (unchecked-add 2 i) i4 (unchecked-add 3 i) b (byte (aget cpuArray i)) g (byte (aget cpuArray i2)) r (byte (aget cpuArray i3)) a (byte (aget cpuArray i4))] (aset-byte cpuArray i a) (aset-byte cpuArray i2 b) (aset-byte cpuArray i3 g) (aset-byte cpuArray i4 r) (recur (unchecked-add i 4))) The first function takes forever; the second MUCH faster. Upon disassembling the byte-code of the two compiled functions, it does seem like the + was not being inlined. Since the method of reassignment doesn't preserve the metadata, this makes sense. However, my new, modified function is still around 20 times slower than the java version :( I still don't understand what's slowing me down, but I'm much happier that I can get within 20x of java instead of 2x thanks everyone. sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 1:07 PM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 28, 2011 at 12:55 PM, Benny Tsai benny.t...@gmail.com wrote: It seems that 'unchecked-add' returns a primitive (note that in the first version, 'recur' happily accepts the return from 'unchecked-add' without coercion), but when 'unchecked-add' is bound to a new name, the return gets boxed. Is this the correct interpretation, or am I missing something? It's correct. Clojure's compiler inlines certain functions, including clojure.core/unchecked-foo and, when the arity is 2, clojure.core/+ -- but not a bare, un-qualified +, which might (or might not) at runtime refer to clojure.core/+ or clojure.core/unchecked-add or whatever. -- You 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 -- You 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: Ridiculously massive slowdown when working with images
David, thanks for your suggestions. I copied your code and tested it out, but on my machine it takes 230 milliseconds while the java version takes about 3. If it's not too much trouble, how long does the java implementation take on your machine? sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 2:11 PM, David Nolen dnolen.li...@gmail.com wrote: On Fri, Jan 28, 2011 at 2:01 PM, Aaron Cohen aa...@assonance.org wrote: On Fri, Jan 28, 2011 at 1:55 PM, David Nolen dnolen.li...@gmail.com wrote: As a comparison, the following accomplishes the same thing in 1.3.0. (ns test) (set! *unchecked-math* true) (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defn java-like [^bytes cpuArray] (loop [i (int 0)] Is this hint still necessary on 1.3.0? The int cast on 0 was an oversight on my part. It's not necessary. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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: Help with Java arrays
On my computer this seemed to work. (import 'javax.sound.midi.Synthesizer) (seq (.getChannels (MidiSystem/getSynthesizer))) (#MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1b793ee #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@15109cf #MixerMidiChannel com.sun.media.sound.MixerMid\ iChannel@15b0933 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1b910b0 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@f696c6 #MixerMidiChannel com.sun.medi\ a.sound.MixerMidiChannel@124a4bc #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@bb46b7 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@11fc4dd #MixerMidiChan\ nel com.sun.media.sound.MixerMidiChannel@b59a28 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@9bcf06 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@134b721 \ #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1e2e788 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1ceb175 #MixerMidiChannel com.sun.media.sound.MixerMidi\ Channel@e4b7d3 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1e09de7 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@19eb5f6) Maybe that's helpful :P I hope. good luck, --Robert McIntyre On Fri, Jan 28, 2011 at 11:59 AM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 28, 2011 at 11:30 AM, WoodHacker ramsa...@comcast.net wrote: Hi, I'm trying to get the midi sound class in Java to work in Clojure. Everything seems to work fine except for the conversion of the following Java code: MidiChannel[] channels = synthesizer.getChannels; I've tried just dumping the channels into a Clojure object - (let [channels (.getChannels @synthesizer)] but I get the following error: Exception in thread main java.lang.IllegalArgumentException: Can't call public method of non-public class: public javax.sound.midi.MidiChannel[] com.sun.media.sound.AbstractPlayer.getChannels() I don't think this is an array issue at all, but one to do with overload resolution and Clojure's use of reflection. Try hinting @synthesizer like this: (let [channels (.getChannels ^Synthesizer @synthesizer)] ...) and see if that makes it work. -- You 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 -- You 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: Help with Java arrays
oh and of course (import 'javax.sound.midi.MidiSystem) before everything. sorry about that. sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 2:47 PM, Robert McIntyre r...@mit.edu wrote: On my computer this seemed to work. (import 'javax.sound.midi.Synthesizer) (seq (.getChannels (MidiSystem/getSynthesizer))) (#MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1b793ee #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@15109cf #MixerMidiChannel com.sun.media.sound.MixerMid\ iChannel@15b0933 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1b910b0 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@f696c6 #MixerMidiChannel com.sun.medi\ a.sound.MixerMidiChannel@124a4bc #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@bb46b7 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@11fc4dd #MixerMidiChan\ nel com.sun.media.sound.MixerMidiChannel@b59a28 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@9bcf06 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@134b721 \ #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1e2e788 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1ceb175 #MixerMidiChannel com.sun.media.sound.MixerMidi\ Channel@e4b7d3 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@1e09de7 #MixerMidiChannel com.sun.media.sound.MixerMidiChannel@19eb5f6) Maybe that's helpful :P I hope. good luck, --Robert McIntyre On Fri, Jan 28, 2011 at 11:59 AM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 28, 2011 at 11:30 AM, WoodHacker ramsa...@comcast.net wrote: Hi, I'm trying to get the midi sound class in Java to work in Clojure. Everything seems to work fine except for the conversion of the following Java code: MidiChannel[] channels = synthesizer.getChannels; I've tried just dumping the channels into a Clojure object - (let [channels (.getChannels @synthesizer)] but I get the following error: Exception in thread main java.lang.IllegalArgumentException: Can't call public method of non-public class: public javax.sound.midi.MidiChannel[] com.sun.media.sound.AbstractPlayer.getChannels() I don't think this is an array issue at all, but one to do with overload resolution and Clojure's use of reflection. Try hinting @synthesizer like this: (let [channels (.getChannels ^Synthesizer @synthesizer)] ...) and see if that makes it work. -- You 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 -- You 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: Ridiculously massive slowdown when working with images
I'm running my JVM with: -verbose:gc -Xmn500M -Xms2000M -Xmx2000M -server sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 4:24 PM, Benny Tsai benny.t...@gmail.com wrote: Hi Robert, Just out of curiosity, are you running Clojure with the -server option? When I run David's code, -server mode cuts the time for the first run by half, and the time for subsequent runs by a factor of 5. On Jan 28, 12:36 pm, Robert McIntyre r...@mit.edu wrote: David, thanks for your suggestions. I copied your code and tested it out, but on my machine it takes 230 milliseconds while the java version takes about 3. If it's not too much trouble, how long does the java implementation take on your machine? sincerely, --Robert McIntyre On Fri, Jan 28, 2011 at 2:11 PM, David Nolen dnolen.li...@gmail.com wrote: On Fri, Jan 28, 2011 at 2:01 PM, Aaron Cohen aa...@assonance.org wrote: On Fri, Jan 28, 2011 at 1:55 PM, David Nolen dnolen.li...@gmail.com wrote: As a comparison, the following accomplishes the same thing in 1.3.0. (ns test) (set! *unchecked-math* true) (set! *warn-on-reflection* true) (def buffer-size 192) (def array (byte-array buffer-size)) (defn java-like [^bytes cpuArray] (loop [i (int 0)] Is this hint still necessary on 1.3.0? The int cast on 0 was an oversight on my part. It's not necessary. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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 -- You 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 Quizzes?
Taking a page out of the python book , I like to include a statement at the end that checks to see if the program is being run as a command-line program and then respond accordingly. As an example, (if (command-line?) (your-awesome-function (read-integer (first *command-line-args* Might appear at the end of my file. command-line? and read-integer are listed below (ns coderloop.utils (:use [clojure.contrib [duck-streams :only [file-str read-lines]]]) (:use [clojure [string :only [trim blank? split]]])) (defn read-integer [file] (Integer/parseInt (trim (slurp (file-str file) (defn command-line? [] (.isAbsolute (java.io.File. *file*))) This has the advantage of also working when the namespace is being run on the command-line with no arguments, but not when the namespace is being used or required by another namespace. read-integer is just a simple example for how to read a single integer from a file. You can then actually run your program by making a shell script with something like #!/bin/bash java -Xmn500M -Xms2000M -Xmx2000M -server -cp ./lib/*:./src clojure.main your-namespace-file.clj $@ A little known fact is that the above can actually be embedded into a clojure source file with the following trick: Make this the first line of your clojure namespace to make it executable: :;exec java -verbose:gc -Xmn500M -Xms2000M -Xmx2000M -server -cp your-classpath clojure.main $0 $*; The trick is putting the :; at the beginning and then calling exec. To clojure this looks like a literal string followed by a comment. To bash it looks like a no-op followed by an invocation of java on the file itself, and no lines after the first ever get executed. You can make whatever class structure you cant and then just symlink the clojure file to be an executable file at the base of the directory. You can still always go the shell script route if you don't like the embedding trick. This technique is common with emacs-lisp to make things executable. Hope that helps. sincerely, --Robert McIntyre On Sun, Jan 16, 2011 at 9:56 PM, Stuart Campbell stu...@harto.org wrote: On 17 January 2011 13:48, John Svazic jsva...@gmail.com wrote: Benny already answered, but here's the common block that I'm using for my Clojure submissions: (import '(java.io BufferedReader FileReader)) (defn process-file [file-name] (let [rdr (BufferedReader. (FileReader. file-name))] (line-seq rdr))) (defn my-func [col] ; Do something interesting ) (println (my-func (process-file (first *command-line-args* Basically I read the lines of the file into a sequence, then process that sequence in my function. Since I'm only dealing with the first parameter passed to my script, a (first *command-line-args*) call is equivalent to args[0] in other languages like Java. If you include clojure.contrib.io, you could use read-lines: (defn read-lines Like clojure.core/line-seq but opens f with reader. Automatically closes the reader AFTER YOU CONSUME THE ENTIRE SEQUENCE. [f] (let [read-line (fn this [^BufferedReader rdr] (lazy-seq (if-let [line (.readLine rdr)] (cons line (this rdr)) (.close rdr] (read-line (reader f Regards, Stuart -- You 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 -- You 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 Quizzes?
Because there is a limit on the length of the shebang line to as short as 80 characters in some distributions (notably ubuntu), and the posix standard for the shebang line does not allow you to pass any arguments to the interperter to modify its behaviour --- so no classpath or anything else for you! Try it --- you'll see that the standard shebang line just doesn't work for most project setups. Embedding shell gets around all these problems. sincerely, --Robert McIntyre On Tue, Jan 18, 2011 at 12:03 AM, Alan a...@malloys.org wrote: On Jan 17, 7:42 am, Robert McIntyre r...@mit.edu wrote: You can then actually run your program by making a shell script with something like #!/bin/bash java -Xmn500M -Xms2000M -Xmx2000M -server -cp ./lib/*:./src clojure.main your-namespace-file.clj $@ A little known fact is that the above can actually be embedded into a clojure source file with the following trick: Make this the first line of your clojure namespace to make it executable: :;exec java -verbose:gc -Xmn500M -Xms2000M -Xmx2000M -server -cp your-classpath clojure.main $0 $*; The trick is putting the :; at the beginning and then calling exec. To clojure this looks like a literal string followed by a comment. To bash it looks like a no-op followed by an invocation of java on the file itself, and no lines after the first ever get executed. You can make whatever class structure you cant and then just symlink the clojure file to be an executable file at the base of the directory. You can still always go the shell script route if you don't like the embedding trick. This technique is common with emacs-lisp to make things executable. Instead of a trick, why not use the fact that clojure treats #! as a single-line comment? Then you can write your shebang line just like every other scripting language. -- You 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 -- You 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 dispatch on [[F ..
How about (def float-2D (class (make-array Float/TYPE 1 1)))? sincerely, --Robert McIntyre On Fri, Jan 14, 2011 at 4:07 AM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 14, 2011 at 3:53 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello Everybody, I would like to know how to have one of the multimethods dispatch on [[F (2d-array of float) .. I don't know how to say that in the code .. I can say Integer Double etc.. How do I say 2-d-array of floats? what is the literal representation of [[F... I am not sure if I am clear with my question .. I remember somebody had before used something like this .. but I am unable to find it right now... I don't think there is a literal representation, but you also don't need it to be literal: user= (defmulti foo #(vector (type %1) (type %2))) #'user/foo user= (defmethod foo [(type (make-array (type (float-array 0)) 0)) String] [x y] (println [[F and String)) #MultiFn clojure.lang.MultiFn@1a65cf7 user= (foo (make-array (type (float-array 0)) 0) foo) [[F and String nil There may still be a somewhat more elegant way of getting the type; I just promise that this way works. :) -- You 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 -- You 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 dynamically created namespaces, without on-disk source code?
On a related note, is there any way to completely clear all the bytecode that's being stored internally by the jvm, forcing it to fall back to the hard-disk version of the classfiles available on the classpath? sincerely, --Robert McIntyre On Tue, Jan 11, 2011 at 5:04 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: You would have to capture the source form of each definition before it's compiled. Not too hard if you hack the REPL a bit; someone has probably already worked on it. -S -- You 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 -- You 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 Quizzes?
As HTML-y as it it is, PHP is Turing complete and thus a real programming language. It's got foreach loops, mutable arrays, and boolean logic, and that's one particular set of operations to simulate a Turing machine. http://en.wikipedia.org/wiki/Turing_machine http://aturingmachine.com/ sincerely, --Robert McIntyre On Thu, Jan 13, 2011 at 10:07 PM, Ken Wesson kwess...@gmail.com wrote: On Thu, Jan 13, 2011 at 10:04 PM, John Svazic jsva...@gmail.com wrote: They do seem to allow whatever you like if you upload your own package. I'm hooked on using their built-in editor, so in some cases I copy-and-paste code until they get around to updating their version of Clojure. The one nice thing about the site is that they do seem rather responsive to questions, bugs and feature requests! I'm jsvazic on the site if anyone is interested. :-) Based on the list of recent submissions lately, it seems like Clojure is getting a lot of exposure! It's funny to see some language turf wars showing up, since I've seen Clojure dominate recent submissions list, then Scala gets a kick, then people go on a PHP binge for some reason. :-) PHP? Isn't that a web page generation engine, rather than a general-purpose application programming language? In any case, I'm finding the site absolutely great, and it's been an absolute boon for updating my Clojure skills. I fully expect that in the next 6 months I'll look back at earlier submissions and say what was I thinking?! :-) I think we all get that at first. It may be because functional/Lisp is somewhat alien to most other things you're likely to have had experience with beforehand, or just because C++ is to chess as Lisp is to go -- fewer moves and simpler rules, but oh so much depth as your Lisp-fu grows strong. -- You 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 -- You 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 Quizzes?
They seem to allow you to include anything in a lib directory that you'd want. I sometimes include apache commons-io and clojure-contrib1.2 without any problems. I also included a sql connection library for one of the problems, so it seems fine :) --Robert McIntyre On Thu, Jan 13, 2011 at 2:00 AM, Stuart Campbell stu...@harto.org wrote: On 12 January 2011 14:07, Robert McIntyre r...@mit.edu wrote: You can use the latest version of clojure if you include it as a dependency in your submission, so even though they say they only support clojure1.0 they really support all of them. Are other 3rd-party libs allowed, too? Cheers, Stuart -- You 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 -- You 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 Quizzes?
Coderloop is a lot of fun. I'm wondering how people are submitting their code? You can use the latest version of clojure if you include it as a dependency in your submission, so even though they say they only support clojure1.0 they really support all of them. I wrote a short clojure program that automatically packages a clojure namespace and it's particular minimal set of dependencies into a tar.bz2 file with the executable that they want. If anyone's interested, I'd love to hear his/her thoughts on this code. A few thoughts: Should it automatically AOT compile everything and package it all in an executable jar? Can I use a pure java implementation of bzip and tar without calling out to the system's tar command? (I'm bortreb on coderloop btw) sincerely, --Robert McIntyre On Tue, Jan 11, 2011 at 9:17 PM, Sean Corfield seancorfi...@gmail.com wrote: Ah, that does look like more fun - thanx for the link, hadn't heard of it before! On Wed, Jan 5, 2011 at 10:11 PM, benjamin.s.r benjamin.s.rho...@gmail.com wrote: http://coderloop.com/ like Project Euler but more modern -- You 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 -- You 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 Quizzes?
hurrr. teh codes are at https://gist.github.com/775623 sorry for leaving that out. I'm rather new at this; all criticisms are welcome. ---Robert McIntyre On Tue, Jan 11, 2011 at 10:07 PM, Robert McIntyre r...@mit.edu wrote: Coderloop is a lot of fun. I'm wondering how people are submitting their code? You can use the latest version of clojure if you include it as a dependency in your submission, so even though they say they only support clojure1.0 they really support all of them. I wrote a short clojure program that automatically packages a clojure namespace and it's particular minimal set of dependencies into a tar.bz2 file with the executable that they want. If anyone's interested, I'd love to hear his/her thoughts on this code. A few thoughts: Should it automatically AOT compile everything and package it all in an executable jar? Can I use a pure java implementation of bzip and tar without calling out to the system's tar command? (I'm bortreb on coderloop btw) sincerely, --Robert McIntyre On Tue, Jan 11, 2011 at 9:17 PM, Sean Corfield seancorfi...@gmail.com wrote: Ah, that does look like more fun - thanx for the link, hadn't heard of it before! On Wed, Jan 5, 2011 at 10:11 PM, benjamin.s.r benjamin.s.rho...@gmail.com wrote: http://coderloop.com/ like Project Euler but more modern -- You 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 -- You 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: Knuth's literate programming tangle function in Clojure
You may find http://blog.higher-order.net/2009/02/01/understanding-clojures-persistentvector-implementation/ useful for a clear explanation of PersistentVectors. Maybe even get in touch with the guy for an addition to the book? Thanks for your work on a literate clojure. sincerely, --Robert McIntyre On Fri, Jan 7, 2011 at 12:28 AM, Ken Wesson kwess...@gmail.com wrote: On Fri, Jan 7, 2011 at 12:07 AM, Tim Daly d...@axiom-developer.org wrote: Hmmm. I may have misunderstood your point. I thought you were suggesting writing code that is not part of the distribution in order to get a minimal running system and then working from that. If that is not what you're suggesting then I'm confused. No, I was just suggesting that the order of the material put the stuff in the distribution that's necessary to bootstrap a minimally functional repl first, culminating in the eval function and the command-line repl class, then flesh out the rest of Clojure's feature-set with the rest of the stuff in the distribution. No new code. The pamphlet sources are in a git repository so they are immutable. Wikis are fine for a lot of things but not for linearizing the ideas into a readable literate form. Books fulfill that role. I suggested *maybe* letting the wiki users try to decide, collectively, on a linearization; maybe that would prove workable and maybe not. If not, you'd have to linearize it yourself to make the book version. But if you're looking for section submissons and user proof-reading a wiki can at least organize that activity, and can provide seeds by having unwritten sections in there with just the source code that is to be explained. And without potential contributors maybe being put off by having to learn a whole extra set of tools (namely, github and whatever client software) and get a login at some site (github). Some might not have used git. A few might not have used any code repository system. A wiki on the other hand can be edited by anyone who can type stuff into a web form and can be configured not to require a login (ala Wikipedia itself). -- You 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 -- You 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: Knuth's literate programming tangle function in Clojure
Just discovered org-mode myself --- does anyone know of guide to using it with clojure for a total newbie? sincerely, --Robert McIntyre On Tue, Jan 4, 2011 at 9:57 AM, Hubert Iwaniuk neo...@kungfoo.pl wrote: Hi Seth, Yes I did play with org-mode + babel for clojure. It works great :-) Just make sure you are using latest and greatest of org-mode. Cheers, Hubert. On Tue, Jan 4, 2011 at 3:34 PM, Seth wbu...@gmail.com wrote: have you guys checked out org-mode + babel for emacs? This would be an excellent place to start to do literate programming. Interesting ideas ... maybe i will try this in my own code ... -- You 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 -- You 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 -- You 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: Knuth's literate programming tangle function in Clojure
the # is a reader macro for regexes. hope that helps, --Robert McIntyre On Tue, Jan 4, 2011 at 11:18 AM, Tim Daly d...@axiom-developer.org wrote: The latest version of clojure.pamphlet can build Clojure directly from the book. It dynamically builds the source tree from the book, runs tests, creates the pdf, and starts the REPL. At least in theory. I am stuck with running a couple tests. The only real change I've made to the sources is to make it fit a printable page which involves changing a line to make it shorter. I've run into a syntax for strings that I don't understand. The string #some string is used in the test files. The documentation on the reader does not list this as a possible input case. What does it mean? Once I cross this hurdle everything else works and I can post a new version for your experiments. Tim On 1/4/2011 10:49 AM, Hubert Iwaniuk wrote: I would say start here: http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html Cheers, Hubert On Tue, Jan 4, 2011 at 4:12 PM, Robert McIntyrer...@mit.edu wrote: Just discovered org-mode myself --- does anyone know of guide to using it with clojure for a total newbie? sincerely, --Robert McIntyre On Tue, Jan 4, 2011 at 9:57 AM, Hubert Iwaniukneo...@kungfoo.pl wrote: Hi Seth, Yes I did play with org-mode + babel for clojure. It works great :-) Just make sure you are using latest and greatest of org-mode. Cheers, Hubert. On Tue, Jan 4, 2011 at 3:34 PM, Sethwbu...@gmail.com wrote: have you guys checked out org-mode + babel for emacs? This would be an excellent place to start to do literate programming. Interesting ideas ... maybe i will try this in my own code ... -- You 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 -- You 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 -- You 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 -- You 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 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: The non-Enclojure Clojure plugin homepages are all rather hard to find.
I'll have to admit that when I started out using clojure I was confused as well with the google code page. It's hard to see what to do to get ccw on my eclipse. A nice, comforting website that looks like it was designed only for end-users would be helpful I think. Partly this is eclipse's fault for making it semi-difficult to install software. The front-end site you're proposing would have made it easier for me, at least. If you would like help making a nice-looking, simple front-end website for the time being I would be happy to help set up something easy. Let me know, and thanks for making a great plugin for eclipse. Sincerely, --Robert McIntyre On Mon, Jan 3, 2011 at 3:27 AM, Ken Wesson kwess...@gmail.com wrote: On Mon, Jan 3, 2011 at 1:25 AM, Sean Corfield seancorfi...@gmail.com wrote: On Sun, Jan 2, 2011 at 7:41 PM, Ken Wesson kwess...@gmail.com wrote: Because from its url it looks like it'll just be the code repository. It doesn't *seem* any more promising as the home page link than the github.com results you tend to get when you search for other Clojure-related material. Good feedback. Thanx. I guess I'm used to reading wikis on github as being the official project home pages but I can see your p.o.v. I'm a developer so I think it's reasonable to read about developer tools on developer sites but I'm getting the sense that a lot of people coming to Clojure are not coming from what might be called a 'traditional developer' background? Lots of people expect a project to have a sourceforge, github, Google Code, or similar page that isn't very end-user friendly because it's targeted at the developers and not the users, plus its own .com or whatever site (e.g., clojure.org) that serves as the home page for the generally interested public (often linking to sourceforge or wherever from the big friendly DOWNLOAD WINDOWS INSTALLER button, though). Point taken but I find it an interesting distinction given that the users of developer tools like CCW are developers :) Yes, but they are developers of something else, not of CCW itself; CCW's source code may not interest them very much. You're interested in the developer-centric pages for projects you're actually developers on. I would be surprised to find very many coders very interested in such pages for most of the stuff they just use, though (or to have time to be!). And if ANYONE starting out using a new, sizable and complex piece of software doesn't want to start first as a normal user with user-oriented introductory texts, installers/packages that are turn-key, etc. and *maybe* graduate to digging deeper into the project's internals, perhaps contributing patches, etc. *later*. Perhaps *much* later, and time and interest permitting. However, as someone involved with an free open source CFML engine who is faced with a large number of Windows developers who expect simple click-click-done installers, I think I can understand where you're coming from... Yes. I'm sure they're much more interested in developing their CFML-using projects than in developing CFML itself. Some (many?) may be being paid to develop their CFML-using projects, but aren't being paid to develop CFML itself (though they may wind up contributing to CFML at some point, especially where doing so may pay dividends later in making their own project-development easier down the line). So if CounterClockWise had its own domain website that pointed to the Google repo and the wiki and the Assembla wiki (where all the other IDE plugins are documented), you'd be mollified? Certainly. But it's not about mollifying me; it's about making it friendlier to the potentially large number of potential new users who might be put off by not seeing any promising-enough-looking starting-point in their google results. The domain's root URL could even just redirect to whichever project page at code.google.com has the for-end-users home page of the project, so long as the combination of the domain name and the SERP synopsis made the google hit clearly the starting point for prospective new users, and the google hit ranked highly (preferably #1) for reasonably narrowly targeted queries aimed at finding Counterclockwise's home on the web. -- You 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 -- You 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
Re: Compiling dynamically created namespaces, without on-disk source code?
the `(binding [*compile-files* true] ...)` trick does not seem to work for me. Still looking for something that does. What do you mean by the bytecode is no longer accessible ? Wouldn't it have to be in there somewhere in order to use the definition? thank you, --Robert McIntyre On Thu, Dec 30, 2010 at 8:45 PM, Stuart Sierra the.stuart.sie...@gmail.com wrote: You might try `(binding [*compile-files* true] ...)` around whatever code creates the namespace. Can't promise that will work. This still won't let you save definitions entered at the REPL. Once they're compiled and loaded into the JVM, the bytecode is no longer accessible. -Stuart Sierra clojure.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 -- You 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 Small Pieces -- Literate Clojure
This looks very cool, and the opportunities for fully exploiting the power of a cross-referenced book format are very appealing Might I suggest two possible improvements: 1) Colored syntax highlighting for all clojure code. 2) Cross references for every clojure symbol used in the code --- I'd love to be able to click on + anywhere in the document and have it bring me to the proper section in the book discussing the arithmetic operators. Page 971 looks like it still overflows a bit :) I agree that some of the java parts of clojure were definitely developed on very large screens. Thanks for starting on this; best of luck, Sincerely, --Robert McIntyre On Fri, Dec 31, 2010 at 2:07 AM, Mark Engelberg mark.engelb...@gmail.com wrote: I find this exciting! Thanks for starting this. -- You 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 -- You 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: an object of class created using defrecord does not implement IFn .. while it behaves very similar to map otherwise ..
Be sure to also implement the version of get which takes a not-found argument so that your objects will work with map code which uses this functionality. (defrecord map-like-object [field-1 field-2 etc] clojure.lang.IFn (invoke [this k] (get this k)) (invoke [this k not-found] (get this k not-found))) sincerely, --Robert McIntryre On Fri, Dec 31, 2010 at 11:04 AM, Alyssa Kwan alyssa.c.k...@gmail.com wrote: Generating readable code for IDEs is not a good reason. You should think carefully about variable capture and decide which you want. Usually, in a macro-generated defn, I do want to capture the parameters, so I would use ~'this. On Dec 30, 11:54 pm, André Thieme splendidl...@googlemail.com wrote: Am 31.12.2010 03:29, schrieb Alex Baranosky: I've been playing with making a macro to encapsulate Stuart's post, like this: (defmacro defrecord-ifn [name args] `(defrecord ~name ~...@args clojure.lang.IFn (invoke [this key] (get this key (defrecord-ifn Foo [a b c]) (def foo (Foo. A B C)) (prn (map foo [:a :c])) = (A, C) I get the error: No such var: user/this. I guess this is because it is expanding 'this' to 'user/this'. What is the proper way to get a macro like this to expand properly? Others have already pointed to this# . I just would like to add that you can as well use ~'this in some cases, where your macros generate defns. The advantage is that some editors (like emacs) will show you the parameter vector and that would show a useful name and not this_auto_foobarbaz123456 . -- You 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 -- You 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: printf output from threads
seems there's no type hint required: (def t nil) (Thread. t) also works... How are you able to determine that it's calling the String constructor? --Robert McIntyre On Tue, Dec 28, 2010 at 3:08 AM, Alex Osborne a...@meshy.org wrote: Robert McIntyre r...@mit.edu writes: what the heck... mailing-list.print-from-threads (Thread. ((constantly nil))) #Thread Thread[Thread-100,5,main] mailing-list.print-from-threads (Thread. ((fn []))) #Thread Thread[Thread-101,5,main] mailing-list.print-from-threads (Thread. ((fn [] nil))) #Thread Thread[Thread-102,5,main] mailing-list.print-from-threads (Thread. (let [this-is-nil ((fn [] nil))] this-is-nil)) #Thread Thread[Thread-103,5,main] mailing-list.print-from-threads (Thread. nil) ; Evaluation aborted. mailing-list.print-from-threads (= nil (let [this-is-nil ((fn [] nil))] this-is-nil) ((fn [])) ((constantly nil))) true mailing-list.print-from-threads all of these things are referentially transparent, so how is clojure differentiating between things that evaluate to nil and nil itself? It's picking the Thread(String name), constructor for some reason when it gets an Object type hint. user (let [^Object o nil] (Thread. o)) #Thread Thread[Thread-8,5,main] -- You 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 -- You 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: printf output from threads
Your problem is caused by one itty-bitty misplaced parenthesis that is hard to catch; In your code which creates threads, you do: (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand-int 5000))) #(sleeper-thread %1 %2 %3) is exactly the same as just sleeper-thread, so this boils down to (.start (Thread. (sleeper-thread out x (+ 2000 (rand-int 5000))) and now you can see that you are evaulating your sleeper-thread function before you actually create the thread. Thread wants Runnable object like a clojure function with no arguments, so either (.start (Thread. #(sleeper-thread out x (+ 2000 (rand-int 5000))) or (.start (Thread. (partial sleeper-thread out x (+ 2000 (rand-int 5000))) would work and do what you expect. Here's a modified version of your code with output: (ns mailing-list.print-from-threads) (defn sleeper-thread [out id t] Sleep for time T ms (binding [*out* out] (let [start (System/nanoTime)] (printf %d sleeping for time %d\n id t) (Thread/sleep t) (printf %d slept for %d\n id (int (/ (- (System/nanoTime) start) 1e6)) (defn test-threads-rlm [n out] (let [start (System/nanoTime)] (dotimes [x n] (.start (Thread. (partial sleeper-thread out x (+ 2000 (rand-int 5000)) (println Total time is: (int (/ (- (System/nanoTime) start) 1e6) (defn test-threads [n out] (let [start (System/nanoTime)] (dotimes [x n] (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand-int 5000)) (println Total time is: (int (/ (- (System/nanoTime) start) 1e6) mailing-list.print-from-threads (test-threads-rlm 4 *out*) 0 sleeping for time 6783 1 sleeping for time 3716 2 sleeping for time 6890 Total time is: 2 3 sleeping for time 5582 1 slept for 3716 3 slept for 5582 0 slept for 6783 2 slept for 6890 nil mailing-list.print-from-threads (test-threads 4 *out*) 0 sleeping for time 5875 0 slept for 5875 1 sleeping for time 3413 1 slept for 3413 2 sleeping for time 3709 2 slept for 3710 3 sleeping for time 5483 3 slept for 5484 Total time is: 18486 nil mailing-list.print-from-threads However, I am vexed at how your original code works at all! look at this! --- ;;works (Thread. (#(sleeper-thread %1 %2 %3) *out* 2 (+ 2000 (rand-int 5000 (= nil (#(sleeper-thread %1 %2 %3) *out* 2 (+ 2000 (rand-int 5000 ;;true ;;doesn't work (Thread. nil) ;;works (Thread. ((fn [a b c] (sleeper-thread a b c)) *out* 2 (+ 2000 (rand-int 5000 ;;works (Thread. ((fn []))) How can you make a Thread with ((fn [])) when (= ((fn [])) nil) sincerely, --Robert McIntyre On Tue, Dec 28, 2010 at 1:45 AM, justinhj justi...@gmail.com wrote: On Dec 26, 11:42 pm, Alex Osborne a...@meshy.org wrote: justinhj justi...@gmail.com writes: I tried passing *out* to my thread function and then binding it to *out* in the thread, and this works but then makes the threads execute one at a time, and I'm presuming that is because my use of *out* in the binding block is blocking for the other threads which use it. That doesn't sound right: binding itself never blocks. Can you post some example code where you see this behaviour? As I understand it binding conveyance should happen automatically in the upcoming 1.3 release (for futures and agents) but in 1.2 you can use bound-fn, or for better performance use binding explicitly as you suggested. (future-call (bound-fn [] (println log...))) (send some-agent (bound-fn [x] (println log...) (inc x))) This is the code I've written so far (defn sleeper-thread [out id t] Sleep for time T ms (binding [*out* out] (printf %d sleeping for time %d\n id t) (Thread/sleep t) (printf %d slept\n id))) (defn test-threads [n out] (dotimes [x n] (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand- int 5000))) And the output is 0 sleeping for time 5480 0 slept 1 sleeping for time 6739 1 slept 2 sleeping for time 5444 2 slept 3 sleeping for time 3087 3 slept 4 sleeping for time 6753 4 slept 5 sleeping for time 3489 5 slept 6 sleeping for time 5864 6 slept 7 sleeping for time 5523 7 slept 8 sleeping for time 5659 8 slept 9 sleeping for time 5052 9 slept -- You 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 -- You 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
Re: printf output from threads
what the heck... mailing-list.print-from-threads (Thread. ((constantly nil))) #Thread Thread[Thread-100,5,main] mailing-list.print-from-threads (Thread. ((fn []))) #Thread Thread[Thread-101,5,main] mailing-list.print-from-threads (Thread. ((fn [] nil))) #Thread Thread[Thread-102,5,main] mailing-list.print-from-threads (Thread. (let [this-is-nil ((fn [] nil))] this-is-nil)) #Thread Thread[Thread-103,5,main] mailing-list.print-from-threads (Thread. nil) ; Evaluation aborted. mailing-list.print-from-threads (= nil (let [this-is-nil ((fn [] nil))] this-is-nil) ((fn [])) ((constantly nil))) true mailing-list.print-from-threads all of these things are referentially transparent, so how is clojure differentiating between things that evaluate to nil and nil itself? sincerely, --Robert McIntyre On Tue, Dec 28, 2010 at 2:29 AM, Robert McIntyre r...@mit.edu wrote: Your problem is caused by one itty-bitty misplaced parenthesis that is hard to catch; In your code which creates threads, you do: (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand-int 5000))) #(sleeper-thread %1 %2 %3) is exactly the same as just sleeper-thread, so this boils down to (.start (Thread. (sleeper-thread out x (+ 2000 (rand-int 5000))) and now you can see that you are evaulating your sleeper-thread function before you actually create the thread. Thread wants Runnable object like a clojure function with no arguments, so either (.start (Thread. #(sleeper-thread out x (+ 2000 (rand-int 5000))) or (.start (Thread. (partial sleeper-thread out x (+ 2000 (rand-int 5000))) would work and do what you expect. Here's a modified version of your code with output: (ns mailing-list.print-from-threads) (defn sleeper-thread [out id t] Sleep for time T ms (binding [*out* out] (let [start (System/nanoTime)] (printf %d sleeping for time %d\n id t) (Thread/sleep t) (printf %d slept for %d\n id (int (/ (- (System/nanoTime) start) 1e6)) (defn test-threads-rlm [n out] (let [start (System/nanoTime)] (dotimes [x n] (.start (Thread. (partial sleeper-thread out x (+ 2000 (rand-int 5000)) (println Total time is: (int (/ (- (System/nanoTime) start) 1e6) (defn test-threads [n out] (let [start (System/nanoTime)] (dotimes [x n] (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand-int 5000)) (println Total time is: (int (/ (- (System/nanoTime) start) 1e6) mailing-list.print-from-threads (test-threads-rlm 4 *out*) 0 sleeping for time 6783 1 sleeping for time 3716 2 sleeping for time 6890 Total time is: 2 3 sleeping for time 5582 1 slept for 3716 3 slept for 5582 0 slept for 6783 2 slept for 6890 nil mailing-list.print-from-threads (test-threads 4 *out*) 0 sleeping for time 5875 0 slept for 5875 1 sleeping for time 3413 1 slept for 3413 2 sleeping for time 3709 2 slept for 3710 3 sleeping for time 5483 3 slept for 5484 Total time is: 18486 nil mailing-list.print-from-threads However, I am vexed at how your original code works at all! look at this! --- ;;works (Thread. (#(sleeper-thread %1 %2 %3) *out* 2 (+ 2000 (rand-int 5000 (= nil (#(sleeper-thread %1 %2 %3) *out* 2 (+ 2000 (rand-int 5000 ;;true ;;doesn't work (Thread. nil) ;;works (Thread. ((fn [a b c] (sleeper-thread a b c)) *out* 2 (+ 2000 (rand-int 5000 ;;works (Thread. ((fn []))) How can you make a Thread with ((fn [])) when (= ((fn [])) nil) sincerely, --Robert McIntyre On Tue, Dec 28, 2010 at 1:45 AM, justinhj justi...@gmail.com wrote: On Dec 26, 11:42 pm, Alex Osborne a...@meshy.org wrote: justinhj justi...@gmail.com writes: I tried passing *out* to my thread function and then binding it to *out* in the thread, and this works but then makes the threads execute one at a time, and I'm presuming that is because my use of *out* in the binding block is blocking for the other threads which use it. That doesn't sound right: binding itself never blocks. Can you post some example code where you see this behaviour? As I understand it binding conveyance should happen automatically in the upcoming 1.3 release (for futures and agents) but in 1.2 you can use bound-fn, or for better performance use binding explicitly as you suggested. (future-call (bound-fn [] (println log...))) (send some-agent (bound-fn [x] (println log...) (inc x))) This is the code I've written so far (defn sleeper-thread [out id t] Sleep for time T ms (binding [*out* out] (printf %d sleeping for time %d\n id t) (Thread/sleep t) (printf %d slept\n id))) (defn test-threads [n out] (dotimes [x n] (.start (Thread. (#(sleeper-thread %1 %2 %3) out x (+ 2000 (rand- int 5000))) And the output is 0 sleeping for time 5480 0 slept 1 sleeping for time 6739 1 slept 2 sleeping for time 5444 2 slept 3 sleeping for time
Re: Knuth's literate programming tangle function in Clojure
That's really cool. I was _just reading_ your comments from 2006 at http://www.mail-archive.com/gardeners@lispniks.com/msg01006.html and wondering about how hard something like this would be to write. If possible, could you expand on how one might use this in a development work-flow with emacs or texmacs? Is there some sort of lisp-pamphlet mode that could be extended to clojure? I'm assuming you've already solved all these problems and more while working with Axiom. I'd appreciate any pointers or best practices you might have found. Thanks so much for your work! --Robert McIntyre On Sun, Dec 26, 2010 at 1:01 AM, Tim Daly d...@axiom-developer.org wrote: ; 0 AUTHOR and LICENSE ; 1 ABSTRACT and USE CASES ; 2 THE LATEX SUPPORT CODE ; 3 IMPORTS ; 4 THE TANGLE COMMAND ; 5 SAY ; 6 READ-FILE ; 7 ISCHUNK ; 8 HASHCHUNKS ; 9 EXPAND ; 10 TANGLE ;;; 0 AUTHOR and LICENSE ;;; Timothy Daly (d...@axiom-developer.org) ;;; License: Public Domain ;;; 1 ABSTRACT and USE CASES ;;; Don Knuth has defined literate programming as a combination of ;;; documentation and source code in a single file. The TeX language ;;; is documented this way in books. Knuth defined two functions ;;; tangle - extract the source code from a literate file ;;; weave - extract the latex from a literate file ;;; This seems unnecessarily complex. Latex is a full programming ;;; language and is capable of defining environments that can ;;; handle code directly in Latex. Here we define the correct environment ;;; macros. Thus, the weave function is not needed. ;;; If this tangle function were added to Clojure then Clojure could ;;; read literate files in Latex format and extract the code. We create ;;; the necessary tangle function here. ;;; This program will extract the source code from a literate file. ;;; A literate lisp file contains a mixture of latex and lisp sources code. ;;; The file is intended to be in standard latex format. In order to ;;; delimit code chunks we define a latex chunk environment. ;;; Latex format files defines a newenvironment so that code chunks ;;; can be delimited by \begin{chunk}{name} \end{chunk} blocks ;;; This is supported by the following latex code. ;;; So a trivial example of a literate latex file might look like ;;; (ignore the prefix semicolons. that's for lisp) ; this is a file that is in a literate ; form it has a chunk called ; \begin{chunk}{first chunk} ; THIS IS THE FIRST CHUNK ; \end{chunk} ; and this is a second chunk ; \begin{chunk}{second chunk} ; THIS IS THE SECOND CHUNK ; \end{chunk} ; and this is more in the first chunk ; \begin{chunk}{first chunk} ; \getchunk{second chunk} ; THIS IS MORE IN THE FIRST CHUNK ; \end{chunk} ; \begin{chunk}{all} ; \getchunk{first chunk} ; \getchunk{second chunk} ; \end{chunk} ; and that's it ;;; From a file called testcase that contains the above text ;;; we want to extract the chunk names second chunk. We do this with: ; (tangle testcase second chunk) ; which yields: ; THIS IS THE SECOND CHUNK ;;; From the same file we might extract the chunk named first chunk. ;;; Notice that this has the second chunk embedded recursively inside. ;;; So we execute: ; (tangle testcase first chunk) ; which yields: ; THIS IS THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ; THIS IS MORE IN THE FIRST CHUNK ;;; There is a third chunk called all which will extract both chunks: ; (tangle testcase all) ; which yields ; THIS IS THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ; THIS IS MORE IN THE FIRST CHUNK ; THIS IS THE SECOND CHUNK ;;; The tangle function takes a third argument which is the name of ;;; an output file. Thus, you can write the same results to a file with: ; (tangle testcase all outputfile) ;;; It is also worth noting that all chunks with the same name will be ;;; merged into one chunk so it is possible to split chunks in mulitple ;;; parts and have them extracted as one. That is, ; \begin{chunk}{a partial chunk} ; part 1 of the partial chunk ; \end{chunk} ; not part of the chunk ; \begin{chunk}{a partial chunk} ; part 2 of the partial chunk ; \end{chunk} ;;; These will be combined on output as a single chunk. Thus ; (tangle testmerge a partial chunk) ; will yield ; part 1 of the partial chunk ; part 2 of the partial chunk ;;; 2 THE LATEX SUPPORT CODE ;;; The verbatim package quotes everything within its grasp and is used to ;;; hide and quote the source code during latex formatting. The verbatim ;;; environment is built in but the package form lets us use it in our ;;; chunk environment and it lets us change the font. ;;; ;;; \usepackage{verbatim} ;;; ;;; Make the verbatim font smaller ;;; Note that we have
get the total memory used by a data structure?
I think it would be really cool to have a function that gives the total number of bytes that a data structure consumes. so something like: (total-memory [1 2 [1 2]]) would return however many bytes this structure is. Is there already something like this around? Would it be hard to write to work for any clojure data structure? just like (time), I think (total-memory) would be very enlightening for basic testing. sincerely, --Robert McIntyre -- You 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: defmethod/defmulti should dispatch on the new arguments when we call the recur..?
@Ken Wesson: do you mean something like this: https://gist.github.com/747571 My fists stab at this technique looks kinda ugly though... Is there a way to somehow embed the trampoline inside the recursive definition? Is there a way to get the actual dispatch function other than (.dispatchFn multimethod) ? --Robert McIntyre On Sun, Dec 19, 2010 at 10:52 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 19.12.2010 um 16:46 schrieb Ken Wesson: If we had a (resolve-method multi args) that resolved dispatch and then returned a fn that would call the method with those same args -- so ((resolve-method multi args)) = (multi args) -- then this could be used with trampoline in cases like Sunil is describing. It's called get-method. Sincerely Meikel -- You 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 -- You 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: about the repl
Well even if you don't like emacs it still serves as a decent repl :) Also if you don't like emacs you might try the eclipse counterclockwise plugin --- it has a nice repl too. good luck, --Robert McIntyre On Sat, Dec 18, 2010 at 2:56 AM, tor torgau...@gmail.com wrote: Thanks for the quick reply! I tried to get used to emacs a few years ago with little success. But I'm going to give it another try. -- You 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 -- You 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: Waiting for agents
That's brilliant. Has anyone considered targeting clojure for LaTeX3?Numerical support for one would be simplified, since LaTeX3 just uses actual rational numbers as its default instead longs or ints or whatever. This could be big, guys! --Robert McIntyre On Sat, Dec 18, 2010 at 12:19 PM, Ken Wesson kwess...@gmail.com wrote: On Sat, Dec 18, 2010 at 11:38 AM, Daniel Werner daniel.d.wer...@googlemail.com wrote: On 18 December 2010 16:29, Ken Wesson kwess...@gmail.com wrote: Once Java 7 is out is starting to seem like once LaTeX3 is out or Oh, you haven't heard the news yet? LaTeX3 has already been superseded anyway: http://river-valley.tv/tug-2010/an-earthshaking-announcement Are you crazy? I'm not watching a 34-minute video to find out what can surely be explained in a page or two of text that will take me two minutes to read. For the most part the online video revolution seems to be a good thing. But when long videos substitute for short text or HTML documents then there is a problem. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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: about the repl
The rlwrap method is very cool, but I can't seem to get ctrl-C to work (it still quits to the terminal) any advice? --Robert McIntyre On Sat, Dec 18, 2010 at 3:01 PM, Mike Meyer mwm-keyword-googlegroups.620...@mired.org wrote: On Fri, 17 Dec 2010 22:45:01 -0800 (PST) tor torgau...@gmail.com wrote: Is there a way to activate word completion in the repl? I find myself hitting tab all the time... Since nobody else mentioned it (or even offered a solution other than Try my environment), you can use rlwrap (should be available in your systems package manager) to run your repl, and get word completion - among other goodies one wants on a command line. The appropriate rlwrap invocation is: rlwrap --command clojure --complete-filenames --quote-characters='' --prompt-colour=Red followed by whatever command you use to start the repl. You'll also want to past this code into a repl running in your home directory: (def completions (reduce concat (map (fn [ns] (keys (ns-publics ns))) (all-ns (defn save-completions-to [filename] (with-open [f (java.io.BufferedWriter. (java.io.FileWriter. filename))] (.write f (apply str (interleave completions (repeat \n)) (save-completions-to .clojure_completions) to create the list of completions for rlwrap. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You 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 -- You 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: about the repl
That's really cool and has been added to my standard system stuff :) --Robert McIntyre On Sat, Dec 18, 2010 at 6:46 PM, Alex Osborne a...@meshy.org wrote: Stuart Sierra the.stuart.sie...@gmail.com writes: If your REPL implementation runs each command in a new Thread (as most of them do, I think) it can just stop the thread. That won't work in every situation (for example, a thread blocked waiting for I/O) but it will get you out of an infinite sequence. For just a plain command-line REPL on unix you can try running this before going into your infinite loop. Of course if something captures the ThreadDeath exception then it's not going to work. (sun.misc.Signal/handle (sun.misc.Signal. INT) (let [t (Thread/currentThread)] (proxy [sun.misc.SignalHandler] [] (handle [sig] (.stop t) Here's what it looks like when you hit Ctrl+C: user= (while true) ^Cjava.lang.ThreadDeath (NO_SOURCE_FILE:0) user= Under Emacs/Slime you can achieve the same thing by hitting C-c C-b (or M-x slime-interrupt). -- You 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 -- You 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: currying in clojure for fixed number of arg functions
I think your work is a wonderful idea. I've been wanting to do this myself for some time. Thanks for actually doing it instead of just thinking about it. I have some humble thoughts/suggestions after reading your code; I'd love to hear what you think about these points: 1. I think that auto-currying itself should be a higher order function, which a macro then makes easier to use. 2. Your def-curry-fn doesn't allow for easy embedding of metadata like defn does; it could take advantage of defn from core for all that. 3. Your def-curry-fn is similar in spirit to defn-memo from clojure.contrib.def, but it's hard to combine it with that macro to get both effects (both curried and memoized) I feel like this is asking for a higher level of abstraction of apply this unitary higher-order transform to the following definition than making a defn-higher-order-transform macro for every transform those type of functions are called decorators in some other languages. I've sketched out a hopefully enhanced version of your code here: https://gist.github.com/746185 While writing it, I found it convenient to extend the domain of partial to include a single argument. i.e. (= (partial f) f) I think it might be a good enhancement of the partial function, as it logically flows from the other airties. Do people think it would be a good patch for core? Please tell me what you think of my code :) All criticisms are welcome; I too am still learning. Sincerely, --Robert McIntyre On Fri, Dec 17, 2010 at 9:00 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: On Sat, Dec 18, 2010 at 7:21 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hi Eric, I do know about partial. But what I am saying is that the extra function, partial, is not necessary if the function was created with def-curry-fn... The function automatically returns a curried version when called with fewer number of arguments than necessary like it happens in haskell.. thanks, Sunil. On Sat, Dec 18, 2010 at 3:02 AM, Eric Schulte schulte.e...@gmail.com wrote: Hi Sunil, This is already possible using `partial' function in clojure core, which also works for variable arity functions, e.g. (map (partial reduce +) [[1 2 3 4] [5 6 7 8]]) Best -- Eric Sunil S Nandihalli sunil.nandiha...@gmail.com writes: Hello everybody, I remember that the key reasoning for not supporting currying in clojure was to be able to have variable number of arg functions.. So, I just thought a bit and realized that it should be possible to do that for fixed arity functions .. and then wrote the following macro to define a curry-able fixed-number-of-argument-function https://gist.github.com/745654 If the following was defined as (defn f [a b c d] (+ a b c d)) (def-curry-fn f [a b c d] (+ a b c d)) ((f 1) 2 3 4) = 10 the above s-expression using partial would become ... ((partial f 1) 2 3 4) = 10 (((f 1 2) 3) 4) = 10 and ((partial (partial f 1 2) 3) 4) = 10 instead of (((f 1 2) 3) 4).. f 1) 2) 3) 4) = 10 would become ((partial (partial (partial f 1) 2) 3) 4) = 10 . I know there is no real practical utility .. .. it was just something I wrote for fun.. and thought of sharing it ... Sunil. I just thought of sharing it with everybody. Would love to hear any criticisms you may have. Thanks for reading, Sunil -- You 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 -- You 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 -- You 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: about the repl
You can execute (set! *print-length* 20) to avoid traps with printing infinite data structures. I'd also highly recommend the emacs/swank combo for your repl. It's got tab completion and a lot more. try http://riddell.us/ClojureSwankLeiningenWithEmacsOnLinux.html to learn how to get started with emacs and clojure. Hope that helps, --Robert McIntyre On Sat, Dec 18, 2010 at 1:45 AM, tor torgau...@gmail.com wrote: Hi, I have a couple of questions. If I start listing an infinite sequence in the repl and the press ctrl-c, I always exit to bash. Is there a way to interrupt without exiting the repl? Is there a way to activate word completion in the repl? I find myself hitting tab all the time... I use the linux repl.sh if case that makes a difference thanks in advance -- You 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 -- You 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
eclipse and emacs?
I'm trying to move between emacs and eclipse, and was wondering the following: When I change code in eclipse, how do I get those changes to propagate to the repl without restarting? sorry if this is vague --Robert McIntyre -- You 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: eclipse and emacs?
Thanks for trying to help --- I know my first stab at this was vague so I'll try to be more clear this time. I have a java project in eclipse, and I'm using the clojure repl in emacs to try and debug the java. I've just but the special eclipse /bin folder for that project on the classpath so that I can get at the class files that are iteratively compiled by eclipse I have an object with a toString method which I'm munging in eclipse, and then I go to the repl in emacs and try to see my changes. But no matter what I do I can't see the changes I made in the toString function reflected in the repl. Neither reloading the namespace, reimporting the class, or doing a fill clean in eclipse changes anything. However, killing the jvm running the repl and restarting does work. Is there a less painful way to make the changes in eclipse on java code propogate to another repl in emacs outside eclipse? --Robert McIntyre On Wed, Dec 15, 2010 at 5:54 PM, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/12/15 Robert McIntyre r...@mit.edu I'm trying to move between emacs and eclipse, and was wondering the following: When I change code in eclipse, how do I get those changes to propagate to the repl without restarting? sorry if this is vague Hi, You can send code at any time : * via Ctrl+Alt+X : send to the repl either the top level expr where the cursor stands (if there's no current selection), or the current selection * via Ctrl+Alt+S : loads the current file in the REPL Optionally, if you've started the REPL from the project's node (and not from a particular clojure file's node), then you're in 'project mode' aka everytime you save an editor's content, the whole project libs are tentatively reloaded (not that currently this will not automagically remove deleted vars) All the currently available commands usable from an editor in eclipse (assuming you're talking really about Counterclockwise plugin aka ccw) are summed up in this wiki page :http://code.google.com/p/counterclockwise/wiki/EditorKeyBindingsFeatures --Robert McIntyre -- You 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 -- You 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 -- You 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: Looking for a better way
no need to use macros at all: (defn foo creates a symbol named s with the value s in the current namespace [s] (intern *ns* (symbol s) s)) that is, assuming I got the use case right. --Robert McIntyre On Wed, Dec 15, 2010 at 8:00 AM, Laurent PETIT laurent.pe...@gmail.com wrote: 2010/12/15 Emeka emekami...@gmail.com Helllo All, Is there a better way of doing this? (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f# ~b#))) Hello, What is it supposed to be used ? What do you expect the macroexpansion to look like ? As is stands, your example can go without the ending #'s since they aren't declared inside the returned quoted expr. They're useless. So having (defmacro foo [string] (let [b string f (symbol string)] `(def ~f ~b))) But now, string is not (as you may think) evaluated within the let in the macro. string is just an immutable datastructure containing as is what has been passed to foo. So if what you pass to foo is something which evaluates to a string, for example a string concatenation expression as (str the- value), then the code will not do what it suggests it's doing : user= (defmacro foo [string] (let[b# string f# (symbol b#)] `(def ~f# ~b#))) #'user/foo user= (foo (str the- value)) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.String (NO_SOURCE_FILE:0) user= (macroexpand '(foo (str the- value))) java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to java.lang.String (NO_SOURCE_FILE:0) user= Now, if you just want the macro to take literal strings as input, then the code can be further simplified to : (defmacro foo [string] `(def ~(symbol string) ~string)) user= (defmacro foo [string] `(def ~(symbol string) ~string)) #'user/foo user= (foo the-string) #'user/the-string user= the-string the-string user= (macroexpand '(foo the-string)) (def the-string the-string) user= HTH, -- 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 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 -- You 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: aliasing symbols from clojure core
Not to sound like a one track record here, but you should look at clojure.contrib.generic.arithemetic to see how to redefine / have a great day, --Robert McIntyre On Tue, Dec 14, 2010 at 4:26 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 14.12.2010 um 04:25 schrieb Sunil S Nandihalli: yeah cool I can do that.. thx. But I remember seeing a syntax for it in the ns macro... (ns name.space (:refer-clojure :rename {+ core+})) Please note that / is a special case symbol. Slashes are not allowed in symbols, and I'm not sure you can redefine it (haven't tested it). At least I would be very suspicious on its future-safeness. Sincerely Meikel -- You 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 -- You 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: complex number library
It's not a protocol, but you may want to take a look at clojure.contrib.generic.arithmetic for inspiration. I wish you luck in your complex number implementation! I've done my own using clojure.contrib.generic and can post if it anyone's interested. thanks, --Robert McIntyre On Mon, Dec 13, 2010 at 9:55 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Thanks David .. but is there a protocol that contains +,*,/,- operations? If there is one I can simply add those operations... Sunil. On Tue, Dec 14, 2010 at 7:07 AM, David Nolen dnolen.li...@gmail.com wrote: On Mon, Dec 13, 2010 at 8:13 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello Everybody, I see that Konrad-Hinsen's complex-library in the contrib is a very good fit.. But I am afraid about the performance since the basic operations are being dispatched using multi-methods... Does anybody have any say on this? Sunil. Contribute a new library that uses protocols and deftype/record ? :) David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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 -- You 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: aliasing symbols from clojure core
you can always do (def c+ clojure.core/+) right after the namespace declaration. --Robert McIntyre On Mon, Dec 13, 2010 at 10:20 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, I am defining a protocol which defines the functions +,-,*,/ .. so I am excluding those symbols when I do :refer-clojure but I would like to give an alias to say something like c+ c- c* and c/ how can I do this? Thanks, Sunil -- You 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 -- You 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: complex number library
here it is: (defrecord imaginary [real complex]) (defmethod + [imaginary Number] [i r] (imaginary. (+ (:real i) r) (:complex i))) (defmethod + [Number imaginary] [r i] (+ i r)) (defmethod + [imaginary imaginary] [i1 i2] (imaginary. (+ (:real i1) (:real i2)) (+ (:complex i1) (:complex i2 (defmethod * [imaginary Number] [i r] (imaginary. (* r (:real i)) (* r (:complex i (defmethod * [Number imaginary] [r i] (* i r)) (defmethod * [imaginary imaginary] [i1 i2] (let [[a1 b1] [(:real i1) (:complex i1)] [a2 b2] [(:real i2) (:complex i2)]] (imaginary. (- (* a1 a2) (* b1 b2)) (+ (* a1 b2) (* a2 b1) (defmethod / imaginary [i] (cond (and (not= (:real i) 0) (not= (:complex i) 0)) (let [[a b] [(:real i) (:complex i)] d (- (/ (/ a) (+ (/ a b) (/ b a c (/ (+ 1 (* b d)) a)] (imaginary. c d)) (= (:real i) 0) (imaginary. 0 (- (/ (:complex i (= (:complex i) 0) (imaginary. (/ (:real i)) 0))) (defmethod / [imaginary imaginary] [i1 i2] (* i1 (/ i2))) (defmethod / [imaginary Number] [i r] (* i (/ r))) (defmethod / [Number imaginary] [r i] (* r (/ i))) (defmulti norm class) (defmethod norm Number [r] r) (defmethod norm imaginary [i] (sqrt (+ (sq (:real i) ) (sq (:complex i) (def i (imaginary. 0 1)) It's a very basic complex number implementation. It uses clojure.generic Math operators instead of clojure.core Maybe it can help you out. I'd be interested in hearing your protocol implementation. --Robert McIntyre On Mon, Dec 13, 2010 at 10:27 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Robert would love to see your implementation.. The reason I am going for protocols .. is performance... Sunil. On Tue, Dec 14, 2010 at 8:52 AM, Robert McIntyre r...@mit.edu wrote: It's not a protocol, but you may want to take a look at clojure.contrib.generic.arithmetic for inspiration. I wish you luck in your complex number implementation! I've done my own using clojure.contrib.generic and can post if it anyone's interested. thanks, --Robert McIntyre On Mon, Dec 13, 2010 at 9:55 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Thanks David .. but is there a protocol that contains +,*,/,- operations? If there is one I can simply add those operations... Sunil. On Tue, Dec 14, 2010 at 7:07 AM, David Nolen dnolen.li...@gmail.com wrote: On Mon, Dec 13, 2010 at 8:13 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello Everybody, I see that Konrad-Hinsen's complex-library in the contrib is a very good fit.. But I am afraid about the performance since the basic operations are being dispatched using multi-methods... Does anybody have any say on this? Sunil. Contribute a new library that uses protocols and deftype/record ? :) David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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 -- You 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 -- You 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 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure
Re: Moderately off-topic: installing emacs on OSX
I don't know how applicable this might be for you, but I've had no problems whatsoever checking out the latest source for emacs 23 and compiling from source using the mac developer tools, all on my friend's laptop. All I did was type make and cross my fingers. you might give it 5 minutes if other things aren't working out. sincerely, --Robert McIntyre On Mon, Dec 13, 2010 at 11:12 PM, javajosh javaj...@gmail.com wrote: Aha! You're a genius! On Dec 13, 8:06 pm, gaz jones gareth.e.jo...@gmail.com wrote: homebrew installs a mac application to: /usr/local/Cellar/emacs/23.2/Emacs.app/ by default which you can run from there, or copy to your /Applications folder to run. running from the terminal doesnt seem to work so well in my experience. On Mon, Dec 13, 2010 at 8:43 PM, javajosh javaj...@gmail.com wrote: Ok, I decided to nuke ports, fink, and delete every package they ever installed. I successfully installed emacs 23.2 via homebrew (there's a good overview of homebrew herehttp://ascarter.net/2010/02/22/homebrew-for-os-x.html). I started the emacs it installed, but I didn't know how to access the scratch buffer, so I started the tutorial. Exit worked (C-x C-c). Scroll forward did not (C-v). Needless to say, I couldn't complete the elpa instructions. Additionally, emacs pops up a new colorful window but keeps the terminal in place. That's not the behavior I personally want. Perhaps I will try installing without the --cocoa option. Also tried the elpa self-install script in Aquamacs (where the scratch buffer comes up first thing), but C-j (the 'eval' keystroke) had no discernible effect. I tried M-x package-list-packages but it said [No Match]. So I assume nothing happened. Sorry to say but I'm rather annoyed with emacs. I find futzing around with package managers and this stuff to be utterly exhausting. -- You 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 -- You 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 -- You 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: math utilities question
I have looked at incanter and like it very much, but these are all things that incanter can't currently do. --Robert McIntyre On Mon, Dec 6, 2010 at 3:15 AM, Saul Hazledine shaz...@gmail.com wrote: On Dec 6, 12:27 am, Robert McIntyre r...@mit.edu wrote: I'm trying to use clojure for scientific data analysis but I keep running into lacunas of functionality. 6. symbolic manipulation as in sage This is something that would be awesome to have in Clojure because, unlike most non-lisps, you can compile the result and use it. This makes : 7. minimizing non-linear functions much easier. Saul -- You 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 -- You 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: Lots of newbie clojure questions
1. What is the justification for using a map as a function? I find this to be very confusing. In math, a function is a mapping from one set to another, so from that perspective it makes good sense for a clojure-map to be a function from its set of keys to its set of values. The justification here is mathematical convention. Same thing with vectors being functions. 2. In practice, I find myself wincing when needing to decide whether or not to type an open-paren. Is that a common thing? Normally this isn't a problem for me because I always look at the bottom of my emacs window and am able to see the arguments whatever function I'm working with requires. 3. Is there a compendium of recursive idioms, ideally expressed in clojure? Including indentation conventions! (Is there an opportunity for a python inspired pre-processor that interprets indentation as parens?) You might try SICP (http://mitpress.mit.edu/sicp/) because Professor Sussman is awesome. Also try the clojure cookbook (http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Cookbook) 4. Why don't long-running clojure programs monotonically increase in heap usage if all data-structures are immutable? If every reference to an immutable structure disappears than that structure can be garbage collected. Therefore, loops that create intermittent structures aren't that much of a memory hog since java garbage collects the structures every turn of the loop. ;;Memory : 0 (let [a (range 5)]) ;; Memory: big while the let is executing ;;Memory : 0 -- no reference to a anymore ! 5. In the REPL, isn't it redundant to always have to type the top- level parens? not for (let:) 6. Is there a place to get guidlines on macro idioms? The feature is so powerful that it seems like it would be easy to misuse it and crack a programmers head like a nut with a badly structured macro. Try Stuart Halloway's book, Programming Clojure. I liked it, at least. 1. Isn't the world actually imperative? And mutable? Collaboration *is* a messy proposition in real life. It's hard to fix your car, and even harder to have lots of people fix your car. I find the it models the real world better justification for functional programming rather confusing. (Indeed, the CPU and physical memory also have an imperative relationship!) The amount of mutability depends on your level of granularity. Let's say you want to add two numbers --- if you consider all the robotic actions the arm in your hard disk must do to load the memory into the CPU, the flow of electrons in the wires, etc, then there does seem to be mutable state everywhere. But, addition itself is a pure function, so the mutable state is incidental complexity that doesn't really matter in the long run. You can tell it doesn't matter because you can change all the mutable physical stuff and it won't affect the computation. You might use an abacus, a hydraulic computer, your brain, etc, but 2 + 2 is still 4 no matter how you get there. Just as Greens Theorem can transform a surface integral into a line integral and save a lot of work, it's important to circumscribe as much mutable state as possible with abstraction barriers to make our lives simpler. 2. 'Side-effects' are treated almost as a bad word by most functional programming advocates. And yet, aren't ALL programs executed for their side-effects? Does side effect perhaps then require a qualification or a tighter definition? Or perhaps side-effects aren't that bad? What is a side effect and what isn't depends again on your level of granularity. Too many side effects is a warning of badness because it means that you might be working at the wrong abstraction level. Incidental mutability should be removed because it just clutters everything up, but truly necessary mutability is just fine. 3. What is the relationship between the shape of a clojure program and the runtime call stack? (I ask because a clojure program looks strikingly similar to the callstack of an ordinary program when you 'pause' a thread.) 4. Is it possible (and/or advisable) to introduce a typing system on top of clojure? E.g. a macro-form along the lines of (fnif type_function function args) Try out defrecord to make your own java objects. Hope you have fun, --Robert McIntyre On Mon, Dec 6, 2010 at 8:40 PM, Stuart Halloway stuart.hallo...@gmail.com wrote: 1. Isn't the world actually imperative? And mutable? Collaboration *is* a messy proposition in real life. It's hard to fix your car, and even harder to have lots of people fix your car. I find the it models the real world better justification for functional programming rather confusing. (Indeed, the CPU and physical memory also have an imperative relationship!) I think it is important not to conflate Clojure with functional programming, since the latter is very broad. The world is a series of immutable states, and the future is a function of the past. See http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey
Re: Lots of newbie clojure questions
@javajosh You're speaking of the Turing description of computation, you might be interested in Church's lambda calculus description which works just as well and doesn't use mutability to describe computation, --Robert McIntyre On Mon, Dec 6, 2010 at 9:08 PM, javajosh javaj...@gmail.com wrote: On Dec 6, 5:40 pm, Stuart Halloway stuart.hallo...@gmail.com wrote: The world is a series of immutable states, and the future is a function of the past. See http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey. My philosophy questions are the most interesting to people, ha! Neat link. It appears that Hickey is something of a Alfred North Whitehead apostle. Not that there's anything wrong with that. But it's interesting. I question the truth of the general view, even as I enthusiastically endorse the utility of immutability in computer programs. At the lowest level, a computer program can be visualized as a two dimensional bitmap of ones and zeroes. These bits are interpreted by the CPU starting at the upper left, say, and they instruct the CPU what to do. The CPU in turn mutates the bitmap and proceeds, generally, across and down, unless it's instructed to move differently. Convention separates instruction from data but this is by no means written in stone. In any event, the *physical process* underlying computation, a bitmap modifying itself, appears imperative and mutable. One must jump through a lot of hoops (as Hickey can attest, I'm sure) to simulate immutability of value. Or perhaps the CPU designers are laboring under some false assumptions about reality, and CPU design itself needs to change? -- You 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 -- You 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 I'm getting StackoverflowError?
Your function never actually ends because even the empty list evaluates to true :) rlm.dna-melting (if (rest '()) true false) true rlm.dna-melting (if (next '()) true false) false so, changing your list length function to use next will work rlm.dna-melting (defn list-length [col] (if col (+ 1 (list-length (next col))) 0)) #'rlm.dna-melting/list-length rlm.dna-melting (list-length (range 5)) 5 hope that helps, --Robert McIntyre On Sun, Dec 5, 2010 at 4:52 PM, HB hubaghd...@gmail.com wrote: Hi, I'm trying to write a function that calculates the length of a list: (defn list-length [col] (if col (+ 1 (list-length(rest col))) 0)) (list-length '(Java, Clojure, Scala)) Upon running it in the REPL, I got the error: java.lang.StackOverflowError (test.clj:3) What is going wrong? -- You 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 -- You 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
math utilities question
I'm trying to use clojure for scientific data analysis but I keep running into lacunas of functionality. I'd love to hear the community's recommendations and experiences with this: Is there a standard way to do things like: 1. take the convolution of two vectors 2. work with imaginary numbers, quaternions, octonions, etc 3. work with matrices of arbitrary dimension 4. Fourier transform ( in multiple dimensions) 5. integration / finite difference 6. symbolic manipulation as in sage 7. minimizing non-linear functions 8. finding zeros of non-linear functions thank you all in advance for any recommendations you might have. --Robert McIntyre -- You 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: parameters destructuring sets?
If sets don't have a set ordering, then why should seq on a set always return the same order for the same set? If seq doesn't always return the a seq with the same order, then (nth set 5) might be different than a future call to (nth set 5), because the underlying sequence returned by the set might change. If seq on a set always returns a seq with the same order, then that may limit the future efficiency of sets. --Robert McIntyre On Sun, Dec 5, 2010 at 8:08 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: +1 to what Ken said Sunil On Mon, Dec 6, 2010 at 4:04 AM, Ken Wesson kwess...@gmail.com wrote: On Sun, Dec 5, 2010 at 4:14 PM, jweiss jeffrey.m.we...@gmail.com wrote: That's totally different than nth for a set being undefined. It's undefined on purpose. Now, if you are using a sorted-set, then you have a point there, I would expect that nth means something then. But yeah, clojure doesn't let you call nth on it directly, you have to make a seq out of it first. I vote to make nth work on sets and maps, in general, sorted and otherwise, with the well-defined semantics of (identical? (nth set-or-map) (nth (seq (set-or-map. More generally, let nth work on anything that seq works on, by calling seq on its argument when necessary. -- You 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 -- You 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 -- You 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: math utilities question
Thanks for your input --- I'm hoping that some of this stuff is already written with performance optimizations and the like. I'm wondering if people have had experience with java libraries of that sort and might have some recommendations. Anyone use clojure for scientific data analysis? What do you find helpful to use? --Robert McIntyre On Sun, Dec 5, 2010 at 9:36 PM, Ken Wesson kwess...@gmail.com wrote: On Sun, Dec 5, 2010 at 6:27 PM, Robert McIntyre r...@mit.edu wrote: I'm trying to use clojure for scientific data analysis but I keep running into lacunas of functionality. I'd love to hear the community's recommendations and experiences with this: Is there a standard way to do things like: 1. take the convolution of two vectors 2. work with imaginary numbers, quaternions, octonions, etc 3. work with matrices of arbitrary dimension 4. Fourier transform ( in multiple dimensions) 5. integration / finite difference 6. symbolic manipulation as in sage 7. minimizing non-linear functions 8. finding zeros of non-linear functions Standard, as in built into Clojure? No. Standard as in algorithmic? Of course. There are two options here. First, many of those things are fairly easily implemented in Clojure, and with a bit more work can be made very efficient (essentially, native-C efficient). For instance, for matrices you'd want a contiguous representation in memory so you'd use a vector, or even a Java array of doubles, of length m*n and functions that provided a matrix API and used this representation internally. With definline and macros this can be made efficient, and a Java array of doubles could have the speed of equivalent C code since it would be a contiguous block of doubles in RAM just as you'd get in C. Second, there are probably lots of existing scientific-computing libraries for Java out there that do the things you need done, and Clojure can load and call into Java libraries pretty easily. -- You 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 -- You 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.contrib.seq vs. clojure.contrib.seq-utils
clojure.core.seq is preferred --- from clojure.core.seq_utils.clj ;;; seq_utils.clj -- Sequence utilities for Clojure ;; by Stuart Sierra, http://stuartsierra.com/ ;; last updated March 2, 2009 ;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use ;; and distribution terms for this software are covered by the Eclipse ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) ;; which can be found in the file epl-v10.html at the root of this ;; distribution. By using this software in any fashion, you are ;; agreeing to be bound by the terms of this license. You must not ;; remove this notice, or any other, from this software. ;; Change Log ;; ;; DEPRECATED in 1.2. Some functions promoted to clojure.core and some ;; moved to c.c.seq --Robert McIntyre On Sun, Dec 5, 2010 at 12:04 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, Both of clojure.contrib.seq and clojure.contrib.seq-utils seem to give the same functionality.. any idea as to which one we r supposed to be using.. Sunil. -- You 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 -- You 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: Ring startup processing?
Why not use good old runonce from lancet? (defn runonce Create a function that will only run once. All other invocations return the first calculated value. The function can have side effects. Returns a [has-run-predicate, reset-fn, once-fn] [function] (let [sentinel (Object.) result (atom sentinel) reset-fn (fn [] (reset! result sentinel) nil) has-run? #(not= @result sentinel)] [has-run? reset-fn (fn [ args] (locking sentinel (if (= @result sentinel) (reset! result (function)) @result)))])) --Robert McIntyre On Sun, Nov 28, 2010 at 11:28 PM, Stuart Campbell stu...@harto.org wrote: Ah, OK. We just use Tomcat 6 for everything here :) On 29 November 2010 12:16, lprefonta...@softaddicts.ca wrote: Yep but some app servers have bugs with this interface (GlassFish 2, jetty 6.1, tomcat 5.5, ...) and the interface is not called appropriately. There are less problems reported with the load-on-startup flag. Of course if you know your app server's behavior regarding this feature, it might not be a problem. I got caught once so I prefer a safer mechanism, we are not always using the same app server here. Might work in dev and not in prod... oups... Luc P. Stuart Campbell stu...@harto.org wrote .. On 28 November 2010 16:51, lprefonta...@softaddicts.ca wrote: We use a dedicated servlet for every web app to make sure all prerequisites are met. Since it's loaded first, we can find problems by looking at a single piece of the log files just after the container messages announcing that it's loading the app. There's also ServletContextListener ( http://download.oracle.com/javaee/5/api/javax/servlet/ServletContextListener.html), which is configured in web.xml too. Regards, Stuart -- You 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 Luc P. The rabid Muppet -- You 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 -- You 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 -- You 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: a macro to debug the let form
cool! Although I think with-seperator should be spelled with-separator --Robert McIntyre On Thu, Nov 25, 2010 at 9:13 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: I just tried to re-write with-seperator without using the symbol-macros from macro-utils and it seems to work fine .. On Thu, Nov 25, 2010 at 1:27 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, I was trying to learn to write clojure macros and the code is posted here in the following link https://gist.github.com/715047 There are basically three macros 1. with-seperator - a zero argument macro and is supposed to just draw a line to indicate beginning and ending of the execution of the body. 2. display-local-bindings - a function to print the local bindings in the lexical scope where the macro is called 3. letd - a helper macro to print the values of all the bindings followed by printing of the local bindings using display-local-bindings The letd macro as posted works as expected but without the seperation line . It is supposed to print the seperation line when I uncomment line 14 and comment line 15 but some how this is causing the env variable automatically passed with every macro to be nil display-local-binding .. but the I feel it is not the case .. can somebody help me understand this. This was an exercise to learn macro writing than to writing a letd debugging helper function.. Thanks, Sunil. -- You 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 -- You 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: fastest way to remove nils
So, just to be clear, user (def nil-seq (doall (interleave (repeat 1e5 nil) (repeat 1e5 whatever))) ) #'user/nil-seq user (time (doall (keep identity nil-seq))) Elapsed time: 122.485848 msecs user (time (doall (remove nil? nil-seq))) Elapsed time: 149.71484 msecs --Robert McIntyre On Wed, Nov 17, 2010 at 5:57 AM, Steve Purcell st...@sanityinc.com wrote: Miki miki.teb...@gmail.com writes: user= (time (remove nil? (repeat 100 nil))) Elapsed time: 0.079312 msecs () user= (time (filter identity (repeat 100 nil))) Elapsed time: 0.070249 msecs () Seems like filter is a bit faster, however YMMV You're not timing the execution, just the construction of a lazy seq: user (time (remove nil? (repeat 100 nil))) Elapsed time: 0.044 msecs () user (time (doall (remove nil? (repeat 100 nil Elapsed time: 772.469 msecs () -Steve On Nov 16, 4:48 pm, Glen Rubin rubing...@gmail.com wrote: What is the fastest way to remove nils from a sequence? I usually use the filter function, but I see there are other functions like remove that should also do the trick. -- You 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 -- You 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: Incorrect behaviour for large s-expressions :(
(clojure/JVM) here? --Robert McIntyre On Sun, Nov 14, 2010 at 3:36 AM, Mike Meyer m...@mired.org wrote: On Sun, 14 Nov 2010 00:48:13 -0500 Robert McIntyre r...@mit.edu wrote: So my friend and I were screwing around, battling versions of LISP as nerds are wont to do, when I came across this: (eval `(clojure.core/+ ~@(take 1e4 (iterate inc 1 Invalid method Code length 89884 in class file user$eval13607 This is just trying to evaluate + directly on a bunch of arguments. I'd say the first problem is using the macro-building constructs outside a macro. I believe this is generally a bad idea. If you build the list and apply + to it directly, it works fine Clojure 1.2.0 user= (apply + (doall (take 1e4 (iterate inc 1 (apply + (take 1e4 (iterate inc 1))) 50005000 user= (apply + (doall (take 1e5 (iterate inc 1 (apply + (take 1e5 (iterate inc 1))) 55 user= But nope, you've got a real problem. It appears to be with eval: user= (eval (cons + (take 1e4 (iterate inc 1 (eval (cons + (take 1e4 (iterate inc 1 java.lang.ClassFormatError: Invalid method Code length 89881 in class file user$eval26 (NO_SOURCE_FILE:8) user= (count (cons + (take
Re: Incorrect behaviour for large s-expressions :(
That is not in fact an adequate workaround --- (eval `(apply + ~@(take 9001 (iterate inc 1 ;; OVER 9000!!! or, alternately (eval (cons 'apply (cons '+ (take 9001 (iterate inc 1) will fail just as in the addition examples. It's not true that you can just use an apply in your auto generated code, you would instead have to do something like a tree of function calls, so It may be worth increasing the limit for for the sake of enabling machine generated code. What are you peoples' thoughts on this? --Robert McIntyre On Sun, Nov 14, 2010 at 12:54 PM, Mike Meyer mwm-keyword-googlegroups.620...@mired.org wrote: On Sun, 14 Nov 2010 08:43:11 -0500 Robert McIntyre r...@mit.edu wrote: @Mike Meyer Using apply is different than what I'm doing. Yup. When I use eval I'm trying to evaluate a huge s-expression. When you use apply you're evaluating a s-expression with three elements. Same thing with the count form (except with two elements). The problem isn't because I'm calling eval or not using idiomatic clojure; I just wrote it that way so it would only take one line. I did agree that there was a problem. The thing is, quasiquotes in clojure were designed for use in macros, and using them outside macros sometimes generates weird results: I wanted to make sure that wasn't the case here. My first attempt - in idiomatic clojure - didn't recreate it. So I went a bit further afield to do so. Are we really OK with having a 30 year old (Common Lisp/Lisp Machine) that operates at megahertz speeds do better than (clojure/JVM) here? Yes, I'm OK that a LISP running on an architecture that's the end result of decades of research on creating machines that run LISP well has fewer and/or higher limits than a LISP running on a VM designed to run Java. I'm not even sure it's worth any effort in fixing. You're not going to run into this limit except in machine-generated code, and there's an easy work-around: generate (apply fun (sequence)) instead of (fun sequence). mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You 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 -- You 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
Incorrect behaviour for large s-expressions :(
So my friend and I were screwing around, battling versions of LISP as nerds are wont to do, when I came across this: (eval `(clojure.core/+ ~@(take 1e4 (iterate inc 1 Invalid method Code length 89884 in class file user$eval13607 This is just trying to evaluate + directly on a bunch of arguments. Common Lisp on my friend's 30 year old Lisp machine does the equivalent of this with ease, even for much larger numbers. As I'm writing this, my friend is rubbing in this in my face by also doing the above with C-LISP on his laptop. (although his stack overflows for 1e5) I'm losing my battle!!! :( Pls. help! --Robert McIntyre -- You 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: a macro
I'm still a little confused as to what you're trying to do, but is this what you're looking for? (defmacro zzz [form] (first form)) (defmacro eval-zzz [form] `(zzz ~(eval form))) rlm.play-all (zzz (range 1 2)) #core$range clojure.core$ra...@61e066 rlm.play-all (macroexpand-1 '(eval-zzz (range 5))) (rlm.play-all/zzz (0 1 2 3 4)) rlm.play-all (eval-zzz (range 5)) 0 --Robert On Wed, Oct 13, 2010 at 1:55 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello Everybody, I think I was not clear about things in my previous email.. I am reposting simplifying things... Variables is a macro which works in the following way.. (Variables (+ x (* 2 y)) returns [x y] now let us say we have a function (defn f [] '(+ x (* 2 y))) now I would like to do something like (Variables (f)) which would return [x y] I know if is a function and will not be evaluated before the macro expands.. may be there is a way to wrap it in a macro (since f is already defined which I would like to use) and have the macro Variables apply on the result of evaluation of f any help is greatly appreciated. Thanks, Sunil. -- You 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 -- You 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: New Release of the Clojure Debugging Toolkit
I believe this is not caused by any problems with the debugging environment. Instead you appear to not have the clojure jar on your classpath. I would recommend you explicitly launch java with java -cp H:\path\to\clojure.jar plus any additional arguments of course. if this is still not working for you, please post the exact command you are using to invoke java, as well as a listing of all jars on your classpath, and I'll try to help some more. Good luck, --Robert McIntyre 2010/10/8 limux liumengji...@gmail.com: I do a full source install of clojure follow by the article Emacs Front End to the Clojure Debugging Toolkit, I started the java vm with all the necesory arguments, and M-x cdt, then there will be some error messages as below: Current directory is H:\heoxsoft\emacs\emacs-23.2\bin/ java.lang.NoClassDefFoundError: clojure/main Caused by: java.lang.ClassNotFoundException: clojure.main at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: clojure.main. Program will exit. Exception in thread main Debugger exited abnormally with code 1 I am a newbie of clojure and java, thanks for you help! My java is sun jdk 1.6.18, os is windows 7 x64. I will try it after October 10 because I will install the Ubuntu 10.10. On 10月8日, 下午7时32分, George Jahad cloj...@blackbirdsystems.net wrote: sa-jdi.jar is supposed to come with the jdk. The code I use for finding it should work for sun's 1.6 jdk on linux and osx. Which java are you using? What os are you running it on? Also, what problem are you running into without it? (I think I only use it for some advanced features which you may not need.) On Oct 7, 8:15 pm, limux liumengji...@gmail.com wrote: where is the sa-jdi.jar, there isn't the sa-jdi.jar under my java's lib directory. On 9月29日, 下午12时00分, George Jahad cloj...@blackbirdsystems.net wrote: hmmm, you must be as big a debugger geek as I am, but I'm not sure anyone else would be interested. In any case the commands are almost trivial, which is why I don't think it will be too hard to port this to other IDE's: These are theCDTcommands that were generated by the Emacs front end in the first example: (set-bpclojure.set/difference) (reval s1) (reval s2) (reval count) (reval (count s2)) (step-over) (reval (reduce disj s1 s2)) (up) (down) (cont) (line-bp /Users/georgejahad/incoming/clo11/clojure/src/clj/clojure/ set.clj 56) On Sep 28, 5:13 am, David Nolen dnolen.li...@gmail.com wrote: On Tue, Sep 28, 2010 at 3:40 AM, George Jahad cloj...@blackbirdsystems.netwrote: As some of you know, I suffer from a seemingly interminable obsession with improving theClojuredebugging story. It just seems so clear to me thatClojuredeserves a world class debugger, one befitting it's power, beauty and elegance. Maybe one day, we'll get there. Till then, here are my latest improvements to theCDT: Great stuff! Would it be possible to write a version of the tutorial that shows how to accomplish the same things purely from the command line? While I love Emacs as much as the next guy, I think a tutorial that shows how to debug using only theCDTREPL would be useful to many people. David -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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: An Emacs command to close the various balanced expressions in Clojure
Thank you blais --- I also have troubles with paredit and this function will really help me out. keep up the good work, --Robert McIntyre On Sun, Sep 26, 2010 at 8:19 PM, Tassilo Horn tass...@member.fsf.org wrote: Hi, did you already try out paredit [1]? That mode is absolutely fabulous for programming any lisp and provides much more than just closing parens. Give it a shot! Bye, Tassilo Footnotes: [1] http://mumble.net/~campbell/emacs/paredit.el -- You 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 -- You 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: functions left over in the vm
I generally use the ns macro to jump around my namespaces (like I use ls to change directories in the shell) , and use a convenience function I wrote called ns-nuke, which gets rid of all functions defined in that ns. Then I use reload, another convenience function, which just uses that namespace again. This works for me but then again my code is rather small. If you are using emacs, you can do C-c C-k to recompile that namespace as well. I used to restart my repl all the time but I don't ever do that anymore after making ns-nuke (and a function to add stuff to the classpath :)) You can also use user.clj to preload convenience functions, so that you no longer need to experience the pain of a million (use) statements on a restart. Here are my functions that they may be helpful to you: (defmacro ns-nuke ([] (let [current-ns# (symbol (str *ns*))] `(do (println NUKING namespace (quote ~current-ns#)) (clojure.lang.Namespace/remove (quote ~current-ns#)) (ns ~current-ns#) (defmacro reload [] `(do (use :reload-all (quote ~(symbol (str *ns*)) --Robert McIntyre On Sun, Sep 26, 2010 at 5:56 PM, Michael Ossareh ossa...@gmail.com wrote: How are other people handling the process of reducing code in their projects? Situation: We've built a product, very rapidly thanks to being able to produce stuff very quickly in clojure. However now that it is somewhat settled I'm in the process of paring down the code, removing defunct fn's, etc. Problem: You compile your code, you test it, you pare down some functions or rename a function and push that into the VM - hit refresh, everything works. However there is a chance you are actually using a function which you have removed from the source code. i.e. you missed a reference in another file or something similar. Most recently I removed a pointless wrapper fn around another fn, however the wrapped fn was declared private. Everything seemed to be working until I compiled the source and found out that my fn's were calling the wrappee which was still in scope within the VM . I've now started to use lein uberjar to point out cases that I'm doing this - and it's fine for now, however it is a bit of a throwback to the pains of Java development. Another solution I've been using is to regularly restart my running clojure instance, however this has the annoyance of me losing all my locally defined vars during dev. Thanks for any suggestions on 'dev best practices' in this space. Cheers, 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 -- You 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 meetup group listing
Are there any clojure groups around Boston, MA? --Robert McIntyre On Tue, Sep 21, 2010 at 12:43 PM, Sean Corfield seancorfi...@gmail.com wrote: The Bay Area Clojure User Group had its 25th meeting last night: http://www.meetup.com/The-Bay-Area-Clojure-User-Group/ It was a great meeting - with Rich talking about the new primitives stuff in master / 1.3 and explaining design decisions behind the language! Awesome stuff! Big thanx to Amit for organizing, Tom for hosting at 3VR and, of course, to Rich for speaking! On Mon, Sep 20, 2010 at 8:33 AM, Andrew Gwozdziewycz apg...@gmail.com wrote: I know there are certainly a few groups out there (organized via Meetup.com or otherwise) which I see things posted about from time to time on the list. I'd like to propose that we make an effort to list these groups on Meetup Everywhere (http://www.meetup.com/everywhere), which is a free platform useful for finding a nearby meetup about a given topic. Please note, this is not meant to overtake your existing organization method. Everywhere is designed to be agnostic in regards to organization platform. If enough groups start listing there, it might make sense to then post a link on the Clojure site to help people find their local user group: http://www.meetup.com/Clojure I can make changes to the page as necessary. -- You 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 -- You 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: Quirk of Map destructuring
Right, but the :or could conceptually just merge the supplied map with the actual supplied argument map instead -- it's just another way it could go. This is possibly a simpler model to manage in your head, since presumably you have some idea of how you want to call the function when you're writing it. I'm wondering why the symbol route was selected when the merge way may be more convenient, or why there's something really bad about the merge way that I'm overlooking. --Robert McIntyre On Mon, Sep 13, 2010 at 1:08 PM, Mark Nutter manutte...@gmail.com wrote: On Mon, Sep 13, 2010 at 12:37 PM, Tom Hicks hickstoh...@gmail.com wrote: On Sep 12, 10:44 pm, Meikel Brandmeyer m...@kotka.de wrote: The default map specifies the default for the symbols which are bound, not the source of the values. (let [{foo :some-key bar some-other-key :or {foo 1}} ] ...) Sorry Meikel, I don't understand your answer. My question was why does the default map not lookup the values using the same lookup method as the original map (:keys, :strs, or :syms)? Why does it always assume symbols for keys? What he's saying is that the map after the :or is not doing a lookup in the original map you're destructuring, so it's not a question of doing the same kind of lookup or not. The map after the :or is a map of local symbols to default values (as opposed to being a map of keys-found-in-the-original-map to default values. (let [foo bar] ...) Assigns the value of bar to the local symbol foo (let [{:keys [foo]} {:foo bar}] ...) Assigns the string bar to the local symbol foo by looking up the keyword :foo in the supplied map (let[{:keys [foo baz] :or {baz quux}} {:foo bar}]...) The tricky bit: it looks up the key :foo in the supplied map, and creates a local symbol foo with the value bar. Next, it looks up the keyword :baz (which is nil) and creates a local symbol named baz that is also nil. At this point, it's done looking things up in the supplied map. Now we're up to the :or part. For each local symbol with a nil value, we look in the :or map to see if there's a key with the same symbol. If there is, we use that as the value of the local symbol instead of nil. But the point is we're looking up local symbols now, not anything in the original map. Caveat: that's a high-level overview from a fairly new Clojure user (me) who is only attempting to rephrase what he thinks he's understood from reading the words of people who know what they're talking about. The source code for :or destructuring may use a different process completely, or I may have been more or less correct. I don't really know, but if I've mangled anything I'm hopeful someone will correct me. Cheers. -- You 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 -- You 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: ns-unmap-all
shouldn't we rename remove-ns to ns-remove to keep it in line with the other ns functions? --Robert McIntyre On Sun, Sep 12, 2010 at 4:18 PM, Phil Hagelberg p...@hagelb.org wrote: On Sat, Sep 11, 2010 at 6:48 PM, blais martin.bl...@gmail.com wrote: The following function has been a real _lifesaver_ lately in debugging symbol collisions in (ns) directives when developing with SLIME in a long-running VM: (defn ns-unmap-all Unmap all the symbols (except 'ns' and 'in-ns'). ([] (ns-unmap-all *ns*)) ([ns] (map #(ns-unmap ns %) (keys (ns-map ns) May I kindly suggest the inclusion of something similar along with all the other core namespace functions? It's quite nice (IMHO: necessary) to be able to get back to a clean environment when you face a collision error. (I'm guessing may of you have something similar already defined in your environments.) I've had this on my todo list for swank-clojure for a while now; would love to see a patch that integrates it. Not sure it belongs in clojure.core though. -Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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: Quirk of Map destructuring
I've been bitten by this before. Unless there's a good reason for :or to work the way it does I think that would be a good idea, since then you can define default maps somewhere else and use those both with the :or keyword or when calling the function itself. Maybe the :or map can just be underlaid with the actual map being used to call the function? --Robert McIntyre On Sun, Sep 12, 2010 at 9:21 PM, Tom Hicks hickstoh...@gmail.com wrote: I just noticed this unexpected result for Map destructuring with an quote:or/quote directive: pre user= (def guys-name-map {:f-name Guy :l-name Steele}) #'user/guys-name-map user= (let [{:keys [f-name m-name l-name] :or {:m-name CL}} guys- name-map] (str l-name , f-name + m-name)) Steele, Guy+ user= (let [{:keys [f-name m-name l-name] :or {m-name CL}} guys- name-map] (str l-name , f-name + m-name)) Steele, Guy+CL /pre Note that the quote:or/quote directive does not seem to respect/ use the preceeding :keys directive and appears to be doing its lookup using symbols only. Was this the intended behavior? Wouldn't it be more useful to extend the behavior of quote:or/ quote to use the same lookup method (:keys, :strs, or :syms) as specified in the (same) preceeding map context? -- You 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 -- You 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
what's up with user.clj?
In the clojure getting started guide, it says that if user.clj is found on the classpath, then that file will be evaluated and the repl will start with any modifications made from that file. My directory structure looks like this /src/user.clj /src/rlm/quick.clj /lib/*all-my-jars* I have a function (dirty) in quick.clj that essentially does: (defn dirty [] (use :reload-all '[clojure.java [javadoc :only [javadoc]]) (clojure.java.javadoc/add-local-javadoc /path/to/local/javadocs)) (dirty) works fine at the repl if I type (do (require 'rlm.quick) (rlm.quick/dirty)) If I define user.clj like so: (ns user) (require 'rlm.quick) (rlm.quick/dirty) Then I get the error : java.lang.ClassNotFoundException: clojure.java.javadoc If I move the (clojure.java.javadoc/add-local-javadoc /path/to/local/javadocs) from (dirty) straight into user.clj it works fine. what's up with this? --Robert McIntyre and user.clj reads like this -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Generating functions programmatically
Why not explicitly feed the macro the keyword map if that is what it wants? (defmacro ultra-synth [prefix keywords] (let [symbols (map (comp symbol name) keywords) fn-names (map (comp symbol (partial str prefix) name) keywords) defn-forms (map (fn [fn-name symbol] `(defn ~fn-name [n#] (= n# ~symbol))) fn-names symbols)] `(do ~...@defn-forms))) thunderbolt.play (def a 5) #'thunderbolt.play/a thunderbolt.play (def b 5) #'thunderbolt.play/b thunderbolt.play (ultra-synth hi [:a :b]) #'thunderbolt.play/hib thunderbolt.play (hia 5) true --Robert McIntyre On Fri, Sep 10, 2010 at 6:17 PM, Alan a...@malloys.org wrote: PS this is super-ugly and I'm always embarrassed when I find myself using eval in a lisp. While this works, I'd love it if someone could tell me how to do it with macros. On Sep 10, 3:07 pm, Alan a...@malloys.org wrote: I see. It's hard to imagine how this could work, since macros don't have access to runtime data like the value of x in your example. Perhaps you're better off writing a function that returns a closure, and iteratively def'ing those? user= (defn make-kw-fn [kw] #(= kw %)) #'user/make-kw-fn user= (def kws [:a :b]) #'user/kws user= (eval (cons 'do (map #(list 'def (symbol (str test- (name %))) (make- kw-fn %)) kws))) #'user/test-b user= (test-b :a) false user= (test-b :b) true On Sep 10, 1:37 pm, icemaze icem...@gmail.com wrote: Alan, thank you for your reply. Unfortunately your solution is very similar to mine and it suffers from the same problem (maybe I'm using it incorrectly, I don't know). If I write: (doseq [x '(:a :b)] (make-fn x)) it defines a single function synthetic-x. Is there a way to make this work? I tried everything but both eval and var-get don't work for local bindings. Thanks again. -- You 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 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Generating functions programmatically
there's always apply-macro from contrib for doing perverse stuff like that, so you don't have to *see* eval if you don't want to :) --Robert McIntyre On Fri, Sep 10, 2010 at 8:24 PM, icemaze icem...@gmail.com wrote: I agree: eval never looks pretty. -- You 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 -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Generating functions programmatically
That is very elegant but has the exact same problem in that the macro must be called on a literal vector of keywords. --Robert McIntyre On Fri, Sep 10, 2010 at 5:41 PM, Btsai benny.t...@gmail.com wrote: This is probably not the prettiest way to do it, but I think it gets the job done: (defn make-sym [keyword] (- keyword name (str prefix-) symbol)) (defn make-fn [keyword] (let [n (gensym)] (list 'defn (make-sym keyword) [n] (list '= n keyword (defmacro make-fns [keywords] `(do ~@(map make-fn keywords))) user= (make-fns [:a :b :c]) #'user/prefix-c user= (prefix-a :a) true user= (prefix-a :x) false user= (prefix-b :b) true user= (prefix-b :x) false user= (prefix-c :c) true user= (prefix-c :x) false The credit belongs to Alan, and Mr. Stuart Halloway for his examples from Ch. 7 of Programming Clojure. On Sep 10, 2:37 pm, icemaze icem...@gmail.com wrote: Alan, thank you for your reply. Unfortunately your solution is very similar to mine and it suffers from the same problem (maybe I'm using it incorrectly, I don't know). If I write: (doseq [x '(:a :b)] (make-fn x)) it defines a single function synthetic-x. Is there a way to make this work? I tried everything but both eval and var-get don't work for local bindings. Thanks again. -- You 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 -- You 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: Documentation tools
As a counterexample to these statements consider proxy, genclass, and it's ilk --- I don't think reading the source is good enough to totally understand the purpose behind those functions. There's also the issue of providing examples in the doc string. What's more clear, Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created. ---or--- Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created. Example: (assoc-in {} [:a :B] 5) {:a {:B 5}} ? --Robert McIntyre On Wed, Sep 8, 2010 at 3:05 AM, Sean Corfield seancorfi...@gmail.com wrote: On Tue, Sep 7, 2010 at 11:10 PM, Mark Engelberg mark.engelb...@gmail.com wrote: What pre-conditions need to be met by the inputs? What invariants are maintained by the function? What are the performance guarantees of the function? And this can't be expressed in a single sentence? Many times there are dozens of functions that are interrelated. Only one or two of them are the crucially important entry points that provide the high-level API. Then reorganize your files. Each file should have a specific public API. Good documentation makes it clear what is the right way. Fix the code. The right way should be the only / obvious way. The list goes on. I just don't see these questions arising from an agile point of view... If you want to comment your code for other people to maintain it, that's even more challenging. Nonsense. That's all about good, descriptive naming. If you can't document your code in a single sentence, it's too complex. I keep hearing FP folks talking about small functions and breaking things down so this issue of documentation runs counter to that... Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- John F. Woods Most people who read my code have said it reads like poetry and they love it. I have almost zero comments in my code. I have literate function / variable names. Comments can get out of sync with code so the fewer comments you have, the better, as far as I'm concerned. The code itself should be literate. -- Sean A Corfield -- (904) 302-SEAN Railo Technologies, Inc. -- http://getrailo.com/ An Architect's View -- http://corfield.org/ If you're not annoying somebody, you're not really alive. -- Margaret Atwood -- You 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 -- You 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: 2 lein swank instances on same project and compiling src from emacs
I don't think you can do that, but you can connect to the same swank instance twice with M-x slime-connect and function updates will be reflected in both repls. --Robert McIntyre On Tue, Sep 7, 2010 at 8:54 PM, HiHeelHottie hiheelhot...@gmail.com wrote: I have two lein swanks going on different ports against the same project. I open up two slime-connect's in emacs. How can I compile (C-c C-k) my core.clj to the two different slime-connect's. hhh -- You 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 -- You 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: Mapping a function to a map
walk is good but it's not lazy. If you want to preserve laziness you can do: (defn map-vals transform a map by mapping it's keys to different values. [f m] (into {} (map (fn [[key val]] [key (f val)]) m))) This is also nice because you can then write functions whose arguments are [val] instead of [key val] and ignoring the key. --Robert McIntyre On Mon, Sep 6, 2010 at 12:06 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: (clojure.walk/walk (fn [[key val]] [key (* 2 val)]) identity {:a 1 :b 2}) On Mon, Sep 6, 2010 at 9:26 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Nicolas I am not sure of the performance characteristics.. but you may want to look at (clojure.walk/walk #(do (println inner : %) %) #(do (println outer : %) %) {:a 1 :b 2}) Best regards, Sunil. On Mon, Sep 6, 2010 at 9:10 PM, Nicolas Oury nicolas.o...@gmail.com wrote: Dear all, is there a function to map a function to all values in a map, keeping the same keys? Reducing from the seqed map seems a bit slower that what could be done directly... Best, 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 -- You 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 -- You 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: Mapping a function to a map
I thought that since into uses reduce, it would be lazy, but I was wrong. reduce just plows through everything with a non-lazy recursion. Why is reduce not lazy? --Robert McIntyre On Mon, Sep 6, 2010 at 12:37 PM, Michał Marczyk michal.marc...@gmail.com wrote: On 6 September 2010 18:29, Robert McIntyre r...@mit.edu wrote: walk is good but it's not lazy. If you want to preserve laziness you can do: This won't be lazy, because (into {} ...) is a strict operation. I'd suggest something like (defn mmap [f m] (zipmap (keys m) (map f (vals m f is expected to care about the value only. Sincerely, Michał -- You 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 -- You 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: Mapping a function to a map
Why is it that clojure maps aren't lazy though? Wouldn't that be just as useful an abstraction as lazy sequences? Aren't map really just lists of pairs in the end anyway? --Robert McIntyre On Mon, Sep 6, 2010 at 1:19 PM, Michał Marczyk michal.marc...@gmail.com wrote: On 6 September 2010 18:49, Robert McIntyre r...@mit.edu wrote: I thought that since into uses reduce, it would be lazy, but I was wrong. reduce just plows through everything with a non-lazy recursion. Well, there's another reason in that the concept of a lazy map is problematic. In Clojure, at any rate, either you have a map or you don't -- it's always strict. Why is reduce not lazy? The tail call in reduce is a call to itself, so it's pretty hard to imagine a meaningful way for it to be lazy -- it only has anything to return other than a result to a further call to reduce upon reaching the end of the sequence being reduced. Thus, it's purpose is fundamentally to go through the entire seq producing a single end product. In contrast, a right fold's tail is a call to the reduction function with one of the arguments being a further call to foldr, so that can be made lazy in a sufficiently lazy language; but in Clojure, only seqs can be lazy, so that wouldn't really work either. Sincerely, Michał -- You 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 -- You 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
clojure Image/video processing?
I was wondering if anyone has used clojure for image/video processing and how that has worked out. I've spent a long time on this since clojure 1.0 and have gone through many different (java) libraries trying to find something that's truly awesome. I've tried: Images: ImageJ (lots of plugins but too tied to the GUI) JMF: a joke that hasn't been updated in years FMJ: looks like it could be good but still in very early development OpenCV : tried two different jna bindings but had many horrible memory leaks and crashes My own hash-map representation/functional way: elegant and easy to write new transforms but incredibly slow and memory hungry. Video: Xuggle: works very well, uses FMPEG in the background -- great for dealing with encodings but not much image processing ability. Processing: still don't know at all what this is or how to get it to work. What have you all come across, and has anyone found something that just wins over everything? --Robert McIntyre -- You 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 Image/video processing?
Thank you everyone for your time and great advice. Thank you Wilson MacGyver, for recommending jmagick. I actually already use it's brother im4java (http://im4java.sourceforge.net/) for great justice already and forgot to mention it. It does alright for basic image manipulation. The reason I've had to try so many libraries is because I'm looking for something flexible and fast enough to do the following: Problem 1. Take in any video file in any common encoding and output a log-polar transform of that video file. Problem 2. Take a video, do blob detection, and output a simplified video showing the main shapes moving around. Extra super bonus points would be for being able to also do this from camera input, from whatever camera you happen to have. Thank you Mark Downie for recommending OpenCL, I'll start playing around with it. As for accessing the c libraries directly, I'm afraid I don't know much about JNI to do it from clojure. Do you or anyone know of a good way to start with JNI in clojure? Java2D and the processing core look like they might be interesting, especially when combined with xuggle's ability to create sequences of buffered images. I'm a little wary of Java2D though as it seems rather old and creaky, like java 3D. Sean Grove: I'd be happy to show my frame-hash implementation as long as you won't laugh too hard at it. I'll throw it up on github sometime soon after I clean it up a bit. I like it because a video treated as just a sequence of hash-maps which flows through an image processing pipeline. I have to say I've been surprised at the state of video in java. It's time to make it better with a clojure library devoted to pulling together the best of all these different methods. When I figure out a way to solve my problems with these recommendations I'll put that up too. thanks a lot, --Robert McIntyre On Mon, Sep 6, 2010 at 9:43 PM, Marc Downie m...@openendedgroup.com wrote: On Mon, Sep 6, 2010 at 5:45 PM, Sean Grove otokora...@gmail.com wrote: On Sep 6, 2010, at 2:57 PM, Robert McIntyre wrote: I was wondering if anyone has used clojure for image/video processing and how that has worked out. We've been rolling our own, either using Apple's Core Image framework or our own OpenGL / FrameBuffer Object library for processing video and gigabit ethernet machine vision cameras for input. I'm afraid that Video in Java is in pretty rough shape right now. I haven't personally used it, but I'd take a look at either http://github.com/ztellman/calx — that's OpenCL for Clojure or Java or the Java level bindings for OpenCL (which I have used a bit) — http://code.google.com/p/nativelibs4java/wiki/OpenCL . If you can formulate your problem in OpenCL the speed can be jaw slackening, and it has a far smaller conceptual footprint than OpenGL. Images: For image processing, I've just been using the java2d api, a la http://www.javaworld.com/javaworld/jw-09-1998/jw-09-media.html?page=1 It's quite low-level, but it works well enough for my basic needs right now. OpenCV : tried two different jna bindings but had many horrible memory leaks and crashes I've been doing some stuff with OpenCV (yes, there are definite problems here, but at least it kind of works) to get access to the webcam. Setting it up was a nightmare though... OpenCV is a sprawling library with a long history. Recently, Willow Garage have taken it over and are now cleaning it up and moving it forward. The Java bindings that I'm familiar with expose a some sliver of the library, and never the sliver I'm interested in. There are gems in there though — just tunnel in through JNI, dig them out and make a quick exit before that C/C++ smell gets in your hair. As far as I know it doesn't really have any camera access code in it to call its own, rather it wraps other libraries. If you want to get serious, I'd go straight to them (for example libdc1394, or the Java Prosillica SDK). Video: Processing: still don't know at all what this is or how to get it to work. Processing is a bigger library, I believe OpenCV is a sub-project of it. That's not really the case. There are one or two Java OpenCV bindings that are targeted at the Processing community. Processing refers to 4 things together — a simplified Java syntax; a simple IDE for writing and compiling code in this syntax; a core Java API that's mainly for drawing things (that abstracts away the differences between Java2D, OpenGL and potentially other renderers) and finally an enormous community of Java libraries usually designed with simplicity in mind. Only these latter two things are potentially interesting for people using Clojure — for example, Incanter can use Processing's core library as its drawing back end. For video input Processing has traditionally used Quicktime for Java, but as I understand it they are trying to move to something else, perhaps GStreamer-java? (http://code.google.com/p/gstreamer-java/). I can't
Re: union using a comparison function
By union do you mean union as in sets, or just smashing the two lists together? --Robert McIntyre On Thu, Sep 2, 2010 at 11:10 AM, mlimotte mslimo...@gmail.com wrote: Hi. I'd like to do a union of some sequences using my own comparison function. Similar to supplying a Comparator in Java. The things being compared are Objects from a Java library that I don't control, so I can't just override the equals function on the class, for example. Would aprecaite any suggestions. thanks, Marc -- You 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 -- You 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: Help speed up an inner loop?
Ah, I see that I was mistaken about the timing. Sorry about that. After a lot of fiddling around, I cam up with this faster form: (defn countnl-lite [#^bytes buf] (areduce buf idx count (int 0) (if (= (clojure.lang.RT/aget buf idx) 10) (unchecked-add count 1) count))) Key points are initializing count to a primitive integer and directly calling clojure's aget to avoid an unnecessary integer cast. On my system: The unmodified countnl function takes ~ 180 msecs Without AOT compilation countnl-lite takes around 66 msecs With AOT compilation countnl-lite takes ~46 msecs The java method takes ~19 msecs. I've lost a factor of 2.25 somewhere and it makes me sad that I can't find it. I would be very interested if anyone could improve countnl-lite. --Robert McIntyre On Mon, Aug 30, 2010 at 8:41 PM, Alan a...@malloys.org wrote: I think this misses the point. Of course java, c, and clojure will all have roughly the same wall-clock time for this program, since it is dominated by the I/O. You can even see that in the output from $ time java Iterate: less than 0.5s was spent in user space, the rest was spent in system code - that is, mostly doing I/O. The java version is a second faster as counted by the wall clock, and this is unlikely to be a coincidence: tsuraan's timing data suggests that the clojure program takes 80ms longer in each loop, and loops 10 times. That comes out to 0.8 seconds, which is quite close to the differential you observed when timing from the command line. On Aug 30, 1:38 pm, Robert McIntyre r...@mit.edu wrote: I don't know what the heck is going here, but ignore the time the program is reporting and just pay attention to how long it actually takes wall-clock style and you'll see that your clojure and java programs already take the same time. Here are my findings: I saved Iterate.java into my rlm package and ran: time java -server rlm.Iterate results: time java -server rlm.Iterate Wanted 16777216 got 16777216 bytes counted 65341 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 66026 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65473 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65679 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65739 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65810 nls in 18 msec Wanted 16777216 got 16777216 bytes counted 65531 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65418 nls in 21 msec real 0m27.469s user 0m0.472s sys 0m26.638s I wrapped the last bunch of commands in your clojure script into a (run) function: (defn run [] (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls)) and ran (time (run)) at the repl: (time (run)) Wanted 16777216 got 16777216 bytes Elapsed time: 183.081975 msecs Got 65894 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.001814 msecs Got 65949 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.061934 msecs Got 65603 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.031131 msecs Got 65563 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.122567 msecs Got 65696 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.968066 msecs Got 65546 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.058508 msecs Got 65468 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.932395 msecs Got 65872 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.074646 msecs Got 65498 nls Wanted 16777216 got 16777216 bytes Elapsed time: 187.733636 msecs Got 65434 nls Elapsed time: 28510.331507 msecs nil Total running time for both programs is around 28 seconds. The java program seems to be incorrectly reporting it's time. --Robert McIntyre On Mon, Aug 30, 2010 at 4:03 PM, tsuraan tsur...@gmail.com wrote: Just to try to see if clojure is a practical language for doing byte-level work (parsing files, network streams, etc), I wrote a trivial function to iterate through a buffer of bytes and count all the newlines that it sees. For my testing, I've written a C version, a Java version, and a Clojure version. I'm running each routine 10 times over a 16MB buffer read from /dev/urandom (the buffer is refreshed between each call to the newline counting function). With gcc -O0, I get about 80ms per 16MB buffer. With gcc -O3, I get ~14ms per buffer. With javac (and java -server) I get 20ms per 16MB buffer. With clojure, I get 105ms per buffer (after the jvm warms up). I'm guessing that the huge boost that java and gcc -O3 get is from
Re: Problem reloading source file with imports
Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, Chris -- You 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 -- You 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: Help speed up an inner loop?
I don't know what the heck is going here, but ignore the time the program is reporting and just pay attention to how long it actually takes wall-clock style and you'll see that your clojure and java programs already take the same time. Here are my findings: I saved Iterate.java into my rlm package and ran: time java -server rlm.Iterate results: time java -server rlm.Iterate Wanted 16777216 got 16777216 bytes counted 65341 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 27 msec Wanted 16777216 got 16777216 bytes counted 66026 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65473 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65679 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65739 nls in 19 msec Wanted 16777216 got 16777216 bytes counted 65310 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65810 nls in 18 msec Wanted 16777216 got 16777216 bytes counted 65531 nls in 21 msec Wanted 16777216 got 16777216 bytes counted 65418 nls in 21 msec real0m27.469s user0m0.472s sys 0m26.638s I wrapped the last bunch of commands in your clojure script into a (run) function: (defn run [] (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls)) and ran (time (run)) at the repl: (time (run)) Wanted 16777216 got 16777216 bytes Elapsed time: 183.081975 msecs Got 65894 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.001814 msecs Got 65949 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.061934 msecs Got 65603 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.031131 msecs Got 65563 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.122567 msecs Got 65696 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.968066 msecs Got 65546 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.058508 msecs Got 65468 nls Wanted 16777216 got 16777216 bytes Elapsed time: 182.932395 msecs Got 65872 nls Wanted 16777216 got 16777216 bytes Elapsed time: 183.074646 msecs Got 65498 nls Wanted 16777216 got 16777216 bytes Elapsed time: 187.733636 msecs Got 65434 nls Elapsed time: 28510.331507 msecs nil Total running time for both programs is around 28 seconds. The java program seems to be incorrectly reporting it's time. --Robert McIntyre On Mon, Aug 30, 2010 at 4:03 PM, tsuraan tsur...@gmail.com wrote: Just to try to see if clojure is a practical language for doing byte-level work (parsing files, network streams, etc), I wrote a trivial function to iterate through a buffer of bytes and count all the newlines that it sees. For my testing, I've written a C version, a Java version, and a Clojure version. I'm running each routine 10 times over a 16MB buffer read from /dev/urandom (the buffer is refreshed between each call to the newline counting function). With gcc -O0, I get about 80ms per 16MB buffer. With gcc -O3, I get ~14ms per buffer. With javac (and java -server) I get 20ms per 16MB buffer. With clojure, I get 105ms per buffer (after the jvm warms up). I'm guessing that the huge boost that java and gcc -O3 get is from converting per-byte operations to per-int ops; at least that ~4x boost looks like it would come from something like that. Is that an optimization that is unavailable to clojure? The java_interop doc makes it sound like java and clojure get the exact same bytecode when using areduce correctly, so maybe there's something I could be doing better. Here are my small programs; if somebody could suggest improvements, I'd appreciate them. iterate.clj: (set! *warn-on-reflection* true) (import java.io.FileInputStream) (def *numbytes* (* 16 1024 1024)) (defn countnl [#^bytes buf] (let [nl (byte 10)] (areduce buf idx count 0 (if (= (aget buf idx) nl) (inc count) count (let [ifs (FileInputStream. /dev/urandom) buf (make-array Byte/TYPE *numbytes*)] (dotimes [_ 10] (let [sz (.read ifs buf)] (println Wanted *numbytes* got sz bytes) (let [count (time (countnl buf))] (println Got count nls) Iterate.java: import java.io.FileInputStream; class Iterate { static final int NUMBYTES = 16*1024*1024; static int countnl(byte[] buf) { int count = 0; for(int i = 0; i buf.length; i++) { if(buf[i] == '\n') { count++; } } return count; } public static final void main(String[] args) throws Throwable { FileInputStream input = new FileInputStream(/dev/urandom); byte[] buf = new byte[NUMBYTES]; int sz; long start, end; for(int i = 0; i 10; i++) { sz = input.read(buf); System.out.println(Wanted + NUMBYTES + got + sz + bytes); start = System.currentTimeMillis(); int count = countnl(buf
Re: Problem reloading source file with imports
Sorry, I was tired and didn't explain very well. Right now you have a naked (:use clojure.contrib.seq-utils) somewhere. You want to use partition-by, but that's already in core, so you might just get rid of the :use altogether. But maybe there are some other functions in seq-utils that you do want to use --- in that case, do (:use [clojure.contrib [seq-utils :only [functions you want]]]) or (:use [clojure.contrib [seq-utils :only []]]) to avoid stepping on core and also to document what you actually use. If you really want the seq-utils version of partition-by, then you can do: (:use [clojure.contrib [seq-utils :as whatever]]) whatever/partition-by And if you really want to replace the core version with the seq version without any namespacing, do (:refer-clojure :exclude [partition-by]) (:use [clojure.contrib [seq-utils :only [partition-by]]]) does that help? --Robert McIntyre On Mon, Aug 30, 2010 at 2:43 PM, Chris Jenkins cdpjenk...@gmail.com wrote: How would using the :only keyword help here? Just to be clear, the problem here is that attempting to load my source file the second time fails (loading the first time having succeeded, albeit with a few warnings about replacing symbols from clojure.core), which makes it very difficult for me to use swank-clojure, for example, because I can't hit C-c C-k twice on the same file. Here is the failure when I try to load the file for the second time: java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) So here's my main question: If I'm working in the REPL and I edit a file that I've preu'vviously loaded, how can I cause the file to be reloaded without hitting that error? If my .clj file doesn't :use any other clojure modules then reloading works fine but, if it imports anything, then the second (load-file...) fails. On 30 August 2010 11:05, Robert McIntyre r...@mit.edu wrote: Yeah, they changed that from clojure 1.1 and it's really annoying --- as far as I know, your only options right now are to either select exactly which functions from seq-utils you want using the :only keyword, or if you really want to use the seq-utils version you can use refer-clojure and the :exclude keyword. Or, you can use the :as keyword in the :use form to qualify the import so that you don't actually replace anything. If you accidently get this warning and don't want to restart the repl you can do (ns-unmap 'your-namespace 'offending-function), fix the naked import, and reload. --Robert McIntyre On Mon, Aug 30, 2010 at 5:54 AM, Chris Jenkins cdpjenk...@gmail.com wrote: Since I switched to Clojure 1.2, I see an error message whenever I try to reload a source file that imports anything. The error message is of the form already refers to xxx, as though it is complaining that it can't import the same thing twice. For example, I have a minimal source file that looks like this: (ns test.core (:use clojure.contrib.seq-utils)) I can load it (once!) into the Clojure REPL successfully: $ java -cp lib/clojure-contrib-1.2.0.jar:lib/clojure-1.2.0.jar clojure.main Clojure 1.2.0 user= (load-file src/test/core.clj) WARNING: partition-by already refers to: #'clojure.core/partition-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-by WARNING: frequencies already refers to: #'clojure.core/frequencies in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/frequencies WARNING: shuffle already refers to: #'clojure.core/shuffle in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/shuffle WARNING: reductions already refers to: #'clojure.core/reductions in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/reductions WARNING: partition-all already refers to: #'clojure.core/partition-all in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/partition-all WARNING: group-by already refers to: #'clojure.core/group-by in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/group-by WARNING: flatten already refers to: #'clojure.core/flatten in namespace: test.core, being replaced by: #'clojure.contrib.seq-utils/flatten nil If I try to reload it then I see an error message: user= (load-file src/test/core.clj) java.lang.IllegalStateException: partition-by already refers to: #'clojure.contrib.seq-utils/partition-by in namespace: test.core (core.clj:1) user= This error message is seen even if I edit the source file and remove the (:use ...) clause and then try to load the file again. Anyone have any idea what is going on? I didn't see this behaviour in Clojure 1.1 and it would be nice if I could find a way to reload files that I'm working on. Cheers, Chris -- You received this message because you are subscribed to the Google Groups Clojure
Re: Is it possible in theory to write/modify a Clojure compiler that doesn't
Has anyone actually implemented this sort of placeholder strategy before? --Robert McIntyre On Sat, Aug 28, 2010 at 3:04 PM, Michael Wood esiot...@gmail.com wrote: On 28 August 2010 19:27, Michał Marczyk michal.marc...@gmail.com wrote: On 28 August 2010 19:19, Luke VanderHart luke.vanderh...@gmail.com wrote: I'm not just talking about class hierarchy dependencies, but also reference dependencies. Ah, I see. In that case, maybe generate placeholders for all the classes to be implemented in Clojure (with all methods doing something like throw new RuntimeException()), compile those stubs with javac together with all the Java classes, then discard the placeholder .class files and compile the Clojure classes? I believe this discussion has been had before with similar conclusion. -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 -- You 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: where did I read that?
That's a neat improvement to be able to ignore the value when you don't need it, thanks Michał Marczyk. Also, though both proxies happen to work with clojure's (read) function, every read operation of the pushback reader would have to be wrapped in the variable changing code to guarantee correctness in all cases. So the proxy needs about 3-5 more methods to be a complete covering. you wouldn't want me to do (.skip reader 5) and have *current-char-number* become wrong! The perils of mutable state are made of this... :( From a code reuse standpoint, isn't this kinda lame? --Robert McIntyre On Sat, Aug 28, 2010 at 5:28 PM, Michał Marczyk michal.marc...@gmail.com wrote: On 28 August 2010 22:14, evins.mi...@gmail.com evins.mi...@gmail.com wrote: I was actually asking how to avoid doing what you did :-). If it's necessary to do it, that's fine, but I thought I'd ask first, in case there was a way around it that I hadn't noticed. Well, some level of reimplementation will probably be necessary (if there is an implementation of an indexing reader in the base class libraries, I'd love to learn about it, but I don't think there is!). Having said that, you could take Robert's approach and have the proxy implement a new interface (which you can define through definterface) to check current offset: ;;; untested... (definterface IReaderOffset (^int readerOffset [])) ;;; and the proxy form: (proxy [java.io.PushbackReader IReaderOffset] [...] (read ...) (unread ...) (readerOffset [] @*current-char-number*)) ;;; also, drop the final (fn ...) form from read-with-number -- ;;; return the proxy itself instead; maybe also rename ;;; to e.g. indexing-reader? Then you could use the regular read function and say (.readerOffset reader-instance) to find out what the current index is. This does at least have the nice property that you can ignore the extra information when it's not needed (as you could with multiple return values in CL). Sincerely, Michał -- You 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 -- You 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 in theory to write/modify a Clojure compiler that doesn't
I don't think two pases is enough. What if a clojure file uses reflection (with macros of course) on a compiled java file to generate classes, sort of like how lancet works but generating classes instead of functions? And then those classes are used from other clojure and java files. Oh, and then another clojure file does the same reflection based junk to make more classes, from the classes that were generated from the first clojure file. These classes are, of course, used by other java and clojure files. In this case the only way I can think to compile everything (and sadly I'm doing something like this on my current project in lieu of a better way) is to: try to compile all the java files first (fail at some), try to compile all the clojure files (fail at some), try to compile all the java files (fail at some, but a little bit less than the first time), repeat until bytecode-level quiescence. The clojure compiler and java compiler will at most have to be invoked something like n times where n is the total number of source files in the project in certain pathological conditions as above. However, no matter what crazy stuff they're doing, as long as there no circular dependencies I think I can prove that this process will always make progress and converge to a steady state. I can make a concrete example of this condition if anyone's interested (at least I think I can!) As wasteful as it sounds is it really that bad? If the compilers only tried files that weren't already compiled and had minimal startup time then this sort of oscillation can be continued until quiescence is reached and will only take around the same time as single pass over all files. I've screwed around with this a lot and think that it would be a triumph if clojure and java could be intermixed freely. Then, there are no barriers to rewriting just one piece of a tightly interconnected java program in clojure for greater clarity/efficiency. You can just replace one java file with one clojure file, and use a java-clojure aware compiler instead of pure javac. I dream of the day where you could do this in a streamlined way in eclipse, so that everyone else on the project can focus on the concepts behind the program, not trivial minutiae like compile order. --Robert McIntyre On Sun, Aug 29, 2010 at 4:46 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, Am 28.08.2010 um 19:09 schrieb Michał Marczyk: I'm sure I'm missing lots of things, but I'd love to know which, so -- please let me know. :-) In fact, your two-pass scenario is probably the best you can get, since you can define arbitrary classes in arbitrary namespaces. (Whether this is advisable is a different question!) So any compiler trying to translate a classname to a defining namespace must fail in general. This could only be remedied by following a convention of one class per namespace which is quite a restriction. Just scanning the source files will also fail, because classes might be generated by macros. And macros might to depend on arbitrary functions defined in the file. So they can only be expanded by loading the file and executing the functions. Hence you cannot discover class generation in general. So I would suspect that your two pass scenario is a strict limit. Sincerely Meikel -- You 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 -- You 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: where did I read that?
I took a stab at it and came up with this: (defn make-reader [s] (java.io.PushbackReader. (java.io.CharArrayReader. (into-array Character/TYPE (seq s) (defn read-with-number like read but takes in a string and returns a function of no arguments which will read the string and provide char number as in Common Lisp [string] (let [*current-char-number* (atom 0) numbering-pushback-reader (proxy [java.io.PushbackReader] [(make-reader string)] (read [] (swap! *current-char-number* inc) (proxy-super read )) (unread [stuff] (swap! *current-char-number* dec) (proxy-super unread stuff)) )] (fn [] [(read numbering-pushback-reader) (deref *current-char-number*)]))) Now you can do: mobius.physics (def read-oh-yeah! (read-with-number (vector 1 2 3) (list 5 6))) #'mobius.physics/read-oh-yeah! mobius.physics (read-oh-yeah!) [(vector 1 2 3) 14] mobius.physics (read-oh-yeah!) [(list 5 6) 25] is that what you're going for? please tell me how I can improve this! --Robert McIntyre On Sat, Aug 28, 2010 at 1:26 AM, evins.mi...@gmail.com evins.mi...@gmail.com wrote: I'm working on a project in which it would be very useful to be able to easily determine how many characters were consumed in the course of a read operation, in a similar fashion to the way that Common Lisp's read-from-string returns as a second value the index of the next character of the input past the end of the object that was read. I want to, for example, read Clojure values from a buffer and keep track of where in the buffer they were read from. Anyone have any good ideas of how to accomplish this without some level of reimplementation of read? -- You 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 -- You 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: Does Clojure has a compiler
Yes, clojure has a compiler that can compile directly to class files. There's more information here: http://clojure.org/compilation and a short demo that you can try here: http://www.rlmcintyre.com/iassac-gouy.tar.bz2 or http://www.bortreb.com/iassac-gouy.tar.bz2 --Robert McIntyre On Wed, Aug 25, 2010 at 10:17 PM, HB hubaghd...@gmail.com wrote: Hey, Both Groovy and Scala have a compiler to produce class files. Does Clojure has a compiler? Do Clojure files are compiled usually? 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 -- You 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
What is the best way to parasitically invade a java project with clojure goodness?
Let's say my group has a fairly large java project on which ~20 people are working. We want to start using clojure with our existing code. Specifically, we want to have clojure classes that provide functions for our java classes, and vice versa. Two questions on the best way to do this: (:1 Should the clojure source files intermingle with the java source files, each according to it's relavance to the problem, or should there be a top level separation between them?) (:2 Say I have this: English.java --- which defines some cool data structure representing English sentences Chinese.java --- same as above except for Chinese. awesome-junk.clj --- which provides unthinkably cool AI functions that map English objects to Chinese objects. This is AOT compiled so other things can use it. PainstakinglyMadeGUI.java --- which provides an awesome GUI that uses the English and Chinese objects and calls the functions provided by awesome-junk. Now, how can I build this project from nothing!? You can't compile all the java objects first, because they need awesome-junk.clj. You can't compile awesome-junk first, because it needs Chinese and English class files to exist. What do you do? What if you have 20 java files and 20 clj files that all depend on each other in interesting ways? This isn't a problem with pure java because you just throw them all together at-once and let javac sort em' out. Can it be just as easy with a heterogeneous mix of files? (maybe with an eclipse plugin or something?)) --Robert McIntyre -- You 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: AOT compilation newbie mistakes
oh yes -- please don't do it manually for anything production But, it's good to know what's actually going on behind the scenes, especially when things stop working :) --Robert McIntyre On Sun, Aug 22, 2010 at 7:05 PM, Wilson MacGyver wmacgy...@gmail.com wrote: On Sun, Aug 22, 2010 at 2:39 PM, Isaac Gouy igo...@yahoo.com wrote: 2) How can I AOT compile Clojure files without using the REPL? on this point, I think most people use build tools to do it. gradle with clojuresque plugin, lein and mvn with clojure plugin will all do this. -- Omnem crede diem tibi diluxisse supremum. -- You 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 -- You 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