Re: How much Clojure source code is complicated?
Here you can peek at the source code of clojure. http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/core.clj It is about 3700 lines, and although you have to get used to a few new functions and names that are normally not exposed when you use clojure, it looks fairly simple. Here is the function that defines defn itself. Most functions in the source are a magnitude easier than this one for us newbies =). (def #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-string or attrs added to the var metadata" :arglists '([name doc-string? attr-map? [params*] body] [name doc-string? attr-map? ([params*] body)+ attr- map?])} defn (fn defn [name & fdecl] (let [m (if (string? (first fdecl)) {:doc (first fdecl)} {}) fdecl (if (string? (first fdecl)) (rest fdecl) fdecl) m (if (map? (first fdecl)) (conj m (first fdecl)) m) fdecl (if (map? (first fdecl)) (rest fdecl) fdecl) fdecl (if (vector? (first fdecl)) (list fdecl) fdecl) m (if (map? (last fdecl)) (conj m (last fdecl)) m) fdecl (if (map? (last fdecl)) (butlast fdecl) fdecl) m (conj {:arglists (list 'quote (sigs fdecl))} m)] (list 'def (with-meta name (conj (if (meta name) (meta name) {}) m)) (cons `fn fdecl) On Jan 13, 8:51 am, HB wrote: > Hey, > How much Clojure source code is complicated? > I'm not a programming Godfather but I would like to study Clojure > source code. > Could an intermediate programmer like me grasp the source code? > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
Do you suggest that I read "Programming Clojure" first and then trying to study the source code? What is the best place (file, package or what ever) to start reading the source code? On Jan 13, 10:01 am, bOR_ wrote: > Here you can peek at the source code of clojure. > > http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > It is about 3700 lines, and although you have to get used to a few new > functions and names that are normally not exposed when you use > clojure, it looks fairly simple. > > Here is the function that defines defn itself. Most functions in the > source are a magnitude easier than this one for us newbies =). > > (def > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > name (fn ([params* ] exprs*)+)) with any doc-string or attrs added > to the var metadata" > :arglists '([name doc-string? attr-map? [params*] body] > [name doc-string? attr-map? ([params*] body)+ attr- > map?])} > defn (fn defn [name & fdecl] > (let [m (if (string? (first fdecl)) > {:doc (first fdecl)} > {}) > fdecl (if (string? (first fdecl)) > (rest fdecl) > fdecl) > m (if (map? (first fdecl)) > (conj m (first fdecl)) > m) > fdecl (if (map? (first fdecl)) > (rest fdecl) > fdecl) > fdecl (if (vector? (first fdecl)) > (list fdecl) > fdecl) > m (if (map? (last fdecl)) > (conj m (last fdecl)) > m) > fdecl (if (map? (last fdecl)) > (butlast fdecl) > fdecl) > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > (list 'def (with-meta name (conj (if (meta name) (meta name) > {}) m)) > (cons `fn fdecl) > > On Jan 13, 8:51 am, HB wrote: > > > Hey, > > How much Clojure source code is complicated? > > I'm not a programming Godfather but I would like to study Clojure > > source code. > > Could an intermediate programmer like me grasp the source code? > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
On Jan 13, 2:59 pm, Chouser wrote: > > It raises a question, though -- how much functionality should a > function provide to be worth making everyone who reads the code learn > the new vocabulary? I've written each of these inline when I've > needed them. Are they better as idioms or functions? I can't comment on which ones I would use: I'm too new to Clojure for that. But I think a rich utility library is good, so long as it's clear from a function's name and parameters what it does. There are only a few in the collection above whose purpose I don't understand; for most I see it easily. One question about the collection: > (defn chunk "Lazily break s into chunks of length n (or less, for the > final chunk)." > [n s] > (when (seq s) >(lazy-cons (take n s) > (chunk n (drop n s) Should that "seq" be "seq?". If not, why not? The general question it raises for _me_ is this: why is such a basic, useful and generally applicable function like 'chunk not included in the core? Or 'random-element? Final comment: I think collection parameters should be named "coll", not "s", so that the docs are consistent with the core functions. Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
seq returns nil when a collection has no items. According to the documentation for empty?, empty? is the same as (not (seq coll)) so you should use seq for expressing the opposite of empty? On Tue, Jan 13, 2009 at 3:12 AM, GS wrote: > > On Jan 13, 2:59 pm, Chouser wrote: > > > > It raises a question, though -- how much functionality should a > > function provide to be worth making everyone who reads the code learn > > the new vocabulary? I've written each of these inline when I've > > needed them. Are they better as idioms or functions? > > I can't comment on which ones I would use: I'm too new to Clojure for > that. But I think a rich utility library is good, so long as it's > clear from a function's name and parameters what it does. There are > only a few in the collection above whose purpose I don't understand; > for most I see it easily. > > One question about the collection: > > > (defn chunk "Lazily break s into chunks of length n (or less, for the > > final chunk)." > > [n s] > > (when (seq s) > >(lazy-cons (take n s) > > (chunk n (drop n s) > > Should that "seq" be "seq?". If not, why not? > > The general question it raises for _me_ is this: why is such a basic, > useful and generally applicable function like 'chunk not included in > the core? Or 'random-element? > > Final comment: I think collection parameters should be named "coll", > not "s", so that the docs are consistent with the core functions. > > Gavin > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
Not sure what you want to achieve by studying the source code. I think the answer that I can give to what works best for you will depend on what you want to study the source code for. I'm also not sure what you mean by 'what is the best place to start reading..' The link that I gave before is a direct link to the source code of clojure. That is the source. http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/core.clj On Jan 13, 9:04 am, HB wrote: > Do you suggest that I read "Programming Clojure" first and then trying > to study the source code? > What is the best place (file, package or what ever) to start reading > the source code? > > On Jan 13, 10:01 am, bOR_ wrote: > > > > > Here you can peek at the source code of clojure. > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > It is about 3700 lines, and although you have to get used to a few new > > functions and names that are normally not exposed when you use > > clojure, it looks fairly simple. > > > Here is the function that defines defn itself. Most functions in the > > source are a magnitude easier than this one for us newbies =). > > > (def > > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > > name (fn ([params* ] exprs*)+)) with any doc-string or attrs added > > to the var metadata" > > :arglists '([name doc-string? attr-map? [params*] body] > > [name doc-string? attr-map? ([params*] body)+ attr- > > map?])} > > defn (fn defn [name & fdecl] > > (let [m (if (string? (first fdecl)) > > {:doc (first fdecl)} > > {}) > > fdecl (if (string? (first fdecl)) > > (rest fdecl) > > fdecl) > > m (if (map? (first fdecl)) > > (conj m (first fdecl)) > > m) > > fdecl (if (map? (first fdecl)) > > (rest fdecl) > > fdecl) > > fdecl (if (vector? (first fdecl)) > > (list fdecl) > > fdecl) > > m (if (map? (last fdecl)) > > (conj m (last fdecl)) > > m) > > fdecl (if (map? (last fdecl)) > > (butlast fdecl) > > fdecl) > > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > > (list 'def (with-meta name (conj (if (meta name) (meta name) > > {}) m)) > > (cons `fn fdecl) > > > On Jan 13, 8:51 am, HB wrote: > > > > Hey, > > > How much Clojure source code is complicated? > > > I'm not a programming Godfather but I would like to study Clojure > > > source code. > > > Could an intermediate programmer like me grasp the source code? > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: anyone experience with brics.automaton regex engine?
For posterity: got it working! Here is how (just ignore all the gene amino window size like words, they are specific for my code) (add-classpath "file:///linuxhome/tmp/boris/automaton.jar") (import '(brics.automaton.RegExp)) (import '(brics.automaton.Automaton)) (import '(brics.automaton.RunAutomaton)) (import '(brics.automaton.AutomatonMatcher)) (defn genes-to-single-regexp "makes the possible recombinations from the genes Ag pathway, and returns a single regexp (using brics automaton) to detect epitopes" [genes] (let [make-regexp (fn [gene] (.toAutomaton (dk.brics.automaton.RegExp. (reduce str (map #(str "[ " (reduce str %) "]") gene)] (dk.brics.automaton.RunAutomaton. (reduce (fn [rx1,rx2] (.union rx1 rx2)) (map (fn [n] (make- regexp n)) (set (map #(merge- genes %) (for [x (first genes) y (second genes) z (third genes)] (list x y z)) true))) (defn find-all-epi "turns the rx and string into a matcher. don't know if it is a good idea to keep matchers or not. Now just forgetting about them after I made them" [rx string] (let [matcher (.newMatcher rx string)] (count (take-while #(= true %) (repeatedly (fn [] (.find matcher))) On Dec 10 2008, 9:27 am, bOR_ wrote: > Hired a monkey to hit random keys on my keyboard, and eventually > figured out how to get the automaton working. > > RegExp r = new RegExp("ab(c|d)*"); > Automaton a = r.toAutomaton(); > String s = "abcccdc"; > System.out.println("Match: " + a.run(s)); // prints: true > > (add-classpath "file:///home/boris/projects/chapter4/automaton.jar") > (import '(brics.automaton.RegExp)) > (import '(brics.automaton.Automaton)) > (import '(brics.automaton.RunAutomaton)) ; didn't succeed yet in > figuring out how to call this one. > > (def r (.toAutomaton (dk.brics.automaton.RegExp. "[ab][c][abc][d]"))) > (def s "acbd") > (.run r s) > > Next part of the exploration is to figure out how to get it to find > substrings in a large string. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On 13.01.2009, at 05:35, Mark P wrote: > I know that there are other functional approaches where > the compiler automatically finds ways to parallelize. Is there > much scope for this in Clojure? Or is it all pretty much > manually added concurrency? I am not aware of any auto-parallelizing compiler that is actually useful in practice. All useable parallelization schemes rely at least on hints from the programmer, and most leave the whole specification of parallelism to the programmer. One might say that data-parallel systems are auto-parallelizing, but they aren't really: the programmer has to define the data that is being distributed, which counts for me as a parallelization hint. Clojure does nothing at all, it just provides an infrastructure for pure functional programming that makes concurrency and parallel computing easier to implement than most other languages. > And this leads to another question I have about Lisp-style > languages in general. I get the impression that in Lisp > much of the "compiler" is Lisp code itself. Ie, layer and > layer of macros build up towards the language that then > actually gets "used". Does this layer upon layer of macros > lead to inefficiencies in itself? Or is the opposite true? Macros are handled at compile time, so they add no run-time overhead. There remains the question of how good the compiler can optimize the expressions resulting from macro expansion. But the same question applies to any other compiler, as most of them first transform the input language into some simple intermediate language and then optimize at that level. The difference with Lisp is just that the simple intermediate language is a subset of the full language. > That seems to match what I've read. On average I get the > impression that it is about 2 times as slow as efficient C++ code > and uses maybe 10 times as much memory. I wouldn't trust any "average"! > What I'm wondering is whether there is still quite a bit of > "fat to be trimmed" with HotSpot, or whether it's approaching > the limits of what is achievable. JIT technology being young and in rapid development, it would be risky to do any prediction there. >> You could also consider writing Clojure code that generates C++ code. >> Or C, or why not directly LLVM. > > Thanks. Worth considering. Though I don't really know > whether this is a practical option or not. Maybe it is. There are efficient real-life libraries that use this approach. The best known is probably FFTW, which consists of optimized C code generated by functional OCaml code. I have no doubt that Clojure could take the role of OCaml there. Of course, writing such an optimizing library requires a significant effort. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
>Not sure what you want to achieve by studying the source code. I think >the answer that I can give to what works best for you will depend on >what you want to study the source code for. I want to be familiar with a language design in general and how it integrates with Java Platform. >I'm also not sure what you mean by 'what is the best place to start reading. What I mean is which file in the source code I have to read in order to start mining. This depends on why I'm reading the source code, right? On Jan 13, 10:19 am, bOR_ wrote: > Not sure what you want to achieve by studying the source code. I think > the answer that I can give to what works best for you will depend on > what you want to study the source code for. > > I'm also not sure what you mean by 'what is the best place to start > reading..' The link that I gave before is a direct link to the source > code of clojure. That is the source. > > http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > On Jan 13, 9:04 am, HB wrote: > > > Do you suggest that I read "Programming Clojure" first and then trying > > to study the source code? > > What is the best place (file, package or what ever) to start reading > > the source code? > > > On Jan 13, 10:01 am, bOR_ wrote: > > > > Here you can peek at the source code of clojure. > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > It is about 3700 lines, and although you have to get used to a few new > > > functions and names that are normally not exposed when you use > > > clojure, it looks fairly simple. > > > > Here is the function that defines defn itself. Most functions in the > > > source are a magnitude easier than this one for us newbies =). > > > > (def > > > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > > > name (fn ([params* ] exprs*)+)) with any doc-string or attrs added > > > to the var metadata" > > > :arglists '([name doc-string? attr-map? [params*] body] > > > [name doc-string? attr-map? ([params*] body)+ attr- > > > map?])} > > > defn (fn defn [name & fdecl] > > > (let [m (if (string? (first fdecl)) > > > {:doc (first fdecl)} > > > {}) > > > fdecl (if (string? (first fdecl)) > > > (rest fdecl) > > > fdecl) > > > m (if (map? (first fdecl)) > > > (conj m (first fdecl)) > > > m) > > > fdecl (if (map? (first fdecl)) > > > (rest fdecl) > > > fdecl) > > > fdecl (if (vector? (first fdecl)) > > > (list fdecl) > > > fdecl) > > > m (if (map? (last fdecl)) > > > (conj m (last fdecl)) > > > m) > > > fdecl (if (map? (last fdecl)) > > > (butlast fdecl) > > > fdecl) > > > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > > > (list 'def (with-meta name (conj (if (meta name) (meta name) > > > {}) m)) > > > (cons `fn fdecl) > > > > On Jan 13, 8:51 am, HB wrote: > > > > > Hey, > > > > How much Clojure source code is complicated? > > > > I'm not a programming Godfather but I would like to study Clojure > > > > source code. > > > > Could an intermediate programmer like me grasp the source code? > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
Thanks for the answer. I think you'll need a reply from Chouser or Rich (or someone alike) when they wake up. The best I can give you is this part of the source, where (I think) it is defined how clojure is build upon java. http://code.google.com/p/clojure/source/browse/trunk/src/?r=1205#src/jvm/clojure On Jan 13, 9:41 am, HB wrote: > >Not sure what you want to achieve by studying the source code. I think > >the answer that I can give to what works best for you will depend on > >what you want to study the source code for. > > I want to be familiar with a language design in general and how it > integrates with Java Platform. > > >I'm also not sure what you mean by 'what is the best place to start reading. > > What I mean is which file in the source code I have to read in order > to start mining. > This depends on why I'm reading the source code, right? > > On Jan 13, 10:19 am, bOR_ wrote: > > > > > Not sure what you want to achieve by studying the source code. I think > > the answer that I can give to what works best for you will depend on > > what you want to study the source code for. > > > I'm also not sure what you mean by 'what is the best place to start > > reading..' The link that I gave before is a direct link to the source > > code of clojure. That is the source. > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > On Jan 13, 9:04 am, HB wrote: > > > > Do you suggest that I read "Programming Clojure" first and then trying > > > to study the source code? > > > What is the best place (file, package or what ever) to start reading > > > the source code? > > > > On Jan 13, 10:01 am, bOR_ wrote: > > > > > Here you can peek at the source code of clojure. > > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > > It is about 3700 lines, and although you have to get used to a few new > > > > functions and names that are normally not exposed when you use > > > > clojure, it looks fairly simple. > > > > > Here is the function that defines defn itself. Most functions in the > > > > source are a magnitude easier than this one for us newbies =). > > > > > (def > > > > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > > > > name (fn ([params* ] exprs*)+)) with any doc-string or attrs added > > > > to the var metadata" > > > > :arglists '([name doc-string? attr-map? [params*] body] > > > > [name doc-string? attr-map? ([params*] body)+ attr- > > > > map?])} > > > > defn (fn defn [name & fdecl] > > > > (let [m (if (string? (first fdecl)) > > > > {:doc (first fdecl)} > > > > {}) > > > > fdecl (if (string? (first fdecl)) > > > > (rest fdecl) > > > > fdecl) > > > > m (if (map? (first fdecl)) > > > > (conj m (first fdecl)) > > > > m) > > > > fdecl (if (map? (first fdecl)) > > > > (rest fdecl) > > > > fdecl) > > > > fdecl (if (vector? (first fdecl)) > > > > (list fdecl) > > > > fdecl) > > > > m (if (map? (last fdecl)) > > > > (conj m (last fdecl)) > > > > m) > > > > fdecl (if (map? (last fdecl)) > > > > (butlast fdecl) > > > > fdecl) > > > > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > > > > (list 'def (with-meta name (conj (if (meta name) (meta name) > > > > {}) m)) > > > > (cons `fn fdecl) > > > > > On Jan 13, 8:51 am, HB wrote: > > > > > > Hey, > > > > > How much Clojure source code is complicated? > > > > > I'm not a programming Godfather but I would like to study Clojure > > > > > source code. > > > > > Could an intermediate programmer like me grasp the source code? > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Suggested functions for core: any? none?
Hi, I searched the archives and saw that this has been raised once before, although it wasn't really a suggestion, didn't raise any real discussion and didn't reach any conclusion. I just think it's worth proposing that a function set that includes every? and not-every? but does not include any? or none? feels like it's missing something. These are useful functions and, I humbly suggest, cause needless surprise in the average user when (s)he discovers they don't exist. Of course, they are easy to implement oneself, or to find in a library, but they are also easy to include in the core. Also worth considering is exactly? As in: (defn exactly? [n pred coll] ...) -> returns true iff exactly n elements of the collection satisfy the predicate The case is not as clear for that (I wouldn't have thought about it had I not seen it in a library), but it's worth considering. I realise that 'some can be used instead of 'any?, but: * as mentioned before, the average user would expect that any? exists * any? reads better in code when only a true/false value is required Regards, Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Learning Clojure WikiBook
I've added some info regarding the backquote expansion mechanism in the Reader section here: http://en.wikibooks.org/wiki/Learning_Clojure#The_Reader I tried to answer the author's question regarding the possible expansion order in nested backquotes and the general algorithm Clojure apparently employs, which seems to be very similar to the one "suggested" in the CL HyperSpec, though practically every CL implementation adopts its own and is free to do so. I hope I get his and, of course, Rich's blessing. Happy Clojure. Rock --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
For what's it worth, I think the "Programming Clojure" book is excellent (Okay Stuart, make the check payable to ). My only complaint is that the I wish there were another largish example besides the two in there (mc simulation and the lancelet thing). Cheers, Aria On Jan 13, 12:58 am, bOR_ wrote: > Thanks for the answer. I think you'll need a reply from Chouser or > Rich (or someone alike) when they wake up. The best I can give you is > this part of the source, where (I think) it is defined how clojure is > build upon java. > > http://code.google.com/p/clojure/source/browse/trunk/src/?r=1205#src/... > > On Jan 13, 9:41 am, HB wrote: > > > >Not sure what you want to achieve by studying the source code. I think > > >the answer that I can give to what works best for you will depend on > > >what you want to study the source code for. > > > I want to be familiar with a language design in general and how it > > integrates with Java Platform. > > > >I'm also not sure what you mean by 'what is the best place to start > > >reading. > > > What I mean is which file in the source code I have to read in order > > to start mining. > > This depends on why I'm reading the source code, right? > > > On Jan 13, 10:19 am, bOR_ wrote: > > > > Not sure what you want to achieve by studying the source code. I think > > > the answer that I can give to what works best for you will depend on > > > what you want to study the source code for. > > > > I'm also not sure what you mean by 'what is the best place to start > > > reading..' The link that I gave before is a direct link to the source > > > code of clojure. That is the source. > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > On Jan 13, 9:04 am, HB wrote: > > > > > Do you suggest that I read "Programming Clojure" first and then trying > > > > to study the source code? > > > > What is the best place (file, package or what ever) to start reading > > > > the source code? > > > > > On Jan 13, 10:01 am, bOR_ wrote: > > > > > > Here you can peek at the source code of clojure. > > > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > > > It is about 3700 lines, and although you have to get used to a few new > > > > > functions and names that are normally not exposed when you use > > > > > clojure, it looks fairly simple. > > > > > > Here is the function that defines defn itself. Most functions in the > > > > > source are a magnitude easier than this one for us newbies =). > > > > > > (def > > > > > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > > > > > name (fn ([params* ] exprs*)+)) with any doc-string or attrs added > > > > > to the var metadata" > > > > > :arglists '([name doc-string? attr-map? [params*] body] > > > > > [name doc-string? attr-map? ([params*] body)+ attr- > > > > > map?])} > > > > > defn (fn defn [name & fdecl] > > > > > (let [m (if (string? (first fdecl)) > > > > > {:doc (first fdecl)} > > > > > {}) > > > > > fdecl (if (string? (first fdecl)) > > > > > (rest fdecl) > > > > > fdecl) > > > > > m (if (map? (first fdecl)) > > > > > (conj m (first fdecl)) > > > > > m) > > > > > fdecl (if (map? (first fdecl)) > > > > > (rest fdecl) > > > > > fdecl) > > > > > fdecl (if (vector? (first fdecl)) > > > > > (list fdecl) > > > > > fdecl) > > > > > m (if (map? (last fdecl)) > > > > > (conj m (last fdecl)) > > > > > m) > > > > > fdecl (if (map? (last fdecl)) > > > > > (butlast fdecl) > > > > > fdecl) > > > > > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > > > > > (list 'def (with-meta name (conj (if (meta name) (meta name) > > > > > {}) m)) > > > > > (cons `fn fdecl) > > > > > > On Jan 13, 8:51 am, HB wrote: > > > > > > > Hey, > > > > > > How much Clojure source code is complicated? > > > > > > I'm not a programming Godfather but I would like to study Clojure > > > > > > source code. > > > > > > Could an intermediate programmer like me grasp the source code? > > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
And I would like to kindly ask from Mr. Stu to make the new book as extensive as possible (just like Programming Ruby book) and we will have a title like "The pickaxe book" :) On Jan 13, 12:38 pm, aria42 wrote: > For what's it worth, I think the "Programming Clojure" book is > excellent (Okay Stuart, make the check payable to ). My only > complaint is that the I wish there were another largish example > besides the two in there (mc simulation and the lancelet thing). > > Cheers, Aria > > On Jan 13, 12:58 am, bOR_ wrote: > > > Thanks for the answer. I think you'll need a reply from Chouser or > > Rich (or someone alike) when they wake up. The best I can give you is > > this part of the source, where (I think) it is defined how clojure is > > build upon java. > > >http://code.google.com/p/clojure/source/browse/trunk/src/?r=1205#src/... > > > On Jan 13, 9:41 am, HB wrote: > > > > >Not sure what you want to achieve by studying the source code. I think > > > >the answer that I can give to what works best for you will depend on > > > >what you want to study the source code for. > > > > I want to be familiar with a language design in general and how it > > > integrates with Java Platform. > > > > >I'm also not sure what you mean by 'what is the best place to start > > > >reading. > > > > What I mean is which file in the source code I have to read in order > > > to start mining. > > > This depends on why I'm reading the source code, right? > > > > On Jan 13, 10:19 am, bOR_ wrote: > > > > > Not sure what you want to achieve by studying the source code. I think > > > > the answer that I can give to what works best for you will depend on > > > > what you want to study the source code for. > > > > > I'm also not sure what you mean by 'what is the best place to start > > > > reading..' The link that I gave before is a direct link to the source > > > > code of clojure. That is the source. > > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > > On Jan 13, 9:04 am, HB wrote: > > > > > > Do you suggest that I read "Programming Clojure" first and then trying > > > > > to study the source code? > > > > > What is the best place (file, package or what ever) to start reading > > > > > the source code? > > > > > > On Jan 13, 10:01 am, bOR_ wrote: > > > > > > > Here you can peek at the source code of clojure. > > > > > > >http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/... > > > > > > > It is about 3700 lines, and although you have to get used to a few > > > > > > new > > > > > > functions and names that are normally not exposed when you use > > > > > > clojure, it looks fairly simple. > > > > > > > Here is the function that defines defn itself. Most functions in the > > > > > > source are a magnitude easier than this one for us newbies =). > > > > > > > (def > > > > > > > #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def > > > > > > name (fn ([params* ] exprs*)+)) with any doc-string or attrs > > > > > > added > > > > > > to the var metadata" > > > > > > :arglists '([name doc-string? attr-map? [params*] body] > > > > > > [name doc-string? attr-map? ([params*] body)+ attr- > > > > > > map?])} > > > > > > defn (fn defn [name & fdecl] > > > > > > (let [m (if (string? (first fdecl)) > > > > > > {:doc (first fdecl)} > > > > > > {}) > > > > > > fdecl (if (string? (first fdecl)) > > > > > > (rest fdecl) > > > > > > fdecl) > > > > > > m (if (map? (first fdecl)) > > > > > > (conj m (first fdecl)) > > > > > > m) > > > > > > fdecl (if (map? (first fdecl)) > > > > > > (rest fdecl) > > > > > > fdecl) > > > > > > fdecl (if (vector? (first fdecl)) > > > > > > (list fdecl) > > > > > > fdecl) > > > > > > m (if (map? (last fdecl)) > > > > > > (conj m (last fdecl)) > > > > > > m) > > > > > > fdecl (if (map? (last fdecl)) > > > > > > (butlast fdecl) > > > > > > fdecl) > > > > > > m (conj {:arglists (list 'quote (sigs fdecl))} m)] > > > > > > (list 'def (with-meta name (conj (if (meta name) (meta > > > > > > name) > > > > > > {}) m)) > > > > > > (cons `fn fdecl) > > > > > > > On Jan 13, 8:51 am, HB wrote: > > > > > > > > Hey, > > > > > > > How much Clojure source code is complicated? > > > > > > > I'm not a programming Godfather but I would like to study Clojure > > > > > > > source code. > > > > > > > Could an intermediate programmer like me grasp the source code? > > > > > > > Thanks. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" gro
Re: Ring: A Web application library for Clojure.
This looks really cool. I've actually been experimenting with exactly the same thing. One thing I thought about (but didn't implement), was using some kind of lazy hash map, for the request, so that it only calls the methods (like getServerPort) if you need them. I don't really know how hard or easy that would be though. cheers, Kees On Jan 13, 6:19 am, Paul Barry wrote: > To answer my own question: > [#^HttpServletRequest request] > {:server-port (.getServerPort request) > :server-name (.getServerName request) > :remote-addr (.getRemoteAddr request) > :uri (.getRequestURI request) > :query-string (.getQueryString request) > :scheme (keyword (.getScheme request)) > :request-method (keyword (.toLowerCase (.getMethod request))) > :headers (reduce > (fn [header-map #^String header-name] > (assoc header-map > (.toLowerCase header-name) > (.getHeader request header-name))) > {} > (enumeration-seq (.getHeaderNames request))) > :content-type (.getContentType request) > :content-length (let [len (.getContentLength request)] > (if (>= len 0) len)) > :character-encoding (.getCharacterEncoding request) > :body (.getInputStream request)}) > > Which by the way is awesome, because you function takes a map, which doesn't > have to be created from an HttpServletRequest object. For the purposes of > testing, you can just construct a map with the parts you want and pass that > to your function. Great Work! > > On Tue, Jan 13, 2009 at 1:13 AM, Paul Barry wrote: > > What's does the req object that is passed into the function have in it? > > > On Mon, Jan 12, 2009 at 11:45 PM, Mark McGranaghan > > wrote: > > >> Hi All, > > >> I'm happy to announce the alpha release of 'Ring', a library inspired > >> by Python's WSGI and Ruby's Rack for developing web applications in > >> Clojure. > > >> I've made it as easy as humanly possible for you to try it out: > > >> git clone git://github.com/mmcgrana/ring.git > >> cd ring > >> java -Djava.ext.dirs=jars clojure.main src/ring/examples/ > >> hello_world.clj > > >> And your up and running with your first Ring web app, which you can > >> see athttp://localhost:8080/in your browser. > > >> The basic idea of Ring is that web apps are just Clojure functions > >> that take a standardized request as a single argument and return and > >> standardized response. For example, the hello_world.clj script from > >> above is: > > >> (ns ring.examples.hello-world > >> (:require ring.jetty) > >> (:import java.util.Date java.text.SimpleDateFormat)) > > >> (def formatter (SimpleDateFormat. "HH:mm:ss")); > > >> (defn app > >> [req] > >> {:status 200 > >> :headers {"Content-Type" "text/html"} > >> :body (str "Hello World from Ring" > >> "The current time is " > >> (.format formatter (Date.)) ".")}) > > >> (ring.jetty/run {:port 8080} app) > > >> Its nice to be able to get to "Hello World" so quickly, but the real > >> power of Ring is that apps are just functions - hence we can combine, > >> wrap, curry, and generally manipulate them as first class values. > > >> For example, someone asked in #clojure today how they could make their > >> web app provide a cleaned backtrace as an HTML response when it raised > >> exceptions. To add such exception handling to our Hello World Ring app > >> we would just use the ring.backtrace middleware: > > >> (ring.jetty/run {:port 8080} app) > > >> becomes > > >> (ring.jetty/run {:port 8080} > >> (ring.backtrace/wrap > >> app)) > > >> Similarly, one might want to have changes to a web app's code be > >> reflected in real time in the development environment, so as to avoid > >> constantly having to reboot the webserver. The ring.reload middleware > >> accomplishes exactly that: > > >> (ring.jetty/run {:port 8080} > >> (ring.backtrace/wrap > >> (ring.reload/wrap '(ring.examples.hello-world) > >> app) > > >> These are some of the features that originally motivated me to develop > >> Ring, but the complete list of functionality available to Ring apps is > >> larger and continues to grow: > > >> * ring.jetty: Handler for the Jetty webserver. > >> * ring.file: Middleware that serves static files out of a public > >> directory. > >> * ring.file-info: Middleware that augments response headers with info > >> about File responses. > >> * ring.dump: Endpoint that dumps the Ring requests as HTML responses > >> for debugging. > >> * ring.show-exceptions: Middleware that catches exceptions and > >> displays readable backtraces for debugging. > >> * ring.reload: Middleware to automatically reload selected libs before > >> each requests, minimizing server restarts. > >> * ring.builder: Helpers for combining Ring endpoints and middle
Re: when performance matters
> I am not aware of any auto-parallelizing compiler that is actually > useful in practice. Good to know - thanks. > > And this leads to another question I have about Lisp-style > > languages in general. I get the impression that in Lisp > > much of the "compiler" is Lisp code itself. Ie, layer and > > layer of macros build up towards the language that then > > actually gets "used". Does this layer upon layer of macros > > lead to inefficiencies in itself? Or is the opposite true? > > Macros are handled at compile time, so they add no run-time overhead. But isn't "compile time" sometimes _at_ runtime? Ie, if a macro is dependent on runtime information, then isn't it passed to "the compiler" which is included as part of the runtime executable, turned into bytecode, and then executed itself. That's how I thought it worked anyway. In which case, compiler efficiency is of importance. > There are efficient real-life libraries that use this approach. The > best known is probably FFTW, which consists of optimized C code > generated by functional OCaml code. I have no doubt that Clojure > could take the role of OCaml there. Of course, writing such an > optimizing library requires a significant effort. Thanks for the example. It's good to know what is possible. Cheers, Mark P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 2009, at 12:30, Mark P wrote: >> Macros are handled at compile time, so they add no run-time overhead. > > But isn't "compile time" sometimes _at_ runtime? Ie, if > a macro is dependent on runtime information, then isn't > it passed to "the compiler" which is included as part of > the runtime executable, turned into bytecode, and then > executed itself. That's how I thought it worked anyway. A macro cannot depend on runtime information. A macro is a function that is called at compile time, its argument is an expression (as written by the programmer, or as returned by another macro), and its result is a modified expression. There is no way a macro could access runtime information. It is a program that works on program code, not on runtime data. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 5:49 pm, Zak Wilson wrote: > You're probably thinking of > this:http://www.flownet.com/gat/papers/lisp-java.pdf Thanks for the link. > There's also the (in)famous language benchmark > site:http://shootout.alioth.debian.org/ This is primarily what I was going on. I realize no benchmarking approach is going to be perfect, but this attempt doesn't seem too bad. Is there any reason to be particularly sceptical about results found here? Oh, and I realize my comments about SBCL lisp being 3 to 4 times slower than C++ only apply for the quad core machines. The single core machines have SBCL as 2.2 or 2.3 times slower than C++. Perhaps this is a truer representation of SBCL's "raw capabilities". But a 120% performance hit is still quite a whack. Cheers, Mark P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
> > > > There's also the (in)famous language benchmark > > site:http://shootout.alioth.debian.org/ > > This is primarily what I was going on. I realize no > benchmarking approach is going to be perfect, but > this attempt doesn't seem too bad. Is there any > reason to be particularly sceptical about results > found here? > The programs are written by volunteers, so the languages which have people that care about the results (and spend more time writing optimized code for their language of choice) get a big boost in score. Results are also affected by whether relevant libraries (often highly optimized for speed and memory) are included in the language's standard library, as third party libraries can't be used in shootout submissions. Also, for many shootout problems, the answer can be determined at compile-time, so you are potentially testing an aspect of compilation optimization that is not so relevant for practical programming problems. I don't know of a better set of benchmark results to look at - I use the shootout results myself - but I would take them with a grain of salt. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggested functions for core: any? none?
On Tue, Jan 13, 2009 at 3:03 AM, GS wrote: > > Hi, > > I searched the archives and saw that this has been raised once before, > although it wasn't really a suggestion, didn't raise any real > discussion and didn't reach any conclusion. > > I just think it's worth proposing that a function set that includes > every? and not-every? but does not include any? That one is called "some". The name doesn't end with "?" because it doesn't return true or false. It returns the first value that is logically true. > or none? Hmm ... I'm not sure if an equivalent for that exists. > feels like > it's missing something. These are useful functions and, I humbly > suggest, cause needless surprise in the average user when (s)he > discovers they don't exist. > > Of course, they are easy to implement oneself, or to find in a > library, but they are also easy to include in the core. > > Also worth considering is exactly? As in: > (defn exactly? [n pred coll] ...) >-> returns true iff exactly n elements of the collection satisfy > the predicate > > The case is not as clear for that (I wouldn't have thought about it > had I not seen it in a library), but it's worth considering. > > I realise that 'some can be used instead of 'any?, but: > * as mentioned before, the average user would expect that any? exists > * any? reads better in code when only a true/false value is required -- R. Mark Volkmann Object Computing, Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
> A macro cannot depend on runtime information. A macro is a function > that is called at compile time, its argument is an expression (as > written by the programmer, or as returned by another macro), and its > result is a modified expression. There is no way a macro could access > runtime information. It is a program that works on program code, not > on runtime data. Then what do people mean when they say that lisp blurs the distinction between compile-time and run-time? I thought that "macros executing at runtime" was part of this. But if not, I don't know what they do mean. I thought macros could get executed at runtime as follows. Suppose I have a domain-specific-language implemented in a lisp, using macros. Suppose at runtime some of this domain-specific-code gets generated somehow (code is data at this point). An "eval" is executed on this domain-specific-code, which causes the macros (used to implement the domain-specific-language) to transform the input code at runtime. Is this wrong? I also thought that when a "clojure application" is bundled up as java bytecode, this "executable" actually includes the clojure compiler. Why would this be included if compilation (including macros) is never performed at runtime? Is there something fundamental I am not understanding? Thanks, Mark P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
On Tue, Jan 13, 2009 at 3:12 AM, GS wrote: > > Should that "seq" be "seq?". If not, why not? Nick nailed that one. > The general question it raises for _me_ is this: why is such a basic, > useful and generally applicable function like 'chunk not included in > the core? Or 'random-element? 'chunk' is very similar to the built-in 'partition', the difference being how the last group is handled. user=> (partition 2 '[a b c d e]) ((a b) (c d)) --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 2009, at 14:04, Mark P wrote: > Then what do people mean when they say that lisp blurs > the distinction between compile-time and run-time? I don't know. I can only guess that they may be referring to the fact that many Lisp dialects have both an interpreter and a compiler. Or to the fact that macros (executed at compile time) can call functions that are also available at runtime. Or to the fact that in interactive sessions in a purely compiled Lisp (such as Clojure), every expression gets compiled on the fly just before being executed. Or again to the fact that you have the function eval, which calls the compiler at runtime. Anyway, in Clojure there is a clear distinction between compiling an expression, i.e. producing equivalent JVM bytecodes, and executing it, i.e. running the JVM bytecode. > I thought macros could get executed at runtime as > follows. Suppose I have a domain-specific-language > implemented in a lisp, using macros. Suppose at > runtime some of this domain-specific-code gets > generated somehow (code is data at this point). > An "eval" is executed on this domain-specific-code, > which causes the macros (used to implement the > domain-specific-language) to transform the input > code at runtime. > > Is this wrong? You can do that but it is rarely done. DSLs are typically implemented as ordinary functions and macros without calling eval. Eval is there for very specific needs, such as implementing interactive interpreters. And even in those specific applications, I wouldn't expect the CPU time requirements of eval to be important. > I also thought that when a "clojure application" is > bundled up as java bytecode, this "executable" > actually includes the clojure compiler. Why would > this be included if compilation (including macros) > is never performed at runtime? As long as you want to be able to call eval, you need the compiler to be around. I guess most Clojure applications could be bundled up without including the compiler, but perhaps this is too much effort to be worth pursuing. Konrad. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Can't lookup java.lang.Long keys in a map using int literal
On Jan 13, 1:26 am, Allen Rohner wrote: > Keys in a map that are of type long can't be looked up in a map using > int literal syntax: > > user=> (def my_map { (java.lang.Long. "42") "foo"}) > #'user/my_map > > user=> my_map > {42 "foo"} > > user=> (my_map 42) > nil > > user=> (my_map (long 42)) > "foo" > > user=> (= 42 (java.lang.Long. "42")) > true > > I found this behavior incredibly confusing, especially given the fact > that ints and longs print the same. > > I believe this is a bug. Rich, do you agree? > No. Hashmaps use hashCode and equals (i.e. not =), which are defined by Java for Integer and Long: user=> (.equals (java.lang.Integer. "42") (java.lang.Long. "42") ) false Literals are going to have the smallest (bounded by Integer) representative type. In general, you should use uniform types for hash keys. Rich --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Example Java oriented SWT GUI application in Clojure
On Jan 12, 9:58 pm, e wrote: > thanks. I think this will be useful, but I have to figure out how to get it > to build in enclojure. Right now I get, "Exception in thread "main" > java.util.MissingResourceException: Can't find bundle for base name > octane_main, locale en_US (octane_main.clj:136)" > > On Mon, Jan 12, 2009 at 5:24 PM, BerlinBrown wrote: > > > Here is an example SWT application. It is a 'search' tool. Open a > > file and the search term is highlighted. It has a java oriented > > approach because I copied the java code verbatim. This might be > > useful if you are still used to imperative programming. > > > Main source: > > >http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search/src/oc... > > > Additional Files (all you really need is what is in the lib directory) > >http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search > > > But, I am all ears for suggestions (I am sure there are very, very > > many) and if you want, send me a patch file, I will be glad to update > > it. > > > Might help for newbies like me. Yea, if you see the parent folder, get the octane_main property file. It is needed by the app. http://jvmnotebook.googlecode.com/svn/trunk/clojure/swt/search --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
By Example - another Clojure introduction wiki page
I've written small wiki article which dives right into the look and meaning of common Clojure constructs with examples. Personally I find I learn best by examples and when starting out they were hard to find, whereas formal descriptions were there but rather cryptic when you don't understand the context. My intention is to provide an initial understanding of how programs look, what they mean, and what can be accomplished because of their features... from which someone would then move to one of the more complete articles and references. http://en.wikibooks.org/wiki/Clojure_Programming/By_Example I hope someone finds it useful :) Regards, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggested functions for core: any? none?
On Tue, Jan 13, 2009 at 7:46 AM, Mark Volkmann wrote: > > On Tue, Jan 13, 2009 at 3:03 AM, GS wrote: > >> or none? > > Hmm ... I'm not sure if an equivalent for that exists. user=> (doc not-any?) - clojure.core/not-any? ([pred coll]) Returns false if (pred x) is logical true for any x in coll, else true. nil --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure now running in production
On Jan 13, 7:38 am, Luc Prefontaine wrote: > as of yesterday pm, Clojure is running in a live system in a big > veterinarian hospital. Awesome, congratulations!!! :-D mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Can't lookup java.lang.Long keys in a map using int literal
I still find this confusing, but thanks for the quick response. > In general, you should use uniform types for hash keys. I thought I was using all ints, but it turns out that a java API returned a long when I thought it returned an int. So then my map had some keys that were ints and some that were long, and some lookups failed, based on whether the keys were in the code path that returned ints vs. the code path that returned longs. What if ints and longs had different literal syntax, i.e. 42 vs. 42L? In my example above, if you take that map, write it to a string and then read it back, the behavior would be different. In the original, the key is a long, and in the reconstituted version, it would be an int, right? Allen --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Simple Data Structure Question
Hi, After (are-friends bill bob) they should be friends, so I tried @bob and don't see bill as a friend. why? @bob {:friends #{#}, :name "Bob"} -sun On Jan 10, 9:44 pm, Stuart Sierra wrote: > Hi Patrick, > > Here's one way to do it: > > (defn new-person [name] > (ref {:name name, :friends #{}})) > > (defn are-friends [a b] > (dosync > (commute a assoc :friends (conj (:friends @a) b)) > (commute b assoc :friends (conj (:friends @b) a > > (def bill (new-person "Bill")) > (def bob (new-person "Bob")) > > (are-friends bill bob) > > -Stuart Sierrra > > On Jan 10, 8:39 pm, CuppoJava wrote: > > > Hello, > > I'm stumped as to how I create a mutually referential data structure > > in Clojure. My compsci is fuzzy. I don't know if what I'm trying to do > > is possible. Any insight would be helpful. > > > I have a function that creates a Person, given his name and a list of > > friends. > > > (defn new_person [name & friends] > > {:name name > > :friends friends}) > > > But how do I create a mutually referential definition? > > > ie. what if Bob is Bill's friend, and Bill is also Bob's friend? > > I would have to do something like the following: (which is not > > allowed) > > > (def bob (new_person "Bob" bill)) <-Not allowed: forward reference. > > (def bill (new_person "Bill" bob)) > > > Thanks a lot for your help > > -Patrick --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from 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 now running in production
2009/1/13 Luc Prefontaine > Hi everyone, > > as of yesterday pm, Clojure is running in a live system in a big > veterinarian hospital. > > Congratulations, its always a real buzz to get something out and running in the wild, building it on something really new like Clojure must make it even better. Good luck going forward. ... > Many of the key features of the system rely on Clojure so we would like to > give credit to Clojure and Rich. > I hope you are sponsoring him ;-) Cheers Tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 11, 9:41 pm, Mark P wrote: > The programs I write perform applied mathematical > optimization (using mainly integer arithmetic) > and often take hours (occasionally even days) > to run. So even small percentage improvements > in execution speed can make a significant > practical difference. And large problems can use > a large amount of memory - so memory efficiency > is also a concern. Would you happen to know exactly what the bottlenecks in your applications are? Is performance bound by integer arithmetic, by memory bandwidth (due to lack of temporal locality), or by memory latency (due to lack of spatial locality)? It's important to know because garbage collection influences performance differently depending on the performance bottlenecks in your application. For example, if you're creating a lot of small objects in your C++ code anyway, you're still calling destructors a lot and so replacing C++ with a garbage-collected language may even _improve_ performance. (I recall this being the case with a particular C++ vs. OCaml benchmark, as the OCaml GC implementation used had soft real-time guarantees whereas the C++ destructor chain called at the ends of key functions would cause significant latencies.) > There are three key factors that still give me > hope: > > 1. Some of the algorithms I use have the potential > to be parallelized. I am hoping that as the number > of cores in PCs increase, at some point Clojure's > performance will beat C++'s due to Clojure's > superior utilization of multiple cores. (Any ideas > on how many cores are needed for this to become > true?) You could use OpenMP to parallelize your C++ code without much effort, and it will be backwards portable to single-core machines. Getting performance to scale nicely takes a little more effort with OpenMP. Clojure needs to build up more infrastructure before parallel programming for performance becomes practical (how's that for a tongue twister! ;-P ), but building that infrastructure yourself can be fun and educational. I would do it myself if I had the time. (I have a fair amount of experience in parallel programming and consider myself qualified at least to evaluate a parallel programming framework design.) > 2. The JVM is continually being improved. Hopefully > in a year or two, the performance of HotSpot will be > closer to that of C++. (But maybe this is just > wishful thinking.) Again, this depends on the bottlenecks in your app. Remember also that C++ might be / is (I'm not sure -- you'll have to check this) _managed_ code (i.e., running under the .NET runtime) in Windows. Many developers seem to be willing to endure a small-percentage performance hit in order to make debugging and deployment easier. I've heard senior Windows engineers say that _every_ Windows app should run with a tracer so that on a crash they can get a trace of the last 30 seconds of the program. > If all else fails, maybe I could use Clojure as a prototyping > language. Then when I get it right, I code up the actual > programs in C++. But probably a lot would get lost in > the translation from Clojure -> C++ so would it be worth > it? The alternative mentioned in the discussion above was to use Clojure as a coordination (a.k.a. "scripting") language for Java or C(++). Combining high-level and low-level languages works great as long as you set up the interface right (e.g., making it clear where immutability is violated and avoiding errors that result from certain Clojure operations assuming immutability). We use Lua as a coordination language for our C library OSKI (bebop.cs.berkeley.edu/ oski) and it works just fine; it expresses an algebra of sparse matrix transformations. I prefer Lispy languages but that's just my taste ;-) > I'd love to be convinced that Clojure is a viable choice, > but I need to be a realist too. So what do people think? > How realistic are my three "hopes"? And are there > any other performance enhancing possibilities that I > have not taken into account? I've found that concerns about performance aren't productive unless they are backed up both by performance models (i.e., expectations of performance characteristics) and measurements. Also, you'll want to consider your own productivity as a programmer: on the one hand, rewriting everything in Clojure or any other language will take a lot of time, and on the other, maintaining an application written in a low- level language like C++ also will take a lot of time. The combination of high-level coordination language and low-level performance language is perhaps the best both for productivity and for performance: Productivity: * You can add the high-level coordination functions separately and incrementally, instead of rewriting the whole application from scratch. * It's much easier and faster to add new higher-level functionality. * Using two languages forces you to make a clean divide between high- level interface and low-level implementation, whic
Programming Clojure Beta 5 is Out
http://blog.thinkrelevance.com/2009/1/13/programming-clojure-beta-5-is-out Cheers, 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 To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Delays and their efficiency
Recently, I asked how to make a function evaluate its arguments lazily (http://groups.google.com/group/clojure/browse_thread/thread/ cd01ef39c2b62530), and I was given a good solution: use Delay objects (with the delay and force functions). I wanted to do this for the efficiency of a functional parser library that uses many meta-functions and meta-meta-functions: I thought that stopping arguments from being evaluated until needed was a good way to prevent useless creation of objects, especially in huge trees of meta- meta-functions. But I was very surprised when running my library's unit tests to see that using Delay objects took much more time to run the tests than not using Delays. Here's an example in a REPL: Clojure user=> (defn alt [& functions] (fn [tokens] (some #(% tokens) functions))) #'user/alt user=> (defn sub-function1 [c] (println "1:" c) (fn [c] false)) #'user/sub-function1 user=> (defn sub-function2 [c] (println "2:" c) (fn [c] true)) #'user/sub-function2 user=> (defn sub-function3 [c] (println "3:" c) (fn [c] false)) #'user/sub-function3 user=> (defn a-meta-meta-function [c] (alt (sub-function1 c) (sub-function2 c) (sub-function3 c))) #'user/a-meta-meta-function user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c])) 1: CONTEXT 2: CONTEXT 3: CONTEXT "Elapsed time: 1.018 msecs" true ...vs... Clojure user=> (defn alt [& functions] (fn [tokens] (some #((force %) tokens) functions))) #'user/alt user=> (defn sub-function1 [c] (println "1:" c) (delay (fn [c] false #'user/sub-function1 user=> java.lang.Exception: Unmatched delimiter: ) user=> (defn sub-function1 [c] (println "1:" c) (delay (fn [c] false))) #'user/sub-function1 user=> (defn sub-function2 [c] (println "2:" c) (delay (fn [c] true))) #'user/sub-function2 user=> (defn sub-function3 [c] (println "3:" c) (delay (fn [c] false))) #'user/sub-function3 user=> (defn a-meta-meta-function [c] (alt (sub-function1 c) (sub-function2 c) (sub-function3 c))) #'user/a-meta-meta-function user=> (time ((a-meta-meta-function foo) some-tokens)) java.lang.Exception: Unable to resolve symbol: foo in this context (NO_SOURCE_FILE:13) user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c])) 1: CONTEXT 2: CONTEXT 3: CONTEXT "Elapsed time: 2.443 msecs" true Why would it take so much more time? Is it because it might take a long time to construct a Delay object? Can I do something different to make it more efficient, or should I just not use Delay objects? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
Some comments: 1- If you think that HotSpot/Java is slower than C++ by any interesting amount, I'd love to see the test case. Being the architect of HotSpot "-server" I've a keen interest in where performance isn't on par with C. Except for a handful of specialized uses (e.g. high-level interpreters using gnu label vars), I've only ever seen equivalent code between C/C++ & Java (not so w/asm+C where the asm calls out specialized ops or makes specialized optimizations). 2- As already mentioned, there's no auto-parallelization tools Out There that are ready for prime-time. (there ARE tools out there that can *help* parallelize an algorithm but you need annotations, etc to make them work) 3- Making your algorithm parallel is worth an N-times speedup, where N is limited by the algorithm & available CPUs. Since you can get huge CPU counts these days, if you can parallelize your algorithm you'll surely win over almost any other hacking. If you take a 50% slowdown in the hacking but get to run well on a 4-way box, then your 2x ahead. I'd love to say that the JVM "will just do it", but hand- hacking for parallelism is the current state-of-the-art. 4- Java/Clojure makes some of this much easier than in C/C++. Having a memory model is a HUGE help in writing parallel code, as is the Java concurrency libs, or the above-mentioned Colt libraries. 5- The debian shootout results generally badly mis-represent Java. Most of them have runtimes that are too small (<10sec) to show off the JIT, and generally don't use any of the features which commonly appear in large Java programs (heavy use of virtuals, deep class hierarchies, etc) for which the JIT does a lot of optimization. I give a public talk on the dangers of microbenchmarks and all the harnesses I've looked at in the shootout fail basic sanity checks. Example: the fannkuch benchmark runs 5 secs in Java, somewhat faster in C++. Why does anybody care about a program which runs 5sec? (there's other worse problems: e.g. the C++ code gets explicit constant array sizes hand-optimized via templates; the equivalent Java optimization isn't done but is trivial (declare 'n' as a *final* static var) and doing so greatly speeds up Java, etc). 6- If you need a zillion integer (not FP) parallel Java cycles, look at an Azul box. Azul's got more integer cycles in a flat shared- memory config than anybody else by a long shot. Cliff --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
On Tue, Jan 13, 2009 at 3:04 AM, HB wrote: > > Do you suggest that I read "Programming Clojure" first and then trying > to study the source code? That's a fine option. The book may be a shorter path to *practical* knowledge. > What is the best place (file, package or what ever) to start reading > the source code? As bOR_ suggested, core.clj is a great place to start: http://code.google.com/p/clojure/source/browse/trunk/src/clj/clojure/core.clj Or an unofficial mirror with syntax highlighting: http://github.com/kevinoneill/clojure/blob/310155ffd520987278262ca641ece6149a77555f/src/clj/clojure/core.clj At one time, reading that was the best way to learn clojure. There are now many more tutorials, examples, and of course Holloway's book, but especially if you *want* to read code, that's a good place to start. While a lot of Clojure's features are implemented there, a good many are also implemented in java. You'll find in reading core.clj that it frequently calls static methods of RT.java. It also calls into the various collection (hash, vector, set, etc.) and reference (agent, ref, atom, var) classes, which are largely independent of each other. All this makes core.clj a good place to start, as it can lead you to the others as you go along. It may not, however, lead you to LispReader.java or Compiler.java. The former is for consuming a Java IO Reader and producing Clojure objects to be macroexpanded and compiled, so read that if you want to learn how Clojure parses text. The latter gleans deeper knowledge about the structure of Clojure expressions and produces Java bytecode -- not for the faint of heart. One thing to keep in mind when reading core.clj is that some Clojure idioms are impossible at the beginning of the file, as the tools they need haven't been created yet. So don't take all of it as necessarily the best way to write your own Clojure code. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: non recursive impl in presence of persistence?
sure . . . I'm just impressed with how many things "just work", and this could be one more. Not enough args, but you know what I wanted it to mean. There's no ambiguity. On Tue, Jan 13, 2009 at 2:07 AM, Timothy Pratley wrote: > > > > On Jan 13, 5:57 pm, e wrote: > > Instead of that being an error, why not overload the vector function so > that > > no args calls the version that returns the list. That seems like a good > > idea! I wonder if people will object. > > Actually in your case that would not work, because l2 can also be nil. > (nil) is a function call to nil, and you can't call nil either. > Ok so if nil were to implement a function that returned nil you would > be home free... > But really, isn't that just more confusing than the problem you are > trying to solve? > what's so bad about writing l2 instead of (l2)? > Anything in parenthesis is a function call. > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: How much Clojure source code is complicated?
Hi Aria, Today's drop of the book has two new "mediumish" examples: * a Compojure web app for that uses clojure.contrib.sql for its backing store * the Clojure snake we have been beating to death on the list Let me know you think this is a decent stable of examples. I'm still contemplating about a longer separate example in the concurrency chapter too. Cheers, Stuart > For what's it worth, I think the "Programming Clojure" book is > excellent (Okay Stuart, make the check payable to ). My only > complaint is that the I wish there were another largish example > besides the two in there (mc simulation and the lancelet thing). > > Cheers, Aria > > On Jan 13, 12:58 am, bOR_ wrote: >> Thanks for the answer. I think you'll need a reply from Chouser or >> Rich (or someone alike) when they wake up. The best I can give you is >> this part of the source, where (I think) it is defined how clojure is >> build upon java. >> >> http://code.google.com/p/clojure/source/browse/trunk/src/? >> r=1205#src/... >> >> --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure now running in production
As this is a commercial project, I imagine you are quite limited in what you can tell us, but I'd love to hear about the issues you faced during development. On Jan 13, 10:38 am, Luc Prefontaine wrote: > Hi everyone, > > as of yesterday pm, Clojure is running in a live system in a big > veterinarian hospital. > > We designed an HL7 message bus to link several services within the > hospital. > Presently we link the medical record system with the radiology > department. > The main benefit is to avoid re-keying information about patient and > requests in every system. > > We also provide some key applications on the bus to allow people to > share information in a consistent > way along the system they use on a daily basis. It's like a Babel tower, > radiologists want to work > with their radiology system while the administration wants to work with > the medical record system to > bill, ... each of these systems meet specific needs of a user base. > However there is a need for a common ground to share information. That's > what our product offers. > > This year the bus will expand to encompass prescription requests with > the pharmacy, the lab exams > and a couple of other systems. We have also another prospect so we may > end up with more than one site > by the end of 2009. > > The bus is designed to be a product, not a set of integration tools to > be assembled differently > at each customer site. It is highly configurable, all message based and > runs on distributed hardware. > > Clojure drives the top level logic of the bus (routing decisions, error > handling, archiving, ...). > > After digging for some parallel processing language better than Java, > Clojure emerged as a logical choice. > The design of this system is distributed with fault tolerance in every > software function but we needed to have > some options about the low-level components. Having access to all Java > libraries out there was a major factor > in our decision to use Clojure. > > Presently it runs on six small boxes like this one: > > http://www.fic.com.tw/product/ficimages/minipc.jpg > > with an internal redundant network. Each function is running in > master/slave mode with automatic fail over. > The throughput of the system is at least two thousands transactions an > hour. You can unplug cables, boxes, ... > and it still runs. It can sustain more than one fault before it fails. > > In the following year using Clojure and Terracotta we expect to bring > the degree of parallelism up to a point were we will > be able to run concurrently all the functions on multiple boxes and get > rid of the master/slave mode. > Distributed clusters are also in the pipe to allow to route between > different sites while keeping local site traffic and different local > applications. > > Expect a web site about this product in the next 2/3 months. We will > give Clojure visibility on this site. > Many of the key features of the system rely on Clojure so we would like > to give credit to Clojure and Rich. > Maybe this will be an incentive for people to look at Clojure as a > viable alternative to other functional > languages. > > Rich, thank you and congratulation, your baby has grown up well in the > last year and it will soon be asking for the car keys : > > Luc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Designing a Performance Vector Math library in Clojure.
On Tue, Jan 13, 2009 at 2:18 AM, Timothy Pratley wrote: > > BTW Rich, > > The documentation http://clojure.org/data_structures hints that > accessors are faster than regular map lookups and provides the > following example: > (reduce (fn [n y] (+ n (:fred y))) 0 x) > -> 45 > (reduce (fn [n y] (+ n (fred y))) 0 x) > -> 45 > > However I think it would be clearer if you explicitly showed the speed > improvement: > user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) > "Elapsed time: 100.838989 msecs" > 45 > user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) > "Elapsed time: 48.82307 msecs" > 45 With repeated runs, and my cpu frequency set to not change, I get very little speed improvement. I increased the size of the example range times 10 for these runs: user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 112.961087 msecs" 4950 user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) "Elapsed time: 102.127459 msecs" 4950 --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Designing a Performance Vector Math library in Clojure.
On Tue, Jan 13, 2009 at 2:23 PM, CuppoJava wrote: > > Do struct-maps also have boxing and unboxing overhead? Or does the JVM > optimize that away? Clojure collections currently store Objects, so they'll be boxed. To store primitive values I think you'll have to use a Java array (but only if all the primitives are the same type, of course) or create a new Java class (gen-interface+proxy, gen-class, or .java). If the Java array is an option for you, you can build up an API of functions to keep things named and immutable. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Creating a macro that just calls a function but evaluates its arguments lazily
Hi sampii, The problem, as I see it (& as Konrad suggested above), is that you're not passing *functions* to (alt); you're passing values returned from function calls, even though in the case of the sub-functions you define those returned values are functions. Functions evaluate to themselves, so if you can write your code to pass functions to (alt), e.g. (alt #(sub-function1 c) #(sub-function2 c) #(sub-fuction3 c)) you should be golden. Just to show it can be done, if you make the args to alt be (defn mmf [c] (alt #(sub-one c) #(sub-two c) #(sub-three c))) (note the #() reader macro)), & if you modify the definition of alt to be (defn alt [& funcs] (fn [tokens] (some #((%) tokens) funcs))) (note the extra set of parens around % -- so that the #(sub-one c) funcs get called, then their return values likewise get called), you get user=> ((mmf "context") [:a :b :c]) 1 context 2 context true Of course it would be more straightforward to drop the intermediate step of the anonymous functions -- #(sub-one c) -- which return yet another function -- (fn [c] true) -- say, by passing the equivalent of (fn [c] true) directly to alt, but I don't know your actual use case. My recommendation -- to passing function -- is simple enough that I feel like I might be missing something important from your question, but in case I'm not I didn't want you to think your only recourse was the full machinery of delay/force. Transcript follows. Best, Perry user=> (defn alt [& funcs] (fn [tokens] (some #((%) tokens) funcs))) #'user/alt user=> (defn sub-one [c] (println 1 c) (fn [x] false)) #'user/sub-one user=> (defn sub-two [c] (println 2 c) (fn [x] true)) #'user/sub-two user=> (defn sub-three [c] (println 3 c) (fn [x] false)) #'user/sub-three user=> (defn mmf [c] (alt #(sub-one c) #(sub-two c) #(sub-three c))) #'user/mmf user=> ((mmf "context") [:a :b :c]) 1 context 2 context true --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Ring: A Web application library for Clojure.
Hi Kees-Jochem, Am 13.01.2009 um 12:41 schrieb Kees-Jochem Wehrmeijer: This looks really cool. I've actually been experimenting with exactly the same thing. One thing I thought about (but didn't implement), was using some kind of lazy hash map, for the request, so that it only calls the methods (like getServerPort) if you need them. I don't really know how hard or easy that would be though. I implemented the lazy-map package, which provides lazy versions of all the map types of clojure: hash-map, sorted-map and struct-map. Complete with lazy map entries and lazy-assoc. A value is only evaluated when really accessed. In case you are interested, here's the link: http://kotka.de/projects/clojure/lazy-map.html Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature
Re: Designing a Performance Vector Math library in Clojure.
Do struct-maps also have boxing and unboxing overhead? Or does the JVM optimize that away? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
Why is Clojure slower than Java? And, can it be fixed? Is it just the dynamic lookups? I also want to use Clojure in my work to implement the inner loops, but I was disappointed by a previous discussion looking at the speed of Clojure. As I recall Clojure seems to be about 1/4 the speed of Java at the moment. Until we regularly have 10's of processors, it seems hard to justify that kind of hit for code that has to be fast. So, I use Clojure for scripting and high level code currently. Peter P.S. I also find that C++ and Java are now approximately the same speed. And if exceptions are enabled, Java blows C++ out of the water. cliffc wrote: > Some comments: > > 1- If you think that HotSpot/Java is slower than C++ by any > interesting amount, I'd love to see the test case. Being the > architect of HotSpot "-server" I've a keen interest in where > performance isn't on par with C. Except for a handful of specialized > uses (e.g. high-level interpreters using gnu label vars), I've only > ever seen equivalent code between C/C++ & Java (not so w/asm+C where > the asm calls out specialized ops or makes specialized optimizations). > > 2- As already mentioned, there's no auto-parallelization tools Out > There that are ready for prime-time. (there ARE tools out there that > can *help* parallelize an algorithm but you need annotations, etc to > make them work) > > 3- Making your algorithm parallel is worth an N-times speedup, where N > is limited by the algorithm & available CPUs. Since you can get huge > CPU counts these days, if you can parallelize your algorithm you'll > surely win over almost any other hacking. If you take a 50% slowdown > in the hacking but get to run well on a 4-way box, then your 2x > ahead. I'd love to say that the JVM "will just do it", but hand- > hacking for parallelism is the current state-of-the-art. > > 4- Java/Clojure makes some of this much easier than in C/C++. Having > a memory model is a HUGE help in writing parallel code, as is the Java > concurrency libs, or the above-mentioned Colt libraries. > > 5- The debian shootout results generally badly mis-represent Java. > Most of them have runtimes that are too small (<10sec) to show off the > JIT, and generally don't use any of the features which commonly appear > in large Java programs (heavy use of virtuals, deep class hierarchies, > etc) for which the JIT does a lot of optimization. I give a public > talk on the dangers of microbenchmarks and all the harnesses I've > looked at in the shootout fail basic sanity checks. Example: the > fannkuch benchmark runs 5 secs in Java, somewhat faster in C++. Why > does anybody care about a program which runs 5sec? (there's other > worse problems: e.g. the C++ code gets explicit constant array sizes > hand-optimized via templates; the equivalent Java optimization isn't > done but is trivial (declare 'n' as a *final* static var) and doing so > greatly speeds up Java, etc). > > 6- If you need a zillion integer (not FP) parallel Java cycles, look > at an Azul box. Azul's got more integer cycles in a flat shared- > memory config than anybody else by a long shot. > > Cliff > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 10:07 am, cliffc wrote: > Some comments: > > 1- If you think that HotSpot/Java is slower than C++ by any > interesting amount, I'd love to see the test case. Being the > architect of HotSpot "-server" I've a keen interest in where > performance isn't on par with C. -snip- > 5- The debianshootoutresults generally badly mis-represent Java. > Most of them have runtimes that are too small (<10sec) to show off the > JIT, When you say most of the runtimes are <10sec I wonder what exactly you are looking at - on u32 & u64, 6 of 13 are <10sec (on quadcore u32q & u64q, 8 of 13 are <10sec). I'm always puzzled when I read something like " have runtimes that are too small (<10sec)" because in my innocence it seems as though JIT gets to do a lot more in 10 sec on Q6600 than it did on Pentium 4 - am I just wrong about that? The benchmarks game has never aimed "to show off the JIT" anymore than it's aimed "to show off C++" but - http://shootout.alioth.debian.org/gp4/miscfile.php?file=dynamic&title=Java%20Dynamic%20Compilation > and generally don't use any of the features which commonly appear > in large Java programs (heavy use of virtuals, deep class hierarchies, > etc) for which the JIT does a lot of optimization. I think that has to be right although it seems like similar issues would apply to all the other programming languages, not just Java. "your application is the ultimate benchmark" http://shootout.alioth.debian.org/u32/miscfile.php?file=benchmarking&title=Flawed%20Benchmarks#app > I give a public talk on the dangers of microbenchmarks and all the > harnesses I've looked at in theshootoutfail basic sanity checks. > Example: the fannkuch benchmark runs 5 secs in Java, somewhat faster > in C++. Why does anybody care about a program which runs 5sec? Why does anybody care that a program runs 4sec rather than 6sec? (otoh those programs which run 10 minutes...) Of course you could choose other examples from the benchmarks game which show a Java program only a few tenths of a second from the fastest C++ program. (The reaction I frequently see is surprise that Java can be that close to C++). > (there's other worse problems: e.g. the C++ code gets explicit constant > array sizes hand-optimized via templates; the equivalent Java > optimization isn't done but is trivial (declare 'n' as a *final* static var) > and doing so greatly speeds up Java, etc). Which is to say that some of the programs are better than some of the other programs - isn't that always going to be the case? It's not obvious which Java fannkuch program you're talking about - my guess would be "Java 6 -server" rather than "Java 6 -server #2" or "Java 6 -server #4" (both of which seem to declare 'n' final but don't use all the cores) ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
> > (defn map-when "Like map but discards logically false entries" > > [fn & seqs] > > (filter identity (apply map fn seqs))) > > I'd use map-when. > > > (defn iterate-while [f x] > > (take-while identity (iterate f x))) > > This one too. > > It raises a question, though -- how much functionality should a > function provide to be worth making everyone who reads the code learn > the new vocabulary? I've written each of these inline when I've > needed them. Are they better as idioms or functions? I would say they're better as functions, for several reasons. First, many of these aren't really "new vocabulary", since you can clearly tell what they do from their name and knowledge of the existing core functions. If you know map and you know take-when and take-while, you already know what map-when and map-while do. Moreover, I think some of these actually fill in mysterious gaps in the language. For and map are essentially two different ways of saying the same thing; which to use in a given situation seems to be largely a matter of aesthetics (except when there are multiple iterates...). Yet, for supports :when and :while, whereas there are no map-when and map-while forms. Conversely, we get mapcat but no forcat. Even if you don't buy this, the other advantage of having, e.g., (map- when ...) rather than treating (filter identity (map ...)) as idiomatic is that map-when can be implemented more efficiently, so that it doesn't cons up an extra list; however, the more efficient form is much uglier and almost certainly won't become an idiom. So, to summarize, IMO adding utilities like map-when give you - More uniformity in the language - More concise programs (without sacrificing readibility) - Greater efficiency Finally, I want to mention that some of the idioms these functions replace are not as easy to read as that for map-when. For instance, I find myself needing to use map-map or merge-reduce fairly frequently, and the (reduce (fn [m [k v]] (assoc m k (f v))) {} m) type idioms they replace are much more difficult to read than calls to the utilities IMO. Cheers, Jason map-map --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Ring: A Web application library for Clojure.
On Jan 13, 4:45 am, Mark McGranaghan wrote: > In terms of Clojure web frameworks, I think that there is a lot to be > gained by leveraging the Ring interface, especially from the modular > functionality provided by Ring middleware. I'd like in particular to > be able to run Compojure apps in Ring - if the users and authors of > Compojure are interested I'd be happy to work with them to see what we > can do. I think it's a good idea in principle to have a common functional way of accessing servlets. However, I notice there's still some wheel reinventing going on. The HttpServlet API provides methods for parameters, cookies and sessions, but these are absent from Ring. I notice that in your weld framework, you implement these pieces of functionality in Clojure, but why? I can understand keeping a low- level interface lightweight, but Ring appears to be lightweight than the Servlet API it's based upon. Other than that, I generally like what I see in Ring. It uses Clojure data structures, is functional, and is refreshingly explicit. - James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
On Tue, Jan 13, 2009 at 4:05 PM, Jason Wolfe wrote: >> >> It raises a question, though -- how much functionality should a >> function provide to be worth making everyone who reads the code learn >> the new vocabulary? I've written each of these inline when I've >> needed them. Are they better as idioms or functions? > > I would say they're better as functions, for several reasons. > > First, many of these aren't really "new vocabulary", since you can > clearly tell what they do from their name and knowledge of the > existing core functions. If you know map and you know take-when and > take-while, you already know what map-when and map-while do. > > Moreover, I think some of these actually fill in mysterious gaps in > the language. For and map are essentially two different ways of > saying the same thing; which to use in a given situation seems to be > largely a matter of aesthetics (except when there are multiple > iterates...). Yet, for supports :when and :while, whereas there are > no map-when and map-while forms. Conversely, we get mapcat but no > forcat. Those are good arguments. I guess what I fear is some of the reaction I've had to reading Common Lisp code. The difference in feeling between CL and Clojure is important to me because I tried repeatedly and failed to adopt CL into my toolbox, but Clojure went quite smoothly. One of the things I found difficult with CL was the extremely large number of builtin functions -- a large vocabulary with subtle differences between nearly synonymous-sounding words. It meant that at first glance, a particular block of could would look simple -- 5 lines, how hard could it be? But in reading it I would discover I only new 2 of the 15 functions used. So I'd fight through it, feeling like I was learning something useful, but the next function would use 15 completely different functions. Now perhaps I'm just whining, perhaps I needed better reference tools, perhaps I'm mis-identifying the problem. But it is a real source of my hesitancy to ask for more built-in functions. > For instance, I > find myself needing to use map-map or merge-reduce fairly frequently, > and the (reduce (fn [m [k v]] (assoc m k (f v))) {} m) type idioms > they replace are much more difficult to read than calls to the > utilities IMO. Yes, that's a mouthful. I'll need to study merge-reduce and map-map a bit more to see when to use them instead of merge, merge-with, and into. --Chouser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Profiling Clojure with YourKit: file names and line numbers?
I've got Clojure profiling working fairly easily using the free pre- release build of YourKit [1], and it's already been a big help in speeding up my application (I'll post on my blog about this soon). The main difficulty has been figuring out which functions are which in the output, since the only identifying information that shows up in the stack traces are package names and names from top-level defns. Methods and anonymous functions show up as they do in Clojure stack traces, but without the file names and line numbers. So, my question is, does anyone with experience with YourKit know if there's a way to show filenames and line numbers. Or, is there a way to take a string like edu.berkeley.ai.angelic.hierarchies $fn__5212$iter__5214__5216$fn__5218.invoke(Object) and extract a filename and line number from the clojure REPL from which the profiling was done? Or, even better, might it be possible to replace the (gensym?) numbers following anonymous functions with something more meaningful, like fn__ where a is the first function on the line, going from inside-out and then left-to-right? [1] http://www.yourkit.com/eap/index.jsp Thanks, Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: non recursive impl in presence of persistence?
On Jan 13, 6:45 pm, e wrote: > sure . . . I'm just impressed with how many things "just work", and this > could be one more. Not enough args, but you know what I wanted it to mean. > There's no ambiguity. This is a bad idea. It just adds confusion with no real benefit. Reading the code would be harder, and you'd wind up with all sorts of odd behavior if (nil) evaluated to nil. Or to put it another way, imagine if you allowed this behavior in Python: if foo(): bar() Are foo and bar functions, or lists? - James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Patch: Arbitrary Symbols between ||
Hello everybody, this patch implements a pipe-delimited syntax for symbols. The Reader parses |this symbol| and one symbol. Symbols containing clojure syntax are printed in this form, so they can be printed and read in again. example: (.toString (symbol "()")) => "|()|" What do you think? Robert Pfeiffer --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~--- arbitrarysymbolsbetweenpipechars.patch Description: Binary data
Re: Ring: A Web application library for Clojure.
Hi James, Thanks for taking the time to check out Ring. > The HttpServlet API provides methods for > parameters, cookies and sessions, but these are absent from Ring. I > notice that in your weld framework, you implement these pieces of > functionality in Clojure, but why? I can understand keeping a low- > level interface lightweight, but Ring appears to be lightweight than > the Servlet API it's based upon. I choose not include the parameters, cookies, and sessions features from the Servlet API because I'm not confident that the interfaces presented by Servlets in these cases will be acceptable to all Ring applications. For example, different Ring applications will want to parse parameters in different ways and will have varying requirements for session storage. I think it would be detrimental if Ring applications were compromised by the limitations of the Servlet API when these features can be defined entirely in terms of the more core subset of the Servlet API reflected in the Ring request object. The decision not to require that a Ring request support these extra features of the HttpServlet API was a difficult one to make because not having them will make integration with Compojure and other Java/Servlet-leaning codebases more difficult. I do though still think its worth pursuing in the case of Compojure - if you're interested maybe we should start a discussion on the Compojure list? - Mark On Tue, Jan 13, 2009 at 4:13 PM, James Reeves wrote: > > On Jan 13, 4:45 am, Mark McGranaghan wrote: >> In terms of Clojure web frameworks, I think that there is a lot to be >> gained by leveraging the Ring interface, especially from the modular >> functionality provided by Ring middleware. I'd like in particular to >> be able to run Compojure apps in Ring - if the users and authors of >> Compojure are interested I'd be happy to work with them to see what we >> can do. > > I think it's a good idea in principle to have a common functional way > of accessing servlets. However, I notice there's still some wheel > reinventing going on. The HttpServlet API provides methods for > parameters, cookies and sessions, but these are absent from Ring. I > notice that in your weld framework, you implement these pieces of > functionality in Clojure, but why? I can understand keeping a low- > level interface lightweight, but Ring appears to be lightweight than > the Servlet API it's based upon. > > Other than that, I generally like what I see in Ring. It uses Clojure > data structures, is functional, and is refreshingly explicit. > > - James > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 4:30 am, Mark P wrote: > On Jan 13, 5:49 pm, Zak Wilson wrote: > > > You're probably thinking of > > this:http://www.flownet.com/gat/papers/lisp-java.pdf > > Thanks for the link. > > > There's also the (in)famous language benchmark > > site:http://shootout.alioth.debian.org/ > > This is primarily what I was going on. I realize no > benchmarking approach is going to be perfect, but > this attempt doesn't seem too bad. Is there any > reason to be particularly sceptical about results > found here? > > Oh, and I realize my comments about SBCL lisp being > 3 to 4 times slower than C++ only apply for the quad > core machines. Notice which programs are using more than one core and which aren't. > The single core machines have SBCL > as 2.2 or 2.3 times slower than C++. Perhaps this > is a truer representation of SBCL's "raw capabilities". > > But a 120% performance hit is still quite a whack. > > Cheers, > > Mark P. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure now running in production
On Tue, 2009-01-13 at 10:56 -0800, Vincent Foley wrote: > As this is a commercial project, I imagine you are quite limited in > what you can tell us, but I'd love to hear about the issues you faced > during development. Mostly integration problems with the work flow in the radiology system. That big multinational company that I will not name has the worse support team I ever saw. The left hand does not know what the right hand is doing, their people have a very limited knowledge of the company's product and it looks like they cannot escalate worldwide to find the proper expertise. The customer was banging his head in the wall... They caused the schedule to slip a lot. Since their own system is distributed and that none of them really understands the whole picture, I said a lot of profanities ... behind private walls. I am pretty sure they cannot pee by themselves, you would have to show them how; get the zipper down with the left/right hand, get the ... out, align the ... , ..., :))) Technology wise, it was a breeze. Spring 2.5, Java 5, Rails 2., Terracotta 2.6 were stable as was Clojure too. ActiveMq as of 5.2 became stable, we needed some of the new features in version 5 so we could not use a 4.x version. Prior to version 5.2, it was shaky and it required some digging to find the patches/workarounds we needed. Design wise, the prototype was using XML on the bus. We were using a tool (xmlbooster) to generate parser/generator code but I wanted something less verbose and supported in Java, Ruby and eventually other languages so we went with YAML in the production release. The YAML library we used needed some fixes, that's the only part that we had to retool a bit to make more robust. We use map representations of messages on the bus and this is language neutral in Java and Ruby. We also convert from Clojure types to YAML, we simply replace the java Clojure class type in the YAML output by a java equivalent so a java component receiving the message does not need Clojure classes to deal with the message. >From now on, the product will simply grow in maturity and I have an impressive wish list both addressing the user base needs and what I see as making this a more resilient and scalable system. As for the market well, every player wants to be the focus of attention but since none of them addresses all the needs in all the medical fields, it looks like there is space there and some necessity for a middle man. With our product you can monitor everything in real time from your desk if you need to. Finding if a request was forwarded or if errors were reported is a matter of seconds. No endless searches in log files, digging to try to understand what went wrong. Luc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~--- <>
Re: Utilities for clojure.contrib?
On Jan 13, 1:42 pm, Chouser wrote: > One of the things I found difficult with CL was the extremely large > number of builtin functions -- a large vocabulary with subtle > differences between nearly synonymous-sounding words. It meant that > at first glance, a particular block of could would look simple -- 5 > lines, how hard could it be? But in reading it I would discover I > only new 2 of the 15 functions used. So I'd fight through it, feeling > like I was learning something useful, but the next function would use > 15 completely different functions. I don't recall having this problem with CL, but then again I never did much reading of other peoples' code. The size of the reference section of ANSI CL is definitely daunting though. I guess there's a delicate balance here between functionality and complexity. I think my personal preference is towards more functionality at the expense of added complexity, but I can see the other side too. One thing worth pointing out is that, if a utility is really useful many people will independently recreate it with slightly different names and functionality, and use it in their code. It seems that this results in code that's much more difficult to read than if the utility was standardized in the first place. > Yes, that's a mouthful. I'll need to study merge-reduce and map-map a > bit more to see when to use them instead of merge, merge-with, and > into. Oops, don't know how I missed those. Looks like merge-reduce is almost identical to merge-with (except that it allows seqs of map- entries for all maps but the first), and map-map is equivalent to (into {} (map ...)). I'm not sure if this example supports or detracts from my argument above. On one hand, these utilities are clearly useful enough that I've independently recreated them (this also happened verbatim for several utilities I later discovered in clojure.contrib). On the other hand, given that they already existed (in clojure.core, no less), this would seem to support your point that having more standardized utilities just means that nobody will ever know them all well. -Jason --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 13, 4:41 am, "Eric Lavigne" wrote: > > > There's also the (in)famous language benchmark > > > site:http://shootout.alioth.debian.org/ > > > This is primarily what I was going on. I realize no > > benchmarking approach is going to be perfect, but > > this attempt doesn't seem too bad. Is there any > > reason to be particularly sceptical about results > > found here? > > The programs are written by volunteers, so the languages which have people > that care about the results (and spend more time writing optimized code for > their language of choice) get a big boost in score. It's easy to see which languages have suffered from relative neglect - they're the ones where most of the programs were written by me and still haven't been re-written by anyone else :-) C# Mono, Mozart/Oz, PHP, Scala otoh Scheme programs by Matthew Flatt, Haskell programs by Don Stewart, Clean programs by John van Groningen, etc - wow! > Results are also > affected by whether relevant libraries (often highly optimized for speed and > memory) are included in the language's standard library, as third party > libraries can't be used in shootout submissions. Except when they can - pcre, libgmp > Also, for many shootout > problems, the answer can be determined at compile-time, so you are > potentially testing an aspect of compilation optimization that is not so > relevant for practical programming problems. > > I don't know of a better set of benchmark results to look at - I use the > shootout results myself - but I would take them with a grain of salt. In the words of Simon Peyton-Jones - "flawed, but available" http://www.haskell.org/pipermail/haskell-cafe/2008-December/052589.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Designing a Performance Vector Math library in Clojure.
> With repeated runs, and my cpu frequency set to not change, I get very > little speed improvement. I increased the size of the example range > times 10 for these runs: For me there is a very clear speed improvement of at least 40%, doing quite a lot of repeated runs. I can't run with range times 10 because it crashes my REPL, so I guess it is quite machine/JVM specific as to the relative performances. Here is a sample extract of how I tested (more runs done in practice). I'm not sure how to "cpu frequency set to not change" or how significant that is on my results. ;; first setting up the test and using normal get user=> (defstruct desilu :fred :ricky) #'user/desilu user=> (def x (map (fn [n] (struct-map desilu :fred n :ricky 2 :lucy 3 :ethel 4)) (range 10))) #'user/x user=> (def fred (accessor desilu :fred)) #'user/fred ;; ignore the first one user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 1365.325055 msecs" 45 user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 91.447766 msecs" 45 user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 72.951146 msecs" 45 user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 78.106709 msecs" 45 user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 76.300491 msecs" 45 user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) "Elapsed time: 81.184388 msecs" 45 ;; switching to accessor, getting a consistent speed increase of about 40% user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) "Elapsed time: 53.602536 msecs" 45 user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) "Elapsed time: 51.098607 msecs" 45 user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) "Elapsed time: 51.512913 msecs" 45 user=> (time (reduce (fn [n y] (+ n (fred y))) 0 x)) "Elapsed time: 53.062693 msecs" 45 ;; I defined my own access method so that an accessor is not required, ;; however then you need to type hint which makes it too clumsy ;; performs very similar to an accessor, in theory slightly faster ;;public Object access(int i) throws Exception{ ;; return vals[i]; ;;} user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 53.376319 msecs" 45 user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 49.545614 msecs" 45 user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 49.348831 msecs" 45 user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 49.313406 msecs" 45 user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 51.485216 msecs" 45 user=> (time (reduce (fn [n #^clojure.lang.PersistentStructMap y] (+ n (.access y 0))) 0 x)) "Elapsed time: 50.024856 msecs" 45 ;; then I try running with 10x as you suggested user=> (defstruct desilu :fred :ricky) #'user/desilu user=> (def x (map (fn [n] (struct-map desilu :fred n :ricky 2 :lucy 3 :ethel 4)) (range 100))) #'user/x user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at jline.ConsoleRunner.main(ConsoleRunner.java:69) Caused by: java.lang.OutOfMemoryError: Java heap space at java.lang.reflect.Method.copy(Unknown Source) at java.lang.reflect.ReflectAccess.copyMethod(Unknown Source) at sun.reflect.ReflectionFactory.copyMethod(Unknown Source) at java.lang.Class.copyMethods(Unknown Source) at java.lang.Class.getMethods(Unknown Source) at clojure.lang.Reflector.getMethods(Reflector.java:300) at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java: 27) at clojure.main$repl__5506$fn__5509.invoke(main.clj:136) at clojure.main$repl__5506$fn__5524.invoke(main.clj:154) at clojure.main$repl__5506.doInvoke(main.clj:145) at clojure.lang.RestFn.invoke(RestFn.java:426) at clojure.main$repl_opt__5548.invoke(main.clj:208) at clojure.main$legacy_repl__5573.invoke(main.clj:249) at clojure.lang.Var.invoke(Var.java:327) at clojure.main.legacy_repl(main.java:29) at clojure.lang.Repl.main(Repl.java:20) ... 5 more ;; REPL crashed --~--~-~--~~~---~--~~ You received this message because you
Re: Designing a Performance Vector Math library in Clojure.
> user=> (defstruct desilu :fred :ricky) > #'user/desilu > user=> (def x (map (fn [n] > (struct-map desilu >:fred n >:ricky 2 >:lucy 3 >:ethel 4)) > (range 100))) > #'user/x > user=> (time (reduce (fn [n y] (+ n (:fred y))) 0 x)) > Exception in thread "main" java.lang.reflect.InvocationTargetException >at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown > Source) >at java.lang.reflect.Method.invoke(Unknown Source) >at jline.ConsoleRunner.main(ConsoleRunner.java:69) > Caused by: java.lang.OutOfMemoryError: Java heap space I'm not sure how to do it in your configuration, but you need to as -XmxM to your java invocation. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Ring: A Web application library for Clojure.
On Jan 13, 9:56 pm, "Mark McGranaghan" wrote: > I choose not include the parameters, cookies, and sessions features > from the Servlet API because I'm not confident that the interfaces > presented by Servlets in these cases will be acceptable to all Ring > applications. For example, different Ring applications will want to > parse parameters in different ways and will have varying requirements > for session storage. Sure, but that doesn't mean they have to use them. It seems to me that Ring's approach works well if there's the possibility of implementing Ring using technology other than Servlets. In this case, it makes sense for Ring to act as a minimum common interface. But if this isn't your goal, then you're just removing functionality for aesthetic reasons. I'm in two minds about this. I agree that session handling and parameter parsing don't belong in a functional interface for HTTP handling. But on the other hand, they certainly do belong in a functional interface to the Java Servlet spec (flawed as that spec may be). If you're attempting the former, then I agree with your decision. If it's the latter, I think you should be more pragmatic. > The decision not to require that a Ring request support these extra > features of the HttpServlet API was a difficult one to make because > not having them will make integration with Compojure and other > Java/Servlet-leaning codebases more difficult. It's true that many parts of the compojure.http library are currently tightly coupled to the javax.servlet libraries, but this shouldn't be the state of affairs for too much longer. I've been planning on splitting out the compojure.http library into more generic parts for some time, so it shouldn't be too hard to work Ring into my plans as well - or at least to leave a Ring-shaped hole for someone to fill in. > I do though still think its worth pursuing in the case of Compojure > - if you're interested maybe we should start a discussion on the > Compojure list? Go for it :) - James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Newbie: Creating a macro that just calls a function but evaluates its arguments lazily
Thank you for the explanation; I understand it a lot better now. The reason that I decided to use Delays was that I thought I would need to change less. Now that I've actually changed everything to Delays, it seems that they take much more time (the opposite of what I was trying to do :(. But when I checked using your and Konrad's explanation, the time was shorter than both of them. --- Clojure user=> (defn alt [& functions] (fn [tokens] (some #(% tokens) functions))) #'user/alt user=> (defn sub-function1 [c] (println "1:" c) (fn [c] false)) #'user/sub-function1 user=> (defn sub-function2 [c] (println "2:" c) (fn [c] true)) #'user/sub-function2 user=> (defn sub-function3 [c] (println "3:" c) (fn [c] false)) #'user/sub-function3 user=> (defn a-meta-meta-function [c] (alt (sub-function1 c) (sub-function2 c) (sub-function3 c))) #'user/a-meta-meta-function user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c])) 1: CONTEXT 2: CONTEXT 3: CONTEXT "Elapsed time: 1.062 msecs" true user=> (time ((a-meta-meta-function "CONTEXT") [:a :b :c]) ) 1: CONTEXT 2: CONTEXT 3: CONTEXT "Elapsed time: 0.444 msecs" true --- Clojure user=> (defn alt [& funcs] (fn [tokens] (some #((%) tokens) funcs))) #'user/alt user=> (defn sub-function1 [c] (println "1:" c) (fn [c] false)) #'user/sub-function1 user=> (defn sub-function2 [c] (println "2:" c) (fn [c] true)) #'user/sub-function2 user=> (defn sub-function3 [c] (println "3:" c) (fn [c] false)) #'user/sub-function3 user=> (defn mmf [c] (alt #(sub-one c) #(sub-two c) #(sub-three c))) java.lang.Exception: Unable to resolve symbol: sub-one in this context (NO_SOURCE_FILE:5) user=> (time (defn mmf [c] (alt #(sub-function1 c) #(sub-function2 c) # (sub-function3 c))) ) "Elapsed time: 0.167 msecs" #'user/mmf user=> (time ((mmf "context") [:a :b :c])) 1: context 2: context "Elapsed time: 1.011 msecs" true user=> (time ((mmf "context") [:a :b :c])) 1: context 2: context "Elapsed time: 0.295 msecs" true user=> (time ((mmf "context") [:a :b :c])) 1: context 2: context "Elapsed time: 0.208 msecs" true --- I didn't consider that suggestion enough, and now I'm going to pay for it by refactoring everything again, this time to using meta-functions. Oh, well—thanks to everyone for their help. :) On Jan 13, 12:51 pm, Perry Trolard wrote: > Hi sampii, > > The problem, as I see it (& as Konrad suggested above), is that you're > not passing *functions* to (alt); you're passing values returned from > function calls, even though in the case of the sub-functions you > define those returned values are functions. Functions evaluate to > themselves, so if you can write your code to pass functions to (alt), > e.g. > > (alt #(sub-function1 c) #(sub-function2 c) #(sub-fuction3 c)) > > you should be golden. > > Just to show it can be done, if you make the args to alt be > > (defn mmf [c] (alt #(sub-one c) #(sub-two c) #(sub-three c))) > > (note the #() reader macro)), & if you modify the definition of alt to > be > > (defn alt [& funcs] (fn [tokens] (some #((%) tokens) funcs))) > > (note the extra set of parens around % -- so that the #(sub-one c) > funcs get called, then their return values likewise get called), you > get > > user=> ((mmf "context") [:a :b :c]) > 1 context > 2 context > true > > Of course it would be more straightforward to drop the intermediate > step of the anonymous functions -- #(sub-one c) -- which return yet > another function -- (fn [c] true) -- say, by passing the equivalent of > (fn [c] true) directly to alt, but I don't know your actual use case. > > My recommendation -- to passing function -- is simple enough that I > feel like I might be missing something important from your question, > but in case I'm not I didn't want you to think your only recourse was > the full machinery of delay/force. Transcript follows. > > Best, > Perry > > user=> (defn alt [& funcs] (fn [tokens] (some #((%) tokens) funcs))) > #'user/alt > user=> (defn sub-one [c] (println 1 c) (fn [x] false)) > #'user/sub-one > user=> (defn sub-two [c] (println 2 c) (fn [x] true)) > #'user/sub-two > user=> (defn sub-three [c] (println 3 c) (fn [x] false)) > #'user/sub-three > user=> (defn mmf [c] (alt #(sub-one c) #(sub-two c) #(sub-three c))) > #'user/mmf > user=> ((mmf "context") [:a :b :c]) > 1 context > 2 context > true --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Designing a Performance Vector Math library in Clojure.
> ;; I defined my own access method so that an accessor is not required, > ;; however then you need to type hint which makes it too clumsy > ;; performs very similar to an accessor, in theory slightly faster Actually there is a very simple way to make "by index" quite usable without user type hints: core.clj: (defn get-field "Accesses a struct-map field by index instead of name or accessor" [#^clojure.lang.PersistentStructMap s #^Integer index] (.access s index)) PersistentStructMap.java: public Object access(int i) throws Exception{ return vals[i]; } user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x)) "Elapsed time: 45.038806 msecs" 45 user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x)) "Elapsed time: 51.727498 msecs" 45 user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x)) "Elapsed time: 50.091357 msecs" 45 user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x)) "Elapsed time: 51.299742 msecs" 45 user=> (time (reduce (fn [n y] (+ n (get-field y 0))) 0 x)) "Elapsed time: 51.106905 msecs" 45 Just thought I'd mention it as it might be a preferable form over accessors to some people (perhaps only myself *chuckle*). Regards, Tim. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: IntelliJ Plugin
Did you ever get around to posting the notes on getting the IntelliJ plugin to work? I sorely would love IDE support for Clojure in either Eclipse or IntelliJ. Is the IntelliJ one in a usable state, or is it not ready for some alpha-level testers? Cheers, Aria On Dec 29 2008, 10:36 am, "Justin Johnson" wrote: > On Sat, Dec 27, 2008 at 8:55 AM, Peter Wolf wrote: > > Hi Justin, > > This is the right place. Thanks for trying the plugin. > > > It would absolutely be helpful to document use of the plugin. However, I > > am sure you can tell that it is nowhere near ready. > > Yes, I noticed there wasn't much there yet. I still think it would be great > if you documented how you build and test. In particular I found it to be a > pain to setup my own update site and updatePlugins.xml file just to install > my own plugin. It wasn't difficult, but certainly not efficient. My hope > was that sharing setup info like this would help me discover more efficient > ways of working. > > > > > I would like to get a basic set of features going and then recruit you and > > Randall to test and document it. Once it is banged on, we can post the > > plugin to IntelliJ so it can be installed with a mouse click. > > > I am currently working on the Parser, which will give us parens matching > > and folding, and Compile/Run/Debug/Profile. > > > The one big piece I am missing is the REPL. Any help would be appreciated. > > > Peter > > > On Wed, Dec 24, 2008 at 4:25 PM, Justin Johnson > > wrote: > > >> Hi, > > >> Is this the appropriate mailing list to talk about the Clojure IntelliJ > >> plugin? The Google Code site didn't list any other mailing list. > > >>http://code.google.com/p/clojure-intellij-plugin/ > > >> I went through the process of building and installing the plugin on > >> Windows XP with IntelliJ IDEA 8.0.1 and thought it might be helpful if I > >> document what I did on the wiki. I also have a small suggestion that the > >> build.xml file use environment variables instead of hard coded paths to > >> java.home and idea.home. > > >> Thanks, > >> Justin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Ring: A Web application library for Clojure.
> It seems to me that Ring's approach works well if there's the > possibility of implementing Ring using technology other than Servlets. > In this case, it makes sense for Ring to act as a minimum common > interface. But if this isn't your goal, then you're just removing > functionality for aesthetic reasons. > > I'm in two minds about this. I agree that session handling and > parameter parsing don't belong in a functional interface for HTTP > handling. But on the other hand, they certainly do belong in a > functional interface to the Java Servlet spec (flawed as that spec may > be). If you're attempting the former, then I agree with your decision. > If it's the latter, I think you should be more pragmatic. For Ring, the HttpServlet API is a means to an end, not an end in itself. The interface that Servlets present for parameter parsing and session handling are too flawed to merit their inclusion as default choices for Ring apps and the binding of Ring to Servlets in general. Thus I'd like to see Ring applications remain decoupled from the Servlet API, while Ring handlers can leverage Servlet functionality internally to implement for these apps the cleanest HTTP API possible. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
On Jan 14, 9:13 am, Jason Wolfe wrote: > > One thing worth pointing out is that, if a utility is really useful > many people will independently recreate it with slightly different > names and functionality, and use it in their code. It seems that this > results in code that's much more difficult to read than if the utility > was standardized in the first place. That's a good point, but raises the question: is it enough to include your functions in clojure.contrib if the objective is to standardize them? Inclusion in the core is the most secure path to standardization :) I realise the core shouldn't be expanded forever, but in the case of map-when, map-while, etc: * these are _fundamental_ functions, as opposed to domain-specific functions (DB access, web programming, ...) which suggest "library" rather than "core" * they are _named_ like other fundamental functions, as you pointed out, so they add to the utility of the core without adding to its complexity * provided they're useful enough, they're crying out to be standardized in this way: it's odd to use take-when freely but have to load a library to use map-when I would say this argument does not hold for functions such as 'combinations. > > > [...] > > I'm not sure if this example supports or detracts from my argument > above. On one hand, these utilities are clearly useful enough that > I've independently recreated them (this also happened verbatim for > several utilities I later discovered in clojure.contrib). On the > other hand, given that they already existed (in clojure.core, no > less), this would seem to support your point that having more > standardized utilities just means that nobody will ever know them all > well. It's a very good point. I already feel daunted by the number of clojure's core functions, coming from an OO background where classes prevent global namespace pollution (and make it easier, for example, to read about all functions on strings, or lists, or ...). Therefore I would not be keen on a huge core. But I think it's important to plug the gaps (any?, map-when) with consistent naming schemes so that new users feel Clojure is well-organised, and a sensible, rich vocabulary develops amongs all users. I've spent a lot of time documenting Ruby's standard library, and based on that experience, think it's a damn good idea to get a lot of these "basics" sorted out as early as possible. On the other hand, I lack extensive experience in Clojure, so can't necessarily offer good judgement here. But please be assured I have read a _lot_ of messages in this group before posting any :) Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
clojure.contrib.command-line patch: multiple option format
Hi Chouser & list, I like clojure.contrib.command-line -- thanks for it! -- but I wanted to be able to specify multiple forms for an option, e.g. --help, -h, -?, etc. Here (in the Files section) http://bit.ly/fIVH is a patch to enable it (the values are bound only to the first form given -- help, in the previous example). Would you consider it (my CA is in)? Best, Perry --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
On Jan 12, 10:21 am, Stuart Sierra wrote: > If you have > highly-optimized, custom-designed numerical algorithms written in a > low-level language like C++, you will never be able to write a version > that is equally fast in a dynamic, virtual-machine language. I wouldn't say "never"; clearly Clojure is a managed language, but one important selling point it has I think versus "language+toy VM" dynamic languages like Ruby and Python is that you can easily drop to a lower level with type hints, and in Java dropping to primitives is going down even farther. It doesn't seem hard to imagine that Hotspot could see through and unroll some "inner loop" functional Clojure code with type hints into something much like what a C/C++ compiler would produce. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Programming Clojure Beta 5 is Out
Well, I've gone ahead and finally bought it. Here I thought I would have time to read a fiction novel or something :) On Jan 13, 12:02 pm, Stuart Halloway wrote: > http://blog.thinkrelevance.com/2009/1/13/programming-clojure-beta-5-i... > > Cheers, > 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 To unsubscribe from 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: A Web application library for Clojure.
On Jan 14, 12:35 am, "Mark McGranaghan" wrote: > For Ring, the HttpServlet API is a means to an end, not an end in > itself. The interface that Servlets present for parameter parsing and > session handling are too flawed to merit their inclusion as default > choices for Ring apps and the binding of Ring to Servlets in general. Okay, I think I'm convinced of your reasoning. Currently there are too many practical benefits with servlets for me to drop them as the primary interface to Compojure, but Ring is the more elegant interface, and one that I think will be worth time integrating as an alternative back end. - James --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Erlang vs Clojure
On Dec 5 2008, Luc Prefontaine wrote: > I feel we will start before Xmas to put together a prototype. > > I really want this to come to life because we could use cooperative > Clojure instances on our bus. This would also > provide us another form of persistance. Presently we rely on ActiveMq > queues but to maximize parallelism we > need another model and building that from queues would be harder. > > I'll keep everyone posted. As soon as I can get my hands on it without > being interrupted by the current > release of our bus we launch this. For the record, if anyone is watching only this thread post, Luc has posted an update here: http://groups.google.com/group/clojure/browse_thread/thread/85649a134cf22655# --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Clojure now running in production
On Jan 14, 9:07 am, Luc Prefontaine wrote: > > As this is a commercial project, I imagine you are quite limited in > > what you can tell us, but I'd love to hear about the issues you faced > > during development. > > Mostly integration problems with the work flow in the radiology system. > [] Very interesting to read about. Thanks Luc, and congratulations! Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
On Jan 14, 1:12 am, Timothy Pratley wrote: > I've written small wiki article which dives right into the look and > meaning of common Clojure constructs with examples. Personally I find > I learn best by examples and when starting out they were hard to find, > whereas formal descriptions were there but rather cryptic when you > don't understand the context. My intention is to provide an initial > understanding of how programs look, what they mean, and what can be > accomplished because of their features... from which someone would > then move to one of the more complete articles and references. > > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example > > I hope someone finds it useful :) That's really good, Tim. I hope you continue with it :) AFAIC, just about every function in core, set, zip and xml needs to be documented by example. I'm just not smart enough to read the API docs of a lot of functions and understand how to use them. Some efficiency could be gained by demonstrating several functions at once, clearly labeling them. An example without much thought: (Heading) map, range (map sqr (range 1 10 2)); after defining sqr Cheers, Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: java.lang.IncompatibleClassChangeError: [class] and [inner class] disagree on InnerClasses attribute
Aha! I notice that this problem goes away if I run the JVM the way I'm supposed to (with -cp lucene-core.xxx.jar) instead of using (add- classpath ...) to load the jar in the first place. This probably isn't a big deal, then :o) Thanks, Mark On Jan 13, 11:06 am, Mark Triggs wrote: > Hi all, > > I've just been fiddling with Lucene indexing from Clojure, and wanted > to > access a static field of this inner class: > > http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/index/Index... > > I'm importing IndexWriter$MaxFieldLength with no problems, but > attempts > to eval: > > IndexWriter$MaxFieldLength/UNLIMITED > > or > > (. IndexWriter$MaxFieldLength UNLIMITED) > > both yield the following exception: > > java.lang.IncompatibleClassChangeError: > org.apache.lucene.index.IndexWriter and > org.apache.lucene.index.IndexWriter$MaxFieldLength disagree on > InnerClasses attribute (NO_SOURCE_FILE:0) [Thrown class > clojure.lang.Compiler$CompilerException] > > I'm running SVN r1205. Am I doing something wrong here? > > Thanks, > > Mark --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Utilities for clojure.contrib?
On Jan 13, 4:42 pm, Chouser wrote: > One of the things I found difficult with CL was the extremely large > number of builtin functions -- a large vocabulary with subtle > differences between nearly synonymous-sounding words. I've had the same experience with Common Lisp code. On the other hand, CL also has the problem that everyone defines their own batch of little utility functions, with a lot of overlap but all slightly different. clojure.contrib is slowly evolving into a standard library, but so far it has been more valuable as a testing ground for features that later went into core -- the lib system, several predicates, and defonce, just to name a few. I think contrib is a good place to post any code that might be generally useful. If there are things in contrib that you feel are critical to Clojure itself, you can lobby for their inclusion in the core. -Stuart Sierra --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Suggested functions for core: any? none?
I also find the choice of some/not-any? as opposites to be hard to remember. I'd rather it be some/not-some? or any/not-any? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Can't lookup java.lang.Long keys in a map using int literal
On Jan 13, 11:18 am, Allen Rohner wrote: > I thought I was using all ints, but it turns out that a java API > returned a long when I thought it returned an int. FYI, You can coerce to specific types with the functions int, long, short, etc. You could use that when creating your map to ensure the keys are the correct type. -Stuart Sierra --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Can't lookup java.lang.Long keys in a map using int literal
It might be nice if there were a function that automatically converted the number to the type that Clojure uses for that number if typed in as a literal. On Tue, Jan 13, 2009 at 7:27 PM, Stuart Sierra wrote: > > FYI, You can coerce to specific types with the functions int, long, > short, etc. You could use that when creating your map to ensure the > keys are the correct type. > > -Stuart Sierra > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: non recursive impl in presence of persistence?
ok ok. . . .but yall made lists functions . .. so I could ask the same question of if foo(3): bar(3). if foo a function or a list? It looks like a function. but it's a list, too. . . .because in clojure lists are functions . . . .but only if they take one argument. I didn't start the confusion. (bar 3) is somehow normal . . . . but (bar) isn't? (nth 3 bar) is what's "normal". (bar 3) make (bar) almost work . . . .enough so that the error that is produced is off topic hard to understand, but hey, that's cool with me. I get it now. I can see how experience with such errors will point me to the right place. () is a function call unless quoted so that it can be data . . . or something . . . .right? it didn't make sense to have parens there . . . just a habbit from C++. On Tue, Jan 13, 2009 at 4:52 PM, James Reeves wrote: > > On Jan 13, 6:45 pm, e wrote: > > sure . . . I'm just impressed with how many things "just work", and this > > could be one more. Not enough args, but you know what I wanted it to > mean. > > There's no ambiguity. > > This is a bad idea. It just adds confusion with no real benefit. > Reading the code would be harder, and you'd wind up with all sorts of > odd behavior if (nil) evaluated to nil. > > Or to put it another way, imagine if you allowed this behavior in > Python: > > if foo(): bar() > > Are foo and bar functions, or lists? > > - James > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
i know that will be awesome for me. I just wish clojure.org was the only place I had to go to get stuff like that. Why not wikify it all there? On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: > > On Jan 14, 1:12 am, Timothy Pratley wrote: > > I've written small wiki article which dives right into the look and > > meaning of common Clojure constructs with examples. Personally I find > > I learn best by examples and when starting out they were hard to find, > > whereas formal descriptions were there but rather cryptic when you > > don't understand the context. My intention is to provide an initial > > understanding of how programs look, what they mean, and what can be > > accomplished because of their features... from which someone would > > then move to one of the more complete articles and references. > > > > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example > > > > I hope someone finds it useful :) > > That's really good, Tim. I hope you continue with it :) AFAIC, just > about every function in core, set, zip and xml needs to be documented > by example. I'm just not smart enough to read the API docs of a lot > of functions and understand how to use them. > > Some efficiency could be gained by demonstrating several functions at > once, clearly labeling them. An example without much thought: > > (Heading) map, range > >(map sqr (range 1 10 2)); after defining sqr > > Cheers, > Gavin > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
I humbly propose that folks shouldn't complain about Clojure being slow for their apps until they have at least one of the following: 1. A targeted benchmark for an important bottleneck in their application, implemented in both Clojure and the current implementation language, with performance results; or 2. A performance model based on an understanding of the Clojure and HotSpot compilation processes, that highlights which particular features of the latter would make their application slower than in its current implementation language. This is not out of elitism but out of an earnest desire to be helpful; it's hard to give good advice on language choice and code optimization when we don't know what the bottlenecks are. Also it's really hard for anyone to optimize their own code unless they themselves know where the bottlenecks are. The latter means that #1 above is surprisingly easy; it often can be done with a simple function trace of a typical run. mfh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
It is, that article is part of the wiki linked to directly from clojure.org. On Tue, Jan 13, 2009 at 11:12 PM, e wrote: > i know that will be awesome for me. I just wish clojure.org was the only > place I had to go to get stuff like that. Why not wikify it all there? > > > On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: > >> >> On Jan 14, 1:12 am, Timothy Pratley wrote: >> > I've written small wiki article which dives right into the look and >> > meaning of common Clojure constructs with examples. Personally I find >> > I learn best by examples and when starting out they were hard to find, >> > whereas formal descriptions were there but rather cryptic when you >> > don't understand the context. My intention is to provide an initial >> > understanding of how programs look, what they mean, and what can be >> > accomplished because of their features... from which someone would >> > then move to one of the more complete articles and references. >> > >> > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example >> > >> > I hope someone finds it useful :) >> >> That's really good, Tim. I hope you continue with it :) AFAIC, just >> about every function in core, set, zip and xml needs to be documented >> by example. I'm just not smart enough to read the API docs of a lot >> of functions and understand how to use them. >> >> Some efficiency could be gained by demonstrating several functions at >> once, clearly labeling them. An example without much thought: >> >> (Heading) map, range >> >>(map sqr (range 1 10 2)); after defining sqr >> >> Cheers, >> Gavin >> >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
clojure.contrib.sql updates
I've checked in updates to clojure.contrib.sql. The theme is providing update and delete functions and a move to pervasive support of parameterization in queries and selection criteria. Please see the doc strings for detailed changes. Here's a summary of the changes: sql.clj - Add "update-values" to update values on rows matching selection criteria, supports parameterized criteria - Add "delete-rows" to delete rows matching selection criteria, supports parameterized criteria - Low level "do-commands" and "do-prepared" functions now return a Clojure vector giving summary results rather than a Java array - "with-results" -> "with-query-results", a thinner macro calling an internal function, supports parameterized query - Updated doc strings to improve clarity and correctness sql/internal.clj - Add with-query-results* - Update doc strings to improve clarity and correctness sql/test.clj - Provide doc strings - Fix db-exception to use a transaction - Add db-update-appearance-cost, example of update-values - Add db-update, easily callable example of update-values - Add db-grade-range, example of parameterized query --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Suggested functions for core: any? none?
On Jan 14, 2:27 pm, "Mark Engelberg" wrote: > I also find the choice of some/not-any? as opposites to be hard to > remember. I'd rather it be some/not-some? or any/not-any? I think some and any? both have their place. (let [foo (some prime? numseq)] (do something with foo)) (if (any? composite? numseq) ; we haven't finished factorising That is hastily made-up pseudocode, of course. The point it: 'any? looks like a predicate, as it should. 'some doesn't, so it's a nuisance when it is used as a predicate. Personally, I'd prefer 'some be called 'find or 'find-first, but I'm not arguing in favour of that; that's simply a preference. Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Parameterized query with clojure.contrib.sql
On Jan 12, 2009, at 4:57 PM, Greg Harman wrote: I couldn't figure out how to do this with the included functions/ macros in clojure.contrib.sql so I massaged with-results and do- prepared together to get this macro (with supporting fn), which seems to work. Useful addition for contrib.sql? Hi Greg, I checked in changes to clojure.contrib.sql that are intended to address this. If you get a chance to try the updated lib, I'd appreciate hearing how it works for you and any suggestions or bug reports you may have. Thanks, --Steve smime.p7s Description: S/MIME cryptographic signature
Re: Utilities for clojure.contrib?
> > > (defn chunk "Lazily break s into chunks of length n (or less, for the > > > final chunk)." > > > [n s] > > > (when (seq s) > > > (lazy-cons (take n s) > > > (chunk n (drop n s) > > > Should that "seq" be "seq?". If not, why not? On Jan 13, 7:17 pm, "Nick Vogel" wrote: > seq returns nil when a collection has no items. According to the > documentation for empty?, empty? is the same as (not (seq coll)) so you > should use seq for expressing the opposite of empty? According to my experiment, the code above works equally well whether 'seq or 'seq? is used. Intuitively (i.e. without actually knowing :) seq? is more efficient because it returns a boolean, not a newly- allocated sequence. So, either: 1. My experiment was wrong, and seq? is not a valid stand-in for seq in the above code. 2. My intuition is wrong, and 'seq? is not more efficient than 'seq. 3. 'seq and 'seq? are equally valid, but 'seq is preferred because of the definition of 'empty? Or something else. Which is it? Thanks, Gavin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: update-values for clojure.contrib.sql
On Jan 11, 2009, at 10:42 AM, Stephen C. Gilardi wrote: I'd like to include something like this in clojure.contrib.sql. That will go smoothest if I can base it directly on what you've written and that's only possible if you send in a contributor agreement. Would you please send one in? Hi budu, While I still encourage you (and everyone who thinks they may want to contribute) to send in a contributor agreement, I came up with an original implementation for this function. Please see my recent update to clojure.contrib.sql. Thanks for bringing the need for it to the fore. --Steve smime.p7s Description: S/MIME cryptographic signature
Re: By Example - another Clojure introduction wiki page
define "directly" I clicked on clojure.org. I don't see the link. I stared at the page for a good 30 seconds. I don't see a "links" section. . . . maybe it's there and I'm bad at reading. Ah it's inline in the getting started dialog. In my opinion, that wiki link ought to be prominently displayed on the left, maybe even above rationale . . . .in fact, stick the rationale on the wiki page as the preface to the "book" . . . in fact stick the whole page on the wiki page . . . .and at that point why not just have the wiki on clojure.org. Trust me. I'm a newby, and Tim is being insightful in making a single, quick reference goto place for information on the subject of clojure . . . .a most curious thing to have be confusing given that there's a website on the topic, clojure.org. I'm going to memorize clojure.org. Much harder will it be to memorize, go to clojure.org, then "getting started", then "wiki" . . .and then . . . hm no link so search what? . .. I dunno, go back to this thread . . .read read . . .ah yes, here it is, "By Example". So I can search on By Example, or I can find this thread. finally I'm there. Not Tim's fault. And I'm glad he's doing it. Consider this feedback and opinion. You are getting a data point on how one person thinks (or fails to think). On Tue, Jan 13, 2009 at 11:42 PM, Nick Vogel wrote: > It is, that article is part of the wiki linked to directly from > clojure.org. > > > On Tue, Jan 13, 2009 at 11:12 PM, e wrote: > >> i know that will be awesome for me. I just wish clojure.org was the only >> place I had to go to get stuff like that. Why not wikify it all there? >> >> >> On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: >> >>> >>> On Jan 14, 1:12 am, Timothy Pratley wrote: >>> > I've written small wiki article which dives right into the look and >>> > meaning of common Clojure constructs with examples. Personally I find >>> > I learn best by examples and when starting out they were hard to find, >>> > whereas formal descriptions were there but rather cryptic when you >>> > don't understand the context. My intention is to provide an initial >>> > understanding of how programs look, what they mean, and what can be >>> > accomplished because of their features... from which someone would >>> > then move to one of the more complete articles and references. >>> > >>> > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example >>> > >>> > I hope someone finds it useful :) >>> >>> That's really good, Tim. I hope you continue with it :) AFAIC, just >>> about every function in core, set, zip and xml needs to be documented >>> by example. I'm just not smart enough to read the API docs of a lot >>> of functions and understand how to use them. >>> >>> Some efficiency could be gained by demonstrating several functions at >>> once, clearly labeling them. An example without much thought: >>> >>> (Heading) map, range >>> >>>(map sqr (range 1 10 2)); after defining sqr >>> >>> Cheers, >>> Gavin >>> >>> >> >> >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
. . . that person being me if it wasn't clear :) On Wed, Jan 14, 2009 at 12:35 AM, e wrote: > define "directly" I clicked on clojure.org. I don't see the link. I > stared at the page for a good 30 seconds. I don't see a "links" section. . > . . maybe it's there and I'm bad at reading. Ah it's inline in the getting > started dialog. In my opinion, that wiki link ought to be prominently > displayed on the left, maybe even above rationale . . . .in fact, stick the > rationale on the wiki page as the preface to the "book" . . . in fact stick > the whole page on the wiki page . . . .and at that point why not just have > the wiki on clojure.org. Trust me. I'm a newby, and Tim is being > insightful in making a single, quick reference goto place for information on > the subject of clojure . . . .a most curious thing to have be confusing > given that there's a website on the topic, clojure.org. > > I'm going to memorize clojure.org. Much harder will it be to memorize, go > to clojure.org, then "getting started", then "wiki" . . .and then . . . > hm no link so search what? . .. I dunno, go back to this thread . . > .read read . . .ah yes, here it is, "By Example". So I can search on By > Example, or I can find this thread. finally I'm there. > > Not Tim's fault. And I'm glad he's doing it. Consider this feedback and > opinion. You are getting a data point on how one person thinks (or fails to > think). > > > On Tue, Jan 13, 2009 at 11:42 PM, Nick Vogel wrote: > >> It is, that article is part of the wiki linked to directly from >> clojure.org. >> >> >> On Tue, Jan 13, 2009 at 11:12 PM, e wrote: >> >>> i know that will be awesome for me. I just wish clojure.org was the >>> only place I had to go to get stuff like that. Why not wikify it all there? >>> >>> >>> On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: >>> On Jan 14, 1:12 am, Timothy Pratley wrote: > I've written small wiki article which dives right into the look and > meaning of common Clojure constructs with examples. Personally I find > I learn best by examples and when starting out they were hard to find, > whereas formal descriptions were there but rather cryptic when you > don't understand the context. My intention is to provide an initial > understanding of how programs look, what they mean, and what can be > accomplished because of their features... from which someone would > then move to one of the more complete articles and references. > > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example > > I hope someone finds it useful :) That's really good, Tim. I hope you continue with it :) AFAIC, just about every function in core, set, zip and xml needs to be documented by example. I'm just not smart enough to read the API docs of a lot of functions and understand how to use them. Some efficiency could be gained by demonstrating several functions at once, clearly labeling them. An example without much thought: (Heading) map, range (map sqr (range 1 10 2)); after defining sqr Cheers, Gavin >>> >>> >>> >> >> >> >> > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
actually I think I've seen that page before. I guess I new the way to get there once. On Wed, Jan 14, 2009 at 12:35 AM, e wrote: > . . . that person being me if it wasn't clear :) > > > On Wed, Jan 14, 2009 at 12:35 AM, e wrote: > >> define "directly" I clicked on clojure.org. I don't see the link. I >> stared at the page for a good 30 seconds. I don't see a "links" section. . >> . . maybe it's there and I'm bad at reading. Ah it's inline in the getting >> started dialog. In my opinion, that wiki link ought to be prominently >> displayed on the left, maybe even above rationale . . . .in fact, stick the >> rationale on the wiki page as the preface to the "book" . . . in fact stick >> the whole page on the wiki page . . . .and at that point why not just have >> the wiki on clojure.org. Trust me. I'm a newby, and Tim is being >> insightful in making a single, quick reference goto place for information on >> the subject of clojure . . . .a most curious thing to have be confusing >> given that there's a website on the topic, clojure.org. >> >> I'm going to memorize clojure.org. Much harder will it be to memorize, >> go to clojure.org, then "getting started", then "wiki" . . .and then . . >> . hm no link so search what? . .. I dunno, go back to this thread . . >> .read read . . .ah yes, here it is, "By Example". So I can search on By >> Example, or I can find this thread. finally I'm there. >> >> Not Tim's fault. And I'm glad he's doing it. Consider this feedback and >> opinion. You are getting a data point on how one person thinks (or fails to >> think). >> >> >> On Tue, Jan 13, 2009 at 11:42 PM, Nick Vogel wrote: >> >>> It is, that article is part of the wiki linked to directly from >>> clojure.org. >>> >>> >>> On Tue, Jan 13, 2009 at 11:12 PM, e wrote: >>> i know that will be awesome for me. I just wish clojure.org was the only place I had to go to get stuff like that. Why not wikify it all there? On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: > > On Jan 14, 1:12 am, Timothy Pratley wrote: > > I've written small wiki article which dives right into the look and > > meaning of common Clojure constructs with examples. Personally I find > > I learn best by examples and when starting out they were hard to > find, > > whereas formal descriptions were there but rather cryptic when you > > don't understand the context. My intention is to provide an initial > > understanding of how programs look, what they mean, and what can be > > accomplished because of their features... from which someone would > > then move to one of the more complete articles and references. > > > > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example > > > > I hope someone finds it useful :) > > That's really good, Tim. I hope you continue with it :) AFAIC, just > about every function in core, set, zip and xml needs to be documented > by example. I'm just not smart enough to read the API docs of a lot > of functions and understand how to use them. > > Some efficiency could be gained by demonstrating several functions at > once, clearly labeling them. An example without much thought: > > (Heading) map, range > >(map sqr (range 1 10 2)); after defining sqr > > Cheers, > Gavin > > >>> >>> >>> >>> >> > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: when performance matters
Perhaps this thread is dead, but have you looked at CUDA? A modern GPU has around 100 times the FPU firepower compared to a modern core duo. Whether you can structure your algorithm to suite the hardware is another question and I could help you with that. CUDA isn't as strong on integer but the multiplier is still damn large. NVIDIA also sells specialized boxes (the Tegra line) specially made for high-speed computing or supercomputer level processing power. For an easier route that still produces really great results have you tried SSE optimized assembly? If you don't like SSE, have you looked at MMX? Finally, there is a paper out recently on writing CUDA code with Haskell. You might check that out if you are interested. Any of these options should dramatically increase your available computing resources. Forget language speed; that is a stupid metric that lots of people like to waste lots of time on. Using specialized tools in the right situation will increase your speed by orders of magnitude, not factors. I would highly recommend, if something taking a couple days is costing you any money, to take a serious look at one of the four options listed above. Chris On Jan 13, 3:17 pm, Isaac Gouy wrote: > On Jan 13, 4:41 am, "Eric Lavigne" wrote: > > > > > There's also the (in)famous language benchmark > > > > site:http://shootout.alioth.debian.org/ > > > > This is primarily what I was going on. I realize no > > > benchmarking approach is going to be perfect, but > > > this attempt doesn't seem too bad. Is there any > > > reason to be particularly sceptical about results > > > found here? > > > The programs are written by volunteers, so the languages which have people > > that care about the results (and spend more time writing optimized code for > > their language of choice) get a big boost in score. > > It's easy to see which languages have suffered from relative neglect - > they're the ones where most of the programs were written by me and > still haven't been re-written by anyone else :-) > > C# Mono, Mozart/Oz, PHP, Scala > > otoh Scheme programs by Matthew Flatt, Haskell programs by Don > Stewart, Clean programs by John van Groningen, etc - wow! > > > Results are also > > affected by whether relevant libraries (often highly optimized for speed and > > memory) are included in the language's standard library, as third party > > libraries can't be used in shootout submissions. > > Except when they can - pcre, libgmp > > > Also, for many shootout > > problems, the answer can be determined at compile-time, so you are > > potentially testing an aspect of compilation optimization that is not so > > relevant for practical programming problems. > > > I don't know of a better set of benchmark results to look at - I use the > > shootout results myself - but I would take them with a grain of salt. > > In the words of Simon Peyton-Jones - "flawed, but available" > > http://www.haskell.org/pipermail/haskell-cafe/2008-December/052589.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: By Example - another Clojure introduction wiki page
It's in the upper right hand corner of the main page. The stuff on the left seems to be about the language itself, while the links in the upper right reference the various external sources. I'm the kind of person who explores every nook and cranny of a webpage though so I can't speak for how easily the human eye is drawn there. As for the wiki itself, I agree that it's not entirely clear right now, but if you look at the pending revisions for the main wiki page, Tim already submitted a revision with a link to his article included, it's just awaiting approval. On Wed, Jan 14, 2009 at 12:43 AM, e wrote: > actually I think I've seen that page before. I guess I new the way to get > there once. > > > On Wed, Jan 14, 2009 at 12:35 AM, e wrote: > >> . . . that person being me if it wasn't clear :) >> >> >> On Wed, Jan 14, 2009 at 12:35 AM, e wrote: >> >>> define "directly" I clicked on clojure.org. I don't see the link. I >>> stared at the page for a good 30 seconds. I don't see a "links" section. . >>> . . maybe it's there and I'm bad at reading. Ah it's inline in the getting >>> started dialog. In my opinion, that wiki link ought to be prominently >>> displayed on the left, maybe even above rationale . . . .in fact, stick the >>> rationale on the wiki page as the preface to the "book" . . . in fact stick >>> the whole page on the wiki page . . . .and at that point why not just have >>> the wiki on clojure.org. Trust me. I'm a newby, and Tim is being >>> insightful in making a single, quick reference goto place for information on >>> the subject of clojure . . . .a most curious thing to have be confusing >>> given that there's a website on the topic, clojure.org. >>> >>> I'm going to memorize clojure.org. Much harder will it be to memorize, >>> go to clojure.org, then "getting started", then "wiki" . . .and then . . >>> . hm no link so search what? . .. I dunno, go back to this thread . . >>> .read read . . .ah yes, here it is, "By Example". So I can search on By >>> Example, or I can find this thread. finally I'm there. >>> >>> Not Tim's fault. And I'm glad he's doing it. Consider this feedback and >>> opinion. You are getting a data point on how one person thinks (or fails to >>> think). >>> >>> >>> On Tue, Jan 13, 2009 at 11:42 PM, Nick Vogel wrote: >>> It is, that article is part of the wiki linked to directly from clojure.org. On Tue, Jan 13, 2009 at 11:12 PM, e wrote: > i know that will be awesome for me. I just wish clojure.org was the > only place I had to go to get stuff like that. Why not wikify it all > there? > > > On Tue, Jan 13, 2009 at 9:12 PM, GS wrote: > >> >> On Jan 14, 1:12 am, Timothy Pratley wrote: >> > I've written small wiki article which dives right into the look and >> > meaning of common Clojure constructs with examples. Personally I >> find >> > I learn best by examples and when starting out they were hard to >> find, >> > whereas formal descriptions were there but rather cryptic when you >> > don't understand the context. My intention is to provide an initial >> > understanding of how programs look, what they mean, and what can be >> > accomplished because of their features... from which someone would >> > then move to one of the more complete articles and references. >> > >> > http://en.wikibooks.org/wiki/Clojure_Programming/By_Example >> > >> > I hope someone finds it useful :) >> >> That's really good, Tim. I hope you continue with it :) AFAIC, just >> about every function in core, set, zip and xml needs to be documented >> by example. I'm just not smart enough to read the API docs of a lot >> of functions and understand how to use them. >> >> Some efficiency could be gained by demonstrating several functions at >> once, clearly labeling them. An example without much thought: >> >> (Heading) map, range >> >>(map sqr (range 1 10 2)); after defining sqr >> >> Cheers, >> Gavin >> >> > > > >>> >> > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---