Re: leiningen powershell script
On 15 Lut, 07:42, Brian Wolf brw...@gmail.com wrote: Hi, I am trying to run (http://bit.ly/82zo95http://bit.ly/82zo95 ) powershell script for leiningen install under windows, but it says it can't find file, which file it doesn't say. I was wondering what dependencies leiningen has? Do I need maven pre- installed (I don't see anything mentioned on the website) I don't know this powershell script, but you can use this batch file: http://github.com/technomancy/leiningen/blob/master/bin/lein.bat There is no self-install functionality in this script so far, but you can download needed jars easily: 1. leiningen-1.0.1-standalone.jar from http://repo.technomancy.us/ 2. clojure.jar from http://build.clojure.org/releases/org/clojure/clojure/1.1.0/ You need only these two jars in order to run Leiningen. After downloading these jars you need to copy them on paths pointed by %CLOJURE_JAR% and %LEIN_JAR% variables respectively. HTH, Rob -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: deftype comment
On 14.02.2010, at 22:48, Mark Engelberg wrote: Actually, the more I think about it, the more I feel like deftype's specify clojure.lang.IPersistentMap as an interface with no implementation, and you'll get a default implementation seems like a weird exception, I agree. The current deftype is meant to be both the primitive construct for implementing data types, and a high-performance substitute for defstruct. It would be conceptually cleaner to separate these two roles. Has their been any community brainstorming about what the syntax could look like for a general mechanism to specify within a deftype default implementations or default partial implementations of various interfaces? I don't remember. The issue of default implementations comes up now and then, but only in the form of the question is it possible?. In my own applications, I have only used deftype as a primitive construct, not as a substitute for defstruct. The special status of IPersistentMap thus never bothered me. However, I do see other cases where default implementations would be useful to have. And then IPersistentMap could become just one of them. Konrad. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
thanks) -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
oh wait...I take a look on binding and with-binding* realesation. http://github.com/richhickey/clojure/blob/f4c58e3500b3668a0941ca21f9aa4f444de2c652/src/clj/clojure/core.clj#L1251 Why with-binding* function wasn't write like this: (defn with-bindings* [bindings f args] (assert-args binding (vector? bindings) a vector for its binding (even? (count bindings)) an even number of forms in binding vector) (let [var-ize (fn [var-vals] (loop [ret [] vvs (seq var-vals)] (if vvs (recur (conj (conj ret `(var ~(first vvs))) (second vvs)) (next (next vvs))) (seq ret] (push-thread-bindings (hash-map ~@(var-ize bindings))) (try (apply f args) (finally (pop-thread-bindings -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
On Feb 15, 12:03 pm, Аркадий Рост arkr...@gmail.com wrote: oh wait...I take a look on binding and with-binding* realesation.http://github.com/richhickey/clojure/blob/f4c58e3500b3668a0941ca21f9a... Why with-binding* function wasn't write like this: (defn with-bindings* [bindings f args] (assert-args binding (vector? bindings) a vector for its binding (even? (count bindings)) an even number of forms in binding vector) (let [var-ize (fn [var-vals] (loop [ret [] vvs (seq var-vals)] (if vvs (recur (conj (conj ret `(var ~(first vvs))) (second vvs)) (next (next vvs))) (seq ret] (push-thread-bindings (hash-map ~@(var-ize bindings))) (try (apply f args) (finally (pop-thread-bindings That function is very confused. You're trying to use a splice outside of a syntax-quote which will not work. Even if you called simply (var- ize bindings), you would end up calling something like (push-thread- bindings (hash-map (quote [(var 3) something, (var blah) something]))) because the bindings vector is evaluated. The binding operator is a macro, and it can work with the symbols passed to it and transform the input to code that uses the var operator, but the with-bindings* operator is a function, which means it can't use var on its parameters. If you wanted to pass symbols to with-bindings*, you would have to do it like (with-bindings* ['a 3, 'b 4]) and the functions would have to use resolve internally to transform the vector into a map of vars to bindings. As far as I can tell, binding could be implemented using with-bindings like so: (defmacro binding [bindings body] ; var-ize elided; assume it exists `(with-bindings* ~(apply hash-map (var-ize bindings)) (fn [] ~...@body))) -- Jarkko -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Toying around with REPL: java.lang.IndexOutOfBoundsException
Hi everyone, I'm fairly new to clojure but having a great time right now with this beautiful language. I've been toying around with the REPL this morning: http://paste.lisp.org/display/94972 Now the question arises, am I missing the point or is this some sort of an internal restriction? Any hints are appreciated. Kind regards Matt -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Compilation and Class Generation newbie questions
Hello everyone, I think i've not figured out yet how compile and/or namespace works. I'm trying to execute the example posted in http://clojure.org/compilation I've created a file named hello.clj and put the clojure.jar in the same directory (c:\clojure_tests). Then, i started the REPL using the command: java -cp clojure.jar clojure.main And executed (compile 'clojure.examples.hello), but i'm getting the following error: java.io.FileNotFoundException: Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath: (NO_SOURCE_FILE:0) If i execute compile with a different namespace like (compile 'hello) then i get the following error: java.io.IOException: The system cannot find the path specified (hello.clj:1) Is there any relationship between the namespace name and the file name? How compile determines which file is going to be compiled? Thanks in advance, Paulo Sergio. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
On Mon, Feb 15, 2010 at 7:25 AM, Аркадий Рост arkr...@gmail.com wrote: Hi! I was playing a bit with with-bindings* function, but I got error every time. I've tried: (def a 5) (with-bindings* {a 3} println a) ;; got java.lang.Integer cannot be cast to clojure.lang.Var (with-bindings* [{a 3}] println a) ;;got clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.IMapEntry (with-bindings* [a 3] println a) ;;got java.lang.Integer cannot be cast to clojure.lang.IMapEntry and others variants...So what's the syntaxes of this function? Someone show code example, please. Hi, Try one of the following: user= (with-bindings* {#'a 3} println a) 5 ; It seems as if args doesn't have the new bindings yet since this prints 5 nil user= (with-bindings {#'a 3} (println a)) 3 nil user= (with-bindings* {#'a 3} #(println a)) 3 nil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Compilation and Class Generation newbie questions
Hello If you declared clojure.examples.hello namespace, then you need to have file hello.clj in clojure/examples/ directory. and you need to have c:\clojure_tests in classpath, something like: java -cp clojure.jar:c:\clojure_tests clojure.main Paulo Sérgio Medeiros at Mon, 15 Feb 2010 03:13:51 -0200 wrote: PSM Hello everyone, PSM I think i've not figured out yet how compile and/or namespace works. PSM I'm trying to execute the example posted in http://clojure.org/compilation PSM I've created a file named hello.clj and put the clojure.jar in the same directory (c:\clojure_tests). PSM Then, i started the REPL using the command: java -cp clojure.jar clojure.main PSM And executed (compile 'clojure.examples.hello), but i'm getting the following error: PSM java.io.FileNotFoundException: Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath: PSM (NO_SOURCE_FILE:0) PSM If i execute compile with a different namespace like (compile 'hello) then i get the following error: PSM java.io.IOException: The system cannot find the path specified (hello.clj:1) PSM Is there any relationship between the namespace name and the file name? How compile determines which file is going to be compiled? PSM Thanks in advance, PSM Paulo Sergio. -- With best wishes, Alex Ott, MBA http://alexott.blogspot.com/ http://alexott.net http://alexott-ru.blogspot.com/ -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Compilation and Class Generation newbie questions
Hi, On Feb 15, 6:13 am, Paulo Sérgio Medeiros pase...@gmail.com wrote: I think i've not figured out yet how compile and/or namespace works. I'm trying to execute the example posted inhttp://clojure.org/compilation I've created a file named hello.clj and put the clojure.jar in the same directory (c:\clojure_tests). Then, i started the REPL using the command: java -cp clojure.jar clojure.main And executed (compile 'clojure.examples.hello), but i'm getting the following error: java.io.FileNotFoundException: Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath: (NO_SOURCE_FILE:0) If i execute compile with a different namespace like (compile 'hello) then i get the following error: java.io.IOException: The system cannot find the path specified (hello.clj:1) Is there any relationship between the namespace name and the file name? How compile determines which file is going to be compiled? From http://clojure.org/compilation: For some namespace my.domain.lib, defined in my/domain/lib.clj, in the classpath, ... So put your file in src/clojure/examples/hello.clj. Create also a directory called classes. Then invoke clojure with java -cp src;classes;clojure.jar clojure.main -r and compile the namespace as you did before. The compiled classes will end up in the classes directory. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Toying around with REPL: java.lang.IndexOutOfBoundsException
Hi, On Feb 15, 9:10 am, Matthias von Rohr matthias.vonr...@gmail.com wrote: I'm fairly new to clojure but having a great time right now with this beautiful language. I've been toying around with the REPL this morning: http://paste.lisp.org/display/94972 Now the question arises, am I missing the point or is this some sort of an internal restriction? Just a guess: nth eventually calls RT/nth which takes a primitive int. You overflow the int and get a negative number, which causes the for loop in the Sequential branch to fall through immediately because the index is smaller than 0. Hence the exception. I'm not sure whether this is entirely correct, though. I guess this is done for performance reasons. Taking the 5th item of a collection is rather unlikely, I fancy. Clojure is known to discourage such actions in other situations. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Toying around with REPL: java.lang.IndexOutOfBoundsException
nth is internally defined as the nth static method of the class clojure.lang.RT. That method takes an argument of type int as the index, whereas the huge index you supplied doesn't fit in an int and is normally a BigInteger. I guess that when you pass that to a Java method which expects an int, it gets converted with .intValue, which for your particular number produces a negative value, which is indeed out of bounds from the point of view of nth. As for a discussion of the design tradeoffs involved, I am not competent to discuss those. :-) Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
Thank you so much This is really wonderful advice...saved me months of learning. I have rewritten my code as follows: ;definition of a palindrome (defn palindrome? [s] (= s (apply str (reverse s ;list of palindromes for range of numbers (defn palindromes [start end] (def startmod (- start 1)) (filter #(palindrome? (str %)) (range (* end end) (* startmod startmod) -1))) ;yields a lazy sequence of all that are divisible by a 3 digit number and yield a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) ( 99 (unchecked-divide pal %) 1000)) (range 999 99 -1))) (defn p1 [] (def palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999 (def root1 (first (divis-by-3dig palindromic-number))) (def root2 (unchecked-divide palindromic-number root1)) (def message (str the palindromic number is palindromic-number its roots are root1 root2)) message) On Feb 14, 11:17 pm, ataggart alex.tagg...@gmail.com wrote: On Feb 14, 5:49 pm, Glen Rubin rubing...@gmail.com wrote: Thank you for the advice! Just for reference I am working on project euler question #4 (Find the largest palindrome made from the product of two 3-digit numbers.) I have a solution, but am hoping somebody can clarify some things for me: First, I define a panlindrome tester: (defn palindrome? [s] (= s (apply str (reverse s Next, I define a list of palindromes for the two 3-digit number range: (def palindromes (filter #(palindrome? (str %)) (reverse (range (* 100 100) (+ 1 (* 999 999)) My next function takes a palindromic number as an argument and returns a sequence of all 3 digit divisors with a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) (= 3 (len (str (/ pal %) (reverse (range 100 1000 This function works, but only with an integer, which means I have to use it with another filter function in order to test a collection. And then it will return the palindromic number in my collection which has two 3 digit divisors instead of the factors, which is what I am looking for. I solve this as follows in my main function: (defn e1 [] (def palindromic-number (take 1 (filter #(not (empty? (divis-by-3dig %))) palindromes))) (def root (take 1 (map divis-by-3dig palindromic-number))) root) unfortunately there is still a problem with this, in that i cannot get access to a single root, instead am returned all of the roots from applying my divis-by-3dig function to the single element in my collection palindromic-number (e1) On Feb 14, 8:52 am, Steven E. Harris s...@panix.com wrote: Glen Rubin rubing...@gmail.com writes: How do I take an element from one collection and test for no remainder (e.g. (zero? (mod x y)), when dividing by every element of the second collection, before processing the next item in the first collection? This form checks if every element of the second range is a factor of every element in the first range: , | (let [r2 (range 100 150)] | (every? | #(every? (partial (comp zero? mod) %) r2) | (range 1000 2000))) ` Note that the walk over (range 1000 2000) is the outer one, and the walk over (range 100 150) (r2) is the inner one. -- Steven E. Harris So you're scanning all possible products, then back-tracking to figure out which 3-digit factors can result in that value? Interesting, though outside the scope of the actual PE question. A few comments: - There is no len function. Use count or .length for strings. - Don't def really long sequences; instead defn a function that returns the sequence (which can then be garbage collected). Plus it sucks when pasting into the repl and it tries to realize and print the entire sequence. - Don't reverse ranges since doing so requires first generating the entire (otherwise lazy) sequence; instead make the step negative, e.g., (range 999 99 -1) - Clojure's numeric inequality functions can take more than 2 args, thus you can call ( 99 % 1000) rather than testing the length of the stringified number. - If you want integer dividing, cast to int or use unchecked-divide (I prefer the latter which avoids the intermediate Ratio): user= (/ 3 4) 3/4 user= (int (/ 3 4)) 0 user= (unchecked-divide 3 4) 0 - Per the documentation of empty?, use the idiom (seq x) rather than (not (empty? x)) - See if you can avoid banging everything to/from strings. Maybe turn an int to/from some collection of digits. - (take 1 foo) returns you a one-element (or empty) sequence. (first foo) returns the first value (or nil). Use the latter when you really just want the value. This, by the way, is why your answer to (e1) is ((913 993)). -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to
Re: processing two collections
On 15 Feb 2010, at 13:50, Glen Rubin wrote: Thank you so much This is really wonderful advice...saved me months of learning. I have rewritten my code as follows: You'll want to use let in place of all of those def declarations. -Steve -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
PersistentTreeMap, seqFrom, subseq and range queries
Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? George -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: PersistentTreeMap, seqFrom, subseq and range queries
with keys that range between 30 and 11 should read with keys that range between 30 and 100 On Mon, Feb 15, 2010 at 10:45 PM, George . clojuri...@gmail.com wrote: Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? George -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
Hi, On Feb 15, 2:50 pm, Glen Rubin rubing...@gmail.com wrote: ;definition of a palindrome (defn palindrome? [s] (= s (apply str (reverse s You might want to call vec on the string and then rseq instead of reverse. reverse walks the string twice, while rseq just walks the string once. The vector will use the underlying string as storage. (defn palindrome? [s] (= s (rseq (vec s ;list of palindromes for range of numbers (defn palindromes [start end] (def startmod (- start 1)) ^^^ No. No. No. Use (let [startmod (dec start)] )! def is toplevel only! (filter #(palindrome? (str %)) (range (* end end) (* startmod startmod) -1))) ;yields a lazy sequence of all that are divisible by a 3 digit number and yield a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) ( 99 (unchecked-divide pal %) 1000)) (range 999 99 -1))) (defn p1 [] (def palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999 (def root1 (first (divis-by-3dig palindromic-number))) (def root2 (unchecked-divide palindromic-number root1)) (def message (str the palindromic number is palindromic-number its roots are root1 root2)) message) Again: no nested def's, defn's, or anything else starting with def. Use let! def is always global so this will not do, what you think it does (ie. define a local). (defn p1 [] (let [palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999))) root1 (first (divis-by-3dig palindromic-number)) root2 (unchecked-divide palindromic-number root1)] (str the palindromic number is palindromic-number its roots are root1 root2))) Hope this helps. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
On 15 Feb 2010, at 13:58, Steve Purcell wrote: On 15 Feb 2010, at 13:50, Glen Rubin wrote: Thank you so much This is really wonderful advice...saved me months of learning. I have rewritten my code as follows: You'll want to use let in place of all of those def declarations. e.g. your last function would look like this: (defn p1 [] (let [palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999))) root1 (first (divis-by-3dig palindromic-number)) root2 (unchecked-divide palindromic-number root1)] (str the palindromic number is palindromic-number its roots are root1 root2))) -Steve -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Toying around with REPL: java.lang.IndexOutOfBoundsException
Yep, you're right, I just debugged it and its an int overflow (nth gets called with a parameter int n=-279969792) Matt -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: contrib.sql with postgresql is really a problem
Hi Richard, thanks for clarification. However, http://www.google.com/search?q=clojure.contrib.sql+timestamp+postgresql now returns at least one relevant result (position #1) :). I created the promised blog post and google seems to be quick. Thanks, Andreas Schipplock. On Sun, Feb 14, 2010 at 8:27 PM, Richard Newman holyg...@gmail.com wrote: My first problem was to save a timestamp value. I defined a field in pgsql as timestamp and wasn't able to store a simple timestamp value because I got type mismatch errors and it also displayed the statement which I could copy and execute successfully in pgadmin which confused me a lot. I seem to recall being able to store a java.sql.Timestamp in my PG DB. E.g., I have a now function: (java.sql.Timestamp. (.getTime (java.util.Date.))) so I could successfully save timestamps to my db by casting my strings to a java timestamp (timestamp (params :foobar)). This is really nothing to do with c.c.sql: JDBC is in charge of converting Java objects into native DB datatypes. It simply doesn't know how to cast a String to a Timestamp. However, what I complain about is that in no fracking example any typecast was used and I assumed this is normal as supposed to other interfaces/libs I've used in the past. I've never used typecasts in this way. Using the correct Java class has always been my solution. Possibly you're experiencing a disconnect when you're investigating issues. In every case where some Java object is being interpolated into a query, it's JDBC that's doing the work. Thus, you should be searching for http://www.google.com/search?q=jdbc+timestamp+postgresql (981,000 results) not http://www.google.com/search?q=clojure.contrib.sql+timestamp+postgresql (1,030 irrelevant results) c.c.sql is a handy wrapper around JDBC. HTH, -R -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- M.f.G. Andreas Schipplock -- http://www.schipplock.org __)\_ (\_.-'a`-. (/~~(/~^^` -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: deftype comment
On Mon, Feb 15, 2010 at 3:56 AM, Konrad Hinsen konrad.hin...@fastmail.net wrote: On 14.02.2010, at 22:48, Mark Engelberg wrote: Actually, the more I think about it, the more I feel like deftype's specify clojure.lang.IPersistentMap as an interface with no implementation, and you'll get a default implementation seems like a weird exception, I agree. The current deftype is meant to be both the primitive construct for implementing data types, and a high-performance substitute for defstruct. It would be conceptually cleaner to separate these two roles. Has their been any community brainstorming about what the syntax could look like for a general mechanism to specify within a deftype default implementations or default partial implementations of various interfaces? I don't remember. The issue of default implementations comes up now and then, but only in the form of the question is it possible?. In my own applications, I have only used deftype as a primitive construct, not as a substitute for defstruct. The special status of IPersistentMap thus never bothered me. However, I do see other cases where default implementations would be useful to have. And then IPersistentMap could become just one of them. I just wanted to chime in and say I agree - I am not totally happy with how getting the map/default implementation works, and think that possibly the two roles deftype/defstruct-replacement should be more distinct. So, I'm working on it. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: PersistentTreeMap, seqFrom, subseq and range queries
If you are running Java 6 you could always use java.util.NavigatibleMap/Set. However, this is a workaround, and it would be great to see Clojure support these log(N) operations directly. On Feb 15, 8:45 am, George . clojuri...@gmail.com wrote: Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? George -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: PersistentTreeMap, seqFrom, subseq and range queries
Hey, Sean -- that's the alternative that I've been using for performance reasons. Unfortunately, I can't put it in a ref (well, I suppose I could but the behavior is unspecified and definitely not good). It'd be useful to have both the concurrency benefits of the immutable/persistent PersistentTreeMap and the performance of fully logarithmic range queries. On Mon, Feb 15, 2010 at 11:35 PM, Sean Devlin francoisdev...@gmail.comwrote: If you are running Java 6 you could always use java.util.NavigatibleMap/Set. However, this is a workaround, and it would be great to see Clojure support these log(N) operations directly. On Feb 15, 8:45 am, George . clojuri...@gmail.com wrote: Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? George -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: PersistentTreeMap, seqFrom, subseq and range queries
On Mon, Feb 15, 2010 at 8:45 AM, George . clojuri...@gmail.com wrote: Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? I'm confused. Do you want something other than a seq of values in range as a result? Because if there are K things in range, there is no way to consume them in complexity less than O(K). That cost won't be incurred until you consume them, due to take-while being lazy. OTOH, if what you want is a subset or submap, or, from them, a constant-time count, well, that's a different function altogether. I'm not opposed to subset or submap proposals. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: PersistentTreeMap, seqFrom, subseq and range queries
Sorry, I was mistaken. On Tue, Feb 16, 2010 at 12:23 AM, Rich Hickey richhic...@gmail.com wrote: On Mon, Feb 15, 2010 at 8:45 AM, George . clojuri...@gmail.com wrote: Currently, if you want to perform a range query on a sorted-seq (AKA PersistentTreeMap), you are are advised to use the subseq wrapper for seqFrom. For instance, let's say your keys are dollar values you could do (subseq my-map 30) to get all entries with keys greater than 30 or (subseq my-map 30 100) to get all entries with keys that range between 30 and 11. The former case is O(logN) as it is entirely delegated to the logarithmic seqFrom method. However, the latter example has worst case O(N) behavior since subseq is doing a take-while after .seqFrom. Is there any plan to support upper bounds directly within seqFrom in order to make the worst-case behavior logarithmic all around? If not, would such a patch even be considered or is the simplicity of implementation an overriding factor? I'm confused. Do you want something other than a seq of values in range as a result? Because if there are K things in range, there is no way to consume them in complexity less than O(K). That cost won't be incurred until you consume them, due to take-while being lazy. OTOH, if what you want is a subset or submap, or, from them, a constant-time count, well, that's a different function altogether. I'm not opposed to subset or submap proposals. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
Yeah.. That function is very confused. I didn't check it, sorry. I don't understand the reason to make the argument binding-map: for example, using binding macro: (binding [a 5] ...do something...) ;;using vector to contain bindings. but using with-bindings*: (with-bindings* {#'a 5} f args) ;;hash-map is ised to contain bindings what was the reason for such implementation? (with-bindings* [a 5] f args) ;; it seems to be more common syntaxes -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
When to use loop recur / seq functions?
Hello, I'm new to clojure and have a question concerning recur and lazy seqs. I implemented a function to calculate the perimeter of a polygon. As I'm used to Java and imperative programming, my first approach was to use loop/recur ('euclidean-distance' is a helper-function that calculates the distance between two points): (defn polygon-perimeter Calculates the perimeter of a polygon. For this purpose it adds up the distances between all points. [ pn] (loop [p 0.0, points (conj (vec pn) (first pn))] (if ( (count points) 1) (recur (+ p (euclidean-distance (first points) (second points))) (rest points)) p))) I found that this doesn't look very functional, so I tried a different approach with use of the sequence library; (defn better-perimeter Calculates the perimeter of a polygon. For this purpose it adds up the distances between all points. [ pn] (reduce + (map #(euclidean-distance (first %) (second %)) (partition 2 1 (conj (vec pn) (first pn)) This looks very nice. But then I compared the performance of both implementations: (dotimes [_ 5] (time (polygon-perimeter [0 1] [1 0] [3 2] [2 3] [0 2]))) Elapsed time: 1.129296 msecs Elapsed time: 0.156261 msecs Elapsed time: 0.153229 msecs Elapsed time: 0.153613 msecs Elapsed time: 0.152975 msecs (dotimes [_ 5] (time (better-perimeter [0 1] [1 0] [3 2] [2 3] [0 2]))) Elapsed time: 2.809387 msecs Elapsed time: 0.221396 msecs Elapsed time: 0.214933 msecs Elapsed time: 0.214048 msecs Elapsed time: 0.217317 msecs As you can see, the loop/recur version is a bit faster (not significantly but a little bit). This leads me to a general question: What would be the better implementation? When should I use loop/recur and when seq library functions? Stuart Halloway writes in his book Use recur when you are producing scalar values or small, fixed sequences and also Know the sequences library. You can often write code without using recur or the lazy apis at all. Pehaps you have some more rules of the thumb? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Compilation and Class Generation newbie questions
Hi! Thanks, i think i haven't executed java from command line for a while and forgot some things. ;-) On Mon, Feb 15, 2010 at 11:32 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Feb 15, 6:13 am, Paulo Sérgio Medeiros pase...@gmail.com wrote: I think i've not figured out yet how compile and/or namespace works. I'm trying to execute the example posted inhttp:// clojure.org/compilation I've created a file named hello.clj and put the clojure.jar in the same directory (c:\clojure_tests). Then, i started the REPL using the command: java -cp clojure.jar clojure.main And executed (compile 'clojure.examples.hello), but i'm getting the following error: java.io.FileNotFoundException: Could not locate clojure/examples/hello__init.class or clojure/examples/hello.clj on classpath: (NO_SOURCE_FILE:0) If i execute compile with a different namespace like (compile 'hello) then i get the following error: java.io.IOException: The system cannot find the path specified (hello.clj:1) Is there any relationship between the namespace name and the file name? How compile determines which file is going to be compiled? From http://clojure.org/compilation: For some namespace my.domain.lib, defined in my/domain/lib.clj, in the classpath, ... So put your file in src/clojure/examples/hello.clj. Create also a directory called classes. Then invoke clojure with java -cp src;classes;clojure.jar clojure.main -r and compile the namespace as you did before. The compiled classes will end up in the classes directory. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
newbie question: Please help me stop creating constructors
I am writing a calculator to figure out if I should sell or rent my home using Clojure. This is my first Clojure program so I'm about as wet behind the ears as it gets. So far everything is actually going really well (reminds me of the fun I had with Scheme in college) but for one thing. My calculator needs 30+ arguments from the user in order to run. Furthermore I have a bunch of secondary values that are derived from the arguments the user submits. So imagine the user submits a value A. I will have a value B whose definition will be something like (+ 1 A) (yes, more complex in reality, but you get the idea). If I were back in Java or C# I would define a class, submit A (and it's 29+ friends) in the constructor and then create a property on the class B. In Clojure I have taken a different approach. I first create (def *A* 3) where 3 is a completely bogus value I just made up. Then at run time I use bindings to re-bind A to the actual value the user passed in. But my problem is, what to do about B? I thought of doing something like (def *B* 3) and then in the binding passing in a function like (defn B-Gen [] (+ *A* 1)) to create a new binding to B but I quickly realized this would be a bug inducing nightmare. If I forget to include one of the derived values in the binding or put them in the wrong order then I would get the wrong value. So what I currently do is: (def *A* 3) ; A bogus value that will later be rebound (defn B [] (+ *A* 3)) The good news is, that this works and doesn't require any book keeping. The bad news is that it's ugly. If I want to do something trivial like divide B by 2 I have to call B as a function(/ (B) 2) instead of the more natural (/ B 2). And of course this approach is pretty unfortunate from a performance perspective as I'm constantly having to recalculate what are effectively static values. Yes, I could use memoization but many of these values are pretty trivial (usually just algebra equations) and I suspect the overhead of memoization exceeds the perf improvement. But in any case the whole approach of having to take what really are static values and turn them into functions feels really hacky. So my guess is that I'm thinking about this problem the wrong way. I'm stuck in my old imperative/OO constructor world. What's the right way to think about primary values that will be rebound (once) that then have dependent values that need to be recalculated when that rebinding happens? Thanks, Yaron -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: leiningen powershell script
Rob Wolfe wrote: On 15 Lut, 07:42, Brian Wolf brw...@gmail.com wrote: Hi, I am trying to run(http://bit.ly/82zo95http://bit.ly/82zo95 ) powershell script for leiningen install under windows, but it says it can't find file, which file it doesn't say. I was wondering what dependencies leiningen has? Do I need maven pre- installed (I don't see anything mentioned on the website) I don't know this powershell script, but you can use this batch file: http://github.com/technomancy/leiningen/blob/master/bin/lein.bat There is no self-install functionality in this script so far, but you can download needed jars easily: 1. leiningen-1.0.1-standalone.jar from http://repo.technomancy.us/ 2. clojure.jar from http://build.clojure.org/releases/org/clojure/clojure/1.1.0/ You need only these two jars in order to run Leiningen. After downloading these jars you need to copy them on paths pointed by %CLOJURE_JAR% and %LEIN_JAR% variables respectively. HTH, Rob Well, I set the env variables and ran the script, got an error. These are my env variables: CLASSPATH=c:\clojure;.;c:\clojure\clojure-1.0.0.jar;c:\clojure\clojure.jar CLOJURE_HOME=c:\clojure CLOJURE_JAR=c:\clojure\clojure.jar LEIN_JAR=C:\clojure\lein.d\leiningen-0.5.0.jar LEIN_VERSION=1.1.0-SNAPSHOT JAVA_HOME=C:\jdk1.6.0_16 - directory contents: C:\clojure clojure.jar C:\clojure\lein.d leiningen-0.5.0.jar == the error: C:\clojurelein.bat Exception in thread main java.lang.ExceptionInInitializerError at clojure.lang.Namespace.init(Namespace.java:32) at clojure.lang.Namespace.findOrCreate(Namespace.java:117) at clojure.main.clinit(main.java:21) Caused by: java.lang.RuntimeException: java.lang.NullPointerException at clojure.lang.RT.clinit(RT.java:291) ... 3 more Caused by: java.lang.NullPointerException at clojure.lang.RT.load(RT.java:373) at clojure.lang.RT.load(RT.java:367) at clojure.lang.RT.doInit(RT.java:402) at clojure.lang.RT.clinit(RT.java:288) ... 3 more Could not find the main class: clojure.main. Program will exit. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: clojure-dev: #55: clojure.contrib.sql expects *err* to be a PrintWriter Ticket updated - Resolution?
I had proposed that c.c.sql use c.c.logging, and Steve was ok with that, but I held off after all the back and forth about logging itself. I would be just as happy to see no logging no wrapping/throwing at this level. If you make a patch that does this (and nag me a little :-) ) I will make sure it gets discussed on dev and acted on. Stu 2) c.c.sql shouldn't assume that we want anything printed at all?! Just throw the SQLException. Printing to *err* is acceptable IMO. This is the common should my library write log messages, and if so how? problem. I'd rather have it print to *err* than use Java Logging. Why log anything at all? The relevant information is (or can be) stored in the exception. I don't want to see clojure contrib embrace the catch/log/re-throw idiom. I couldn't find any other code in contrib that follows this approach. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: leiningen powershell script
On 15 Lut, 20:50, Brian Wolf brw...@gmail.com wrote: Rob Wolfe wrote: On 15 Lut, 07:42, Brian Wolf brw...@gmail.com wrote: Hi, I am trying to run (http://bit.ly/82zo95http://bit.ly/82zo95 ) powershell script for leiningen install under windows, but it says it can't find file, which file it doesn't say. I was wondering what dependencies leiningen has? Do I need maven pre- installed (I don't see anything mentioned on the website) I don't know this powershell script, but you can use this batch file: http://github.com/technomancy/leiningen/blob/master/bin/lein.bat There is no self-install functionality in this script so far, but you can download needed jars easily: 1. leiningen-1.0.1-standalone.jar fromhttp://repo.technomancy.us/ 2. clojure.jar fromhttp://build.clojure.org/releases/org/clojure/clojure/1.1.0/ You need only these two jars in order to run Leiningen. After downloading these jars you need to copy them on paths pointed by %CLOJURE_JAR% and %LEIN_JAR% variables respectively. HTH, Rob Well, I set the env variables and ran the script, got an error. These are my env variables: CLASSPATH=c:\clojure;.;c:\clojure\clojure-1.0.0.jar;c:\clojure\clojure.jar CLOJURE_HOME=c:\clojure CLOJURE_JAR=c:\clojure\clojure.jar LEIN_JAR=C:\clojure\lein.d\leiningen-0.5.0.jar LEIN_VERSION=1.1.0-SNAPSHOT JAVA_HOME=C:\jdk1.6.0_16 You need to set only LEIN_JAR and CLOJURE_JAR CLASSPATH will be created by Leiningen. On your CLASSPATH there are two clojure jars: 1. clojure-1.0.0.jar (does it exist?) 2. clojure.jar You should use only one clojure jar, which will be pointed by CLOJURE_JAR variable. Try to use more up-to-date versions: Clojure: 1.1.0 Leinigen: 1.0.1 HTH, Rob -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: What is a form, exactly? + Are there any guarantees about the return types of quote and syntax-quote?
Hi, On Sun, Feb 14, 2010 at 08:58:56PM -0500, Garth Sheldon-Coulson wrote: (Revised version: What characterizes an expression? Is it correct to say that an expression is always something for which seq? returns true and never something for which seq? returns false?) I don't think so. {:a :b} is just an expression (which evaluates to a map) as is 5 (evaluating to 5) as is x (evaluating to whatever x is bound to) as is (inc 1) (evaluating to 2). And please consider the other questions revised as appropriate. In particular, please restrict my question about quote and syntax-quote to situations where they quote a form demarcated by parens. I would still like to know whether there is anything certain about the types returned by quote and syntax-quote when they are called on a paren-demacated form. As Clojure is based on abstractions everything relying on specific types should be questioned. Especially since in the future reify may kill that idea completely. My (certainly limited) experience with this kind of questions is: Why do you need to know? There may be perfectly valid reasons. Then I would go with seq?. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
I tried using your alternate definition for palindromes? , but an exception was thrown: java.lang.NullPointerException [Thrown class java.lang.RuntimeException] On Feb 15, 7:02 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, On Feb 15, 2:50 pm, Glen Rubin rubing...@gmail.com wrote: ;definition of a palindrome (defn palindrome? [s] (= s (apply str (reverse s You might want to call vec on the string and then rseq instead of reverse. reverse walks the string twice, while rseq just walks the string once. The vector will use the underlying string as storage. (defn palindrome? [s] (= s (rseq (vec s ;list of palindromes for range of numbers (defn palindromes [start end] (def startmod (- start 1)) ^^^ No. No. No. Use (let [startmod (dec start)] )! def is toplevel only! (filter #(palindrome? (str %)) (range (* end end) (* startmod startmod) -1))) ;yields a lazy sequence of all that are divisible by a 3 digit number and yield a 3 digit quotient (defn divis-by-3dig [pal] (filter #(if (zero? (mod pal %)) ( 99 (unchecked-divide pal %) 1000)) (range 999 99 -1))) (defn p1 [] (def palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999 (def root1 (first (divis-by-3dig palindromic-number))) (def root2 (unchecked-divide palindromic-number root1)) (def message (str the palindromic number is palindromic-number its roots are root1 root2)) message) Again: no nested def's, defn's, or anything else starting with def. Use let! def is always global so this will not do, what you think it does (ie. define a local). (defn p1 [] (let [palindromic-number (first (filter #(seq (divis-by-3dig %)) (palindromes 100 999))) root1 (first (divis-by-3dig palindromic-number)) root2 (unchecked-divide palindromic-number root1)] (str the palindromic number is palindromic-number its roots are root1 root2))) Hope this helps. Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
Hi, On Mon, Feb 15, 2010 at 01:07:15PM -0800, Glen Rubin wrote: I tried using your alternate definition for palindromes? , but an exception was thrown: java.lang.NullPointerException [Thrown class java.lang.RuntimeException] Works for me. However one has to wrap the first string into a seq. user= (= cba (rseq (vec abc))) false user= (= (seq cba) (rseq (vec abc))) true Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: leiningen powershell script
Rob Wolfe wrote: On 15 Lut, 20:50, Brian Wolf brw...@gmail.com wrote: Rob Wolfe wrote: On 15 Lut, 07:42, Brian Wolf brw...@gmail.com wrote: Hi, I am trying to run(http://bit.ly/82zo95http://bit.ly/82zo95 ) powershell script for leiningen install under windows, but it says it can't find file, which file it doesn't say. I was wondering what dependencies leiningen has? Do I need maven pre- installed (I don't see anything mentioned on the website) I don't know this powershell script, but you can use this batch file: http://github.com/technomancy/leiningen/blob/master/bin/lein.bat There is no self-install functionality in this script so far, but you can download needed jars easily: 1. leiningen-1.0.1-standalone.jar fromhttp://repo.technomancy.us/ 2. clojure.jar fromhttp://build.clojure.org/releases/org/clojure/clojure/1.1.0/ You need only these two jars in order to run Leiningen. After downloading these jars you need to copy them on paths pointed by %CLOJURE_JAR% and %LEIN_JAR% variables respectively. HTH, Rob Well, I set the env variables and ran the script, got an error. These are my env variables: CLASSPATH=c:\clojure;.;c:\clojure\clojure-1.0.0.jar;c:\clojure\clojure.jar CLOJURE_HOME=c:\clojure CLOJURE_JAR=c:\clojure\clojure.jar LEIN_JAR=C:\clojure\lein.d\leiningen-0.5.0.jar LEIN_VERSION=1.1.0-SNAPSHOT JAVA_HOME=C:\jdk1.6.0_16 You need to set only LEIN_JAR and CLOJURE_JAR CLASSPATH will be created by Leiningen. On your CLASSPATH there are two clojure jars: 1. clojure-1.0.0.jar (does it exist?) 2. clojure.jar You should use only one clojure jar, which will be pointed by CLOJURE_JAR variable. Try to use more up-to-date versions: Clojure: 1.1.0 Leinigen: 1.0.1 HTH, Rob OK, I made those suggested changes, ie Clojure: 1.1.0 Leinigen: 1.0.1 took out all clojure related env variables except: c:\clojure\clojure-1.1.0.jar C:\clojure\lein.d\leiningen-1.0.1.jar seems unable to find the project.clj in the jar file I listed leiningen-1.0.1.jar and it seems project.clj is not under leiningen: (is that where it belongs?) 258 Thu Dec 10 22:52:18 PST 2009 leiningen/version.clj 673 Thu Dec 10 22:52:18 PST 2009 project.clj C:\clojurelein.bat Exception in thread main java.io.FileNotFoundException: project.clj (The syste m cannot find the file specified) (NO_SOURCE_FILE:0) at clojure.lang.Compiler.eval(Compiler.java:4658) at clojure.core$eval__5236.invoke(core.clj:2017) at clojure.main$eval_opt__7411.invoke(main.clj:227) at clojure.main$initialize__7418.invoke(main.clj:246) at clojure.main$null_opt__7446.invoke(main.clj:271) at clojure.main$main__7466.doInvoke(main.clj:346) at clojure.lang.RestFn.invoke(RestFn.java:426) at clojure.lang.Var.invoke(Var.java:363) at clojure.lang.AFn.applyToHelper(AFn.java:175) at clojure.lang.Var.applyTo(Var.java:476) at clojure.main.main(main.java:37) Caused by: java.io.FileNotFoundException: project.clj (The system cannot find th e file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.init(FileInputStream.java:106) at java.io.FileInputStream.init(FileInputStream.java:66) at clojure.lang.Compiler.loadFile(Compiler.java:4936) at clojure.lang.RT$4.invoke(RT.java:277) at leiningen.core$read_project__31.invoke(core.clj:39) at leiningen.core$read_project__31.invoke(core.clj:41) at leiningen.core$_main__43.doInvoke(core.clj:67) at clojure.lang.RestFn.invoke(RestFn.java:413) at user$eval__52.invoke(NO_SOURCE_FILE:1) at clojure.lang.Compiler.eval(Compiler.java:4642) ... 10 more -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie question: Please help me stop creating constructors
Let's start with what you've got. Could you post some of your code on github, or something similar? That would make it easier to help you along. Sean On Feb 15, 12:24 pm, Yaron ygol...@gmail.com wrote: I am writing a calculator to figure out if I should sell or rent my home using Clojure. This is my first Clojure program so I'm about as wet behind the ears as it gets. So far everything is actually going really well (reminds me of the fun I had with Scheme in college) but for one thing. My calculator needs 30+ arguments from the user in order to run. Furthermore I have a bunch of secondary values that are derived from the arguments the user submits. So imagine the user submits a value A. I will have a value B whose definition will be something like (+ 1 A) (yes, more complex in reality, but you get the idea). If I were back in Java or C# I would define a class, submit A (and it's 29+ friends) in the constructor and then create a property on the class B. In Clojure I have taken a different approach. I first create (def *A* 3) where 3 is a completely bogus value I just made up. Then at run time I use bindings to re-bind A to the actual value the user passed in. But my problem is, what to do about B? I thought of doing something like (def *B* 3) and then in the binding passing in a function like (defn B-Gen [] (+ *A* 1)) to create a new binding to B but I quickly realized this would be a bug inducing nightmare. If I forget to include one of the derived values in the binding or put them in the wrong order then I would get the wrong value. So what I currently do is: (def *A* 3) ; A bogus value that will later be rebound (defn B [] (+ *A* 3)) The good news is, that this works and doesn't require any book keeping. The bad news is that it's ugly. If I want to do something trivial like divide B by 2 I have to call B as a function(/ (B) 2) instead of the more natural (/ B 2). And of course this approach is pretty unfortunate from a performance perspective as I'm constantly having to recalculate what are effectively static values. Yes, I could use memoization but many of these values are pretty trivial (usually just algebra equations) and I suspect the overhead of memoization exceeds the perf improvement. But in any case the whole approach of having to take what really are static values and turn them into functions feels really hacky. So my guess is that I'm thinking about this problem the wrong way. I'm stuck in my old imperative/OO constructor world. What's the right way to think about primary values that will be rebound (once) that then have dependent values that need to be recalculated when that rebinding happens? Thanks, Yaron -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: newbie question: Please help me stop creating constructors
So imagine the user submits a value A. I will have a value B whose definition will be something like (+ 1 A) (yes, more complex in reality, but you get the idea). In Java, everything's an object, so you go about this by defining some class. All of its private members, its constructors, and its accessors are there to support one thing: should I sell or rent my home? That is, rather than saying something like: should-i-sell given that: current-home-price = 100,000 current-interest-rate = 5.2% ... you say HomeCalculator c = new HomeCalculator(10, 5.2, ...); boolean shouldSell = c.shouldSell(); and the logic is tied up in the shouldSell method definition. When someone calls .setA(...), you have to recompute B, or you have to make sure that B is dynamically computed in .getB(). That's not how you do things in a functional programming language. You don't define global variables B and A. Define functions that compute things; thread them together; and then push your values in the top. Start from the bottom up and the top down together; build a tree of functions that compute what you want. For example, you might think ah, I need to figure out my monthly payment on my mortgage. That's a function of the initial principal, the term, and the rate: (defn monthly-payment [principal term-in-months interest-rate] ...) Then you want to figure out how much more or less you'll pay, assuming a growth in rents of a certain percentage, over some number of months spent living in the house. Let's start by computing a sequence of rents, increasing over time: (defn monthly-rent [starting-value monthly-increase] (lazy-seq starting-value (monthly-rent (* (+ 1 monthly-percentage-increase) starting- value) monthly-increase))) then we want to weigh these against each other: (defn rent-cost-over-time [starting-value monthly-increase months] (reduce + (take months (monthly-rent starting-value monthly- increase))) (defn mortgage-cost-over-time [principal term-in-months interest-rate months] (...)) You get the idea: you're building a library of *pure* functions, each of which does one thing to some inputs, and might rely on the others. Now you're ready to phrase your question as a function: (defn should-i-sell [initial-mortgage-principal monthly-interest-rate months-already-paid-into-house ...] ) If you want to use keywords to denote named arguments, you can do that: (defn should-i-sell [ args] (let [{:keys [initial-mortgage-principal ...]} (apply hash-map args)] ...) No bindings. No global definitions. No redefinition. No state. User input comes in to your function and is passed through other functions. Eventually you get a value. If the user input changes, re-run the function. Dataflow programming is overkill for what you're doing. You don't have primary values and dependent values: you have function inputs, and functions that compute values from inputs. Hope that helps... -R -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)
Hello. I've been trying to get emacs/slime running for a while on ubuntu 9.10. I used clojure box for Windows and that was excellent but this is not running very well for me. I compiled clojure and clojure-contrib.jar by cloning the repositories, checking out tag 1.1.0 and building them with ant. I then followed these instructions to a t (http://riddell.us/tutorial/ slime_swank/slime_swank.html). I've downloaded swank-clojure/slime/ clojure-mode as the instructions but used the latest code (I did not checkout a different tag). I have also tried emacs and emacs-snapshot, both installed via apt-get. All seems to be well when I M-x slime, but if I enter (+ 1 2) it just hangs. If I switch to the *inferior-lisp* buffer and type this expression it returns 3 as expected. The only other thing that seems strange is my *inferior-lisp* has this in it: (require 'swank.swank) (swank.swank/ignore-protocol-version 2010-02-14) (swank.swank/start-server /tmp/slime.26582 :encoding iso-latin-1- unix) Clojure 1.1.0 user= WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead nil user= user= 2010-02-14 user= user= Connection opened on local port 43926 #ServerSocket ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=43926] user= user= WARNING: reader macro ^ is deprecated; use meta instead WARNING: reader macro ^ is deprecated; use meta instead -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: When to use loop recur / seq functions?
Here's your second implementation cleaned up a little: (defn perimeter [ pn] (apply + (map euclidean-distance pn (rest pn My own personal opinion is: The second approach is (1) faster to write (2) easier to understand (3) less error-prone So that's the one that I prefer. IF the first form turns out to perform much better (and I'm not clear as to why this is happening) and the performance is necessary. THEN I would re-write the function using loop-recur. Or better yet, write a macro that preserves the elegance of the second form, but expands into a specialized loop-recur. Hope this helps -Patrick -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)
On Mon, Feb 15, 2010 at 12:58 PM, joseph hirn joseph.h...@gmail.com wrote: Hello. I've been trying to get emacs/slime running for a while on ubuntu 9.10. I used clojure box for Windows and that was excellent but this is not running very well for me. I compiled clojure and clojure-contrib.jar by cloning the repositories, checking out tag 1.1.0 and building them with ant. I then followed these instructions to a t (http://riddell.us/tutorial/ slime_swank/slime_swank.html). I've downloaded swank-clojure/slime/ clojure-mode as the instructions but used the latest code (I did not checkout a different tag). I have also tried emacs and emacs-snapshot, both installed via apt-get. Those instructions are pretty old. Have you tried the official readme? http://github.com/technomancy/swank-clojure Be sure to remove all the manual configuration from following the old instructions. -Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: processing two collections
I think it'd be a good exercise to do this all without using strings. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
On 15 February 2010 19:37, Аркадий Рост arkr...@gmail.com wrote: I don't understand the reason to make the argument binding-map: with-binding* is used in the definition of bound-fn*, which seems like a pretty useful thing to have. The reason it accepts a Var / value map is probably the fact that that's what get-thread-bindings / push-thread-bindings operate on, which in turn makes perfect sense to me. (They're essentially operating on environments, which are basically maps and should be optimised for map-like usage.) for example, using binding macro: (binding [a 5] ...do something...) ;;using vector to contain bindings. but using with-bindings*: (with-bindings* {#'a 5} f args) ;;hash-map is ised to contain bindings That's why you should just use binding most of the time and leave with-bindings / with-bindings* for strange special cases. what was the reason for such implementation? See above. (with-bindings* [a 5] f args) ;; it seems to be more common syntaxes Actually, not at all! with-* functions / macros, by convention, either take no binding-like argument at all (e.g. with-out-str) or whatever binding-like argument makes sense (e.g. clojure.contrib.sql/with-connection, which accepts a map of db connection parameters). Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Emacs/Slime -- Slime wont eval but *inferior-lisp* will (Help a newbie out)
joseph hirn joseph.h...@gmail.com writes: All seems to be well when I M-x slime, but if I enter (+ 1 2) it just hangs. If I switch to the *inferior-lisp* buffer and type this expression it returns 3 as expected. I have the same problem, as documented here: http://thread.gmane.org/gmane.comp.java.clojure.user/24894/focus=24956 In the *inferior-lisp* buffer, try evaluating the following form: (.. java.lang.management.ManagementFactory (getRuntimeMXBean) (getName)) Does that cause SLIME's REPL to finally connect to Swank? -- Steven E. Harris -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about how I got run?
On Sun, 14 Feb 2010 22:32:45 -0800 (PST) ataggart alex.tagg...@gmail.com wrote: On Feb 14, 6:47 pm, Mike Meyer mwm-keyword-googlegroups. 620...@mired.org wrote: So, the next question - possibly another name-space question. Is there any way to tell if inside a .clj file if it was invoked as a script by clojure.main, vs. being loaded for use elsewhere? No. To bad. It's really handy, especially as it starts trickling into system modules. You get one file that provides the simple command line usage plus functions that allow user to get to advanced usage. It also restores functionality that appears to be available in Java but not clojure, in that properly written scripts can then be invoked either from the command line, or as a function by an external caller. Wouldn't be hard to do, either. Just bind *script-name* (or some such) to the path in script-opt, and let the client decide if it's the same as *file*. What I'd like to do is make my unit tests usable in two modes: While working on a bug, I'd like to be able to load them in the REPL to rerun the subset of interest - possibly just the test which is failing. However, I'd also like to be able to feed the script to clojure.main with something like clj test.clj and have it run them all. java -cp path/to/clojure.jar:path/to/your/src clojure.main -e (run- tests 'your.namespace) This doesn't work - run-tests isn't defined, you have to load clojure.test to get it. Even if you wrap the clojure invocation up in a shell script, it's still sort of ugly. mike -- Mike Meyer m...@mired.org http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. O ascii ribbon campaign - stop html mail - www.asciiribbon.org -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about how I got run?
On 16 February 2010 02:12, Mike Meyer mwm-keyword-googlegroups.620...@mired.org wrote: To bad. It's really handy, especially as it starts trickling into system modules. You get one file that provides the simple command line usage plus functions that allow user to get to advanced usage. It also restores functionality that appears to be available in Java but not clojure, in that properly written scripts can then be invoked either from the command line, or as a function by an external caller. You can use gen-class to make your script runnable by Java. Just be sure to provide a -main function (or prefix-main, if you change the method prefix). The functions exported by the script's namespace will still be available as usual to Clojure code which requires / uses the namespace. Sincerely, Michał -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Seattle clojure group
We've started a mailing list for our new Seattle group: http://groups.google.com/group/seajure Hop on the list if you're interested. -Phil -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: how to use with-bindings*
Hi, On Feb 15, 7:37 pm, Аркадий Рост arkr...@gmail.com wrote: for example, using binding macro: (binding [a 5] ...do something...) ;;using vector to contain bindings. Beware the Leopard! user= (def a 5) #'user/a user= (declare b) #'user/b user= (binding [a 1 b (inc a)] b) 6 user= (let [a 1 b (inc a)] b) 2 Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
iterator-seq runs over
(map handler (iterator-seq result-set)) always throws a NoSuchElementException (map handler (butlast (iterator-seq result-set))) always works. (count (iterator-seq result-set)) is returning the correct number of elements. Calls to first, second, nth, also work correctly. When I manually test a result-set of three elements, [(handler (.next result-set)) (handler (.next result-set)) (handler (.next result-set))] evaluates correctly, while adding one more .next call results in the same NoSuchElementException. Using butlast fixes the problem, but then I obviously lose the last element in the result set. This code is replacing vanilla Java code which used .hasNext() and .next() without problem for a couple of months, so I doubt it's the class (com.hp.hpl.jena.query.ResultSet) incorrectly implementing Iterator. Has anyone else seen this type of behavior? Rob -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en