Re: jna Java Native Acess and clojure ....
Access to C/C++ is only available via JNI, which requires a bit of technical understanding about the Java-C bridge. Are you just trying to make use of a C++ library you already have, for which there is no pure Java equivalent? -Fred -- Science answers questions; philosophy questions answers. On Aug 10, 2010, at 6:29 AM, Sunil S Nandihalli wrote: Thanks Mac for your clarification .. I am using clojure 1.2 .. so should be fine. And I was wondering if I can acess c++ stuff via clj-native .. What are your suggestions? Sunil On Tue, Aug 10, 2010 at 12:45 PM, mac markus.gustavs...@gmail.com wrote: I'm the author of clj-native. Currently it only works with Clojure 1.2. In retrospect I should have made a separate branch when dropping 1.1 support. If you need 1.1 support, just tell me and I could make a branch for it since the changes required should be small. /Markus On Aug 9, 5:31 pm, Chouser chou...@gmail.com wrote: On Mon, Aug 9, 2010 at 10:55 AM, Sunil Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, I have been trying to use the native libraries in clojure. I have found clj-native and clojure-jna which may serve the purposes. I would like to get a feed back from the community .. Which of these is good to use .. Or do you have any other suggestions.. I wrote clojure-jna, but although I haven't had a chance to use clj-native yet I understand it's significantly more advanced and efficient than clojure-jna. So I'd recommend at least starting with clj-native to see if it will meet your needs. --Chouserhttp://joyofclojure.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 -- You 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 links for beginners
That is the most unsubstantiated, moronic piece of writing I've ever read in my life. I can't really tell what he's attacking, he's just swinging some dick-shaped sword around trying to hit stuff. -Fred -- Science answers questions; philosophy questions answers. On Aug 3, 2010, at 6:30 AM, faenvie wrote: 2. an article to read after 1. IMO that is useful as an antitoxin for beginners: http://imagine27.com/articles/2009-08-19-011225_clojure_the_false_lisp.html because excitement is always a bad thing ... isn't it ? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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 no tail call optimization
It means that the JVM doesn't look at method calls and figure out that they're in tail call position and optimize them. You can hand-write code that performs a goto in a tight loop (like recur does), but means you can't assume that method calls in general will be tail call optimized. -Fred -- Science answers questions; philosophy questions answers. On Aug 2, 2010, at 4:09 PM, Dale wrote: The JVM has an unconditional goto opcode and the ability to re-bind function parameters, so why no tail-call optimization? Thanks. Dale -- You 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: defrecord and map equality?
I'm sure it's not intentional, but it makes sense. In the first case, the comparison delegates to `r`'s equals() method, which would return false because {:a 1} isn't a `my-record`. In the second case, the comparison delegates to `{:a 1}`'s equals() method, which is a PersistentArrayMap, which would return true, because it's just looking for equality of map entries. Not sure how to make this behave consistently without introducing a lot of weirdness into the language. -Fred -- Science answers questions; philosophy questions answers. On Jul 29, 2010, at 10:51 PM, Ryan Twitchell wrote: Hi all, I noticed (with a very recent git pull) the following asymmetric behavior regarding = and records: (defrecord my-record [a]) (def r (new my-record 1)) (def s (new my-record 1)) (= r s);; true (= s r);; true (= r {:a 1}) ;; false (= {:a 1} r) ;; true Is this intentional? (I hope not) -- You 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: RegEx
If you want a single regex that matches either M123.5554 or 1234.435M, you need to use the OR form (a|b): ([ML]\d+\.\d+|\d+\.\d+[ML]) where: [ML] matches M or L \d+ matches 1 or more digits \. matches a . -Fred -- Science answers questions; philosophy questions answers. On Jul 30, 2010, at 4:02 PM, Base wrote: Hi All - I am sure that this is an easy one, but I am stuck. I have a document that should have triplets of a letter (M or L) flllowed by 2 numbers. But the file has a ton of errors and often I find a number that would be M123.5554 or 1234.435M i.e. - the letter gets appended to the end of the number. This seems like a great place to use regexhow would one craft a pattern for this? Thanks Base -- You 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: Two convenience methods
http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/some -- Science answers questions; philosophy questions answers. On Jul 21, 2010, at 4:45 PM, Travis Hoffman wrote: (defn any? Returns true if (pred x) is logically true for one x in coll, else false. {:added 1.3 :tag Boolean} [pred coll] (when (seq coll) (or (pred (first coll)) (recur pred (next coll) -- You 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: Two convenience methods
Or [using clojure.set] (empty? (intersection s1 s2)). -- Science answers questions; philosophy questions answers. On Jul 21, 2010, at 4:45 PM, Travis Hoffman wrote: The second function is suggested as an addition to clojure.set. The disjoint? function decides if two sets have no elements in common. This can easily be done using: (not (nil? (intersection s1 s2))) but this implementation should be more efficient (I think) and is more readable, imho: (defn disjoint? Is set1 disjoint from set2? {:added 1.3 :tag Boolean} [set1 set2] (if (= (count set1) (count set2)) (recur set2 set1) (not-any? (fn [item] (contains? item set1)) set2))) -- You 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: Two convenience methods
Ok you said this too. :) But the non-booleanness of (some ...) isn't that important. The result of (some ...) is truthy, and can be used in any boolean context. -Fred -- Science answers questions; philosophy questions answers. On Jul 21, 2010, at 8:07 PM, Frederick Polgardy wrote: http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/some -- Science answers questions; philosophy questions answers. On Jul 21, 2010, at 4:45 PM, Travis Hoffman wrote: (defn any? Returns true if (pred x) is logically true for one x in coll, else false. {:added 1.3 :tag Boolean} [pred coll] (when (seq coll) (or (pred (first coll)) (recur pred (next coll) -- You 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 functional, efficient, convolution function. Is imperitive-style the answer?
This statement is interesting. Part of what makes the Python implementation so expressive is precisely the use of functional constructs like list comprehensions, ranges, and all the awesome stuff in itertools. A purely imperative implementation would probably be as clunky as the purely functional ones, but for different reasons. -Fred -- Science answers questions; philosophy questions answers. On Jul 16, 2010, at 2:57 PM, Isaac Hodes wrote: I have a Python implementation to show how nicely it can be expressed in an imperitive language (though I suppose I dabbled in the functional style initializing my return array). -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com 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: Response
This example is beside the point of the original question. It uses mutable arrays. It's very much dropping to the Java level. Am I missing something? -Fred -- Science answers questions; philosophy questions answers. On Jul 17, 2010, at 6:04 PM, David Nolen wrote: (defn ^{:static true} convolve ^doubles [^doubles xs ^doubles is] (let [xlen (count xs) ilen (count is) ys (double-array (dec (+ xlen ilen)))] (dotimes [p xlen] (dotimes [q ilen] (let [n (+ p q), x (aget xs p), i (aget is q), y (aget ys n)] (aset ys n (+ (* x i) y) ys)) I don't think this is so bad and it can do a million points in ~400ms on my machine. 100,000 points in ~25ms. I don't consider this dropping to the Java level at all. -- You 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: Response
I think it really doesn't get any clearer than this in terms of intent. While I was adept at calculus-level math 20 years ago, I've forgotten the little I knew of matrices. This is the first algorithm that has communicated by visual inspection (to me) exactly what a convolution is. -Fred -- Science answers questions; philosophy questions answers. On Jul 17, 2010, at 3:43 PM, Isaac Hodes wrote: double convolve(double *xs, double *is, double *ys){ int i,j; for(i=0; ilen(xs); i++){ for(j=0; jlen(is); j++){ ys[i+j] = ys[i+j] + (xs[i]*is[j]); } } return ys; } -- You 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 functional, efficient, convolution function. Is imperitive-style the answer?
Where's the link? :) -Fred -- Science answers questions; philosophy questions answers. On Jul 16, 2010, at 2:57 PM, Isaac Hodes wrote: I posted this on StackOverflow yesterday, but to no avail: I don't think many people looked at it, or least I didn't get much feedback. I am trying to create a lazy/functional/efficient/Clojuresque function to carry out convolution on two lists/vectors of (ideally BigDecimals but that may be inefficient) doubles. It is turning out to be very difficult. I have four or five versions in my buffer right now, and none of them are acceptable. I've even tried a number of versions using into-array etc, e.g. mutables. Instead of posting a lot of links to pastie, I'm just copying the SO link here, where my code and the algorithms can be found. Right now, it seems as though this is something Clojure cannot do. David Nolen mentioned that the appropriate Java-interop functionality may come in Clojure 1.3, but aside from eschewing the functional style by using arrays, it seems as though there should be a better answer. (As an aside, where can I find out about 1.3?) I have a Python implementation to show how nicely it can be expressed in an imperitive language (though I suppose I dabbled in the functional style initializing my return array). Is it possible to do this, and do it well? Thank you so much, 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
Re: Clojure noob: refactoring factorial code
You don't need to recur to another function, just recur to a loop: (defn factorial [n] (loop [x n acc 1] (if (zero? x) acc (recur (dec x) (* acc x) (println (factorial 5)) -- Science answers questions; philosophy questions answers. On Jul 15, 2010, at 6:38 AM, Brisance wrote: Here's a factorial function as found in the WikiBook Learning Clojure http://en.wikibooks.org/wiki/Learning_Clojure: (defn factorial [n] (defn fac [n acc] (if (zero? n) acc (recur (- n 1) (* acc n ; recursive call to fac, but reuses the stack; n will be (- n 1), and acc will be (* acc n) (fac n 1)) Question: how would I go about writing idiomatic Clojure to return factorials of n, for large values of n. e.g. 1e6 or more? Preferably without having to create another function. Thanks in advance for any insight. -- You 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 noob: refactoring factorial code
Well, no, I was merely demonstrating how to use loop/recur. -- Science answers questions; philosophy questions answers. On Jul 15, 2010, at 8:52 AM, Daniel Gagnon wrote: There's no reason to recur at all: (defn factorial [n] (reduce * (range 1 (inc n On Thu, Jul 15, 2010 at 9:49 AM, Frederick Polgardy f...@polgardy.com wrote: You don't need to recur to another function, just recur to a loop: (defn factorial [n] (loop [x n acc 1] (if (zero? x) acc (recur (dec x) (* acc x) (println (factorial 5)) -- Science answers questions; philosophy questions answers. On Jul 15, 2010, at 6:38 AM, Brisance wrote: Here's a factorial function as found in the WikiBook Learning Clojure http://en.wikibooks.org/wiki/Learning_Clojure: (defn factorial [n] (defn fac [n acc] (if (zero? n) acc (recur (- n 1) (* acc n ; recursive call to fac, but reuses the stack; n will be (- n 1), and acc will be (* acc n) (fac n 1)) Question: how would I go about writing idiomatic Clojure to return factorials of n, for large values of n. e.g. 1e6 or more? Preferably without having to create another function. Thanks in advance for any insight. -- You 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: Typed Racket
A big part of it is that Clojure, being based on the JVM, has to deal with inheritance and polymorphism in the core type system. An algebraic type system like that of Haskell, OCaml, Scheme doesn't have to deal with inheritance. There is parametric polymorphism, but that's based on type classes, not inheritance. -Fred -- Science answers questions; philosophy questions answers. On Jul 15, 2010, at 5:23 PM, ntu...@googlemail.com wrote: On Jul 15, 8:16 pm, Tomi Neste tomi.ne...@gmail.com wrote: But I don't think it would be easy to make it work with Clojure, given how polymorphic and dynamic the language is (IMHO Scheme is not too far from ML when it comes to type systems). Please expand. - nt -- You 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 1.2 Beta 1
Awesome! Looks great. What branch/tag of clojure-contrib is the clojure-contrib-1.2.0- beta1.zip download built from? I don't see it under branches, and master builds clojure-contrib-1.2.0-SNAPSHOT.jar. Thanks. On Jul 14, 10:03 am, Stuart Halloway stuart.hallo...@gmail.com wrote: Clojure 1.2 Beta 1 is now available, along with a corresponding Clojure Contrib, at: http://clojure.org/downloads It contains significant new features, as well as many bug fixes and small enhancements. A larger number of contributors than ever before have pitched in. You can see an overview of the changes in the changes file at: http://github.com/clojure/clojure/blob/1.2.x/changes.txt For maven/leiningen users, your settings to get the beta from build.clojure.org/releases are: :dependencies [[org.clojure/clojure 1.2.0-beta1] [org.clojure/clojure-contrib 1.2.0-beta1] To everyone who has contributed to 1.2, many thanks! Stu -- You 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