thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
Hi, Iam trying to run a function in a thread assuming that threads are runnable, below is my program i want to print 4 time the current date (defn- on-thread [f] (doto (Thread. #^Runnable f) (.start))) (defn prnTime [] (prn (System/currentTimeMillis))) (defn r4t [f] (dotimes [n 4] (f))) (r4t (on-thread (prnTime))) iam getting this error what is wrong with this ? java.lang.Thread cannot be cast to clojure.lang.IFn Pls let me know what is wrong and how to make it run in 4 threads so that i can see 4 time the system print to the screen -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
Hi, foop Your error in this line: (r4t (on-thread (prnTime))) You pass to function r4t thread instead of functions. Because (on-thread (prnTime)) returns thread You must pass #(on-thread (prnTime)) instead Regards, Nikita Beloglazov On Fri, Aug 6, 2010 at 3:13 PM, foop1 wrote: > Hi, > > Iam trying to run a function in a thread assuming that threads are > runnable, below is my program i want to print 4 time the current date > > > (defn- on-thread [f] > (doto (Thread. #^Runnable f) >(.start))) > > > (defn prnTime [] (prn (System/currentTimeMillis))) > > (defn r4t [f] > (dotimes [n 4] (f))) > > (r4t (on-thread (prnTime))) > iam getting this error what is wrong with this ? > java.lang.Thread cannot be cast to clojure.lang.IFn > > Pls let me know what is wrong and how to make it run in 4 threads so > that i can see 4 time the system print to the screen > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from 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: thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
thank you for the reply, is there any way to close this 4 threads after the job is done? On Aug 6, 8:34 am, Nikita Beloglazov wrote: > Hi, foop > Your error in this line: > (r4t (on-thread (prnTime))) > You pass to function r4t thread instead of functions. Because > (on-thread (prnTime)) returns thread > You must pass #(on-thread (prnTime)) instead > > Regards, > Nikita Beloglazov > > > > On Fri, Aug 6, 2010 at 3:13 PM, foop1 wrote: > > Hi, > > > Iam trying to run a function in a thread assuming that threads are > > runnable, below is my program i want to print 4 time the current date > > > (defn- on-thread [f] > > (doto (Thread. #^Runnable f) > > (.start))) > > > (defn prnTime [] (prn (System/currentTimeMillis))) > > > (defn r4t [f] > > (dotimes [n 4] (f))) > > > (r4t (on-thread (prnTime))) > > iam getting this error what is wrong with this ? > > java.lang.Thread cannot be cast to clojure.lang.IFn > > > Pls let me know what is wrong and how to make it run in 4 threads so > > that i can see 4 time the system print to the screen > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from 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: thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
What do you mean "close threads"? As I know threads aren't supposed to be closed. There is no mechanism to do this. They are not connections or smth like that. On Fri, Aug 6, 2010 at 3:46 PM, foop1 wrote: > thank you for the reply, is there any way to close this 4 threads > after the job is done? > > On Aug 6, 8:34 am, Nikita Beloglazov wrote: > > Hi, foop > > Your error in this line: > > (r4t (on-thread (prnTime))) > > You pass to function r4t thread instead of functions. Because > > (on-thread (prnTime)) returns thread > > You must pass #(on-thread (prnTime)) instead > > > > Regards, > > Nikita Beloglazov > > > > > > > > On Fri, Aug 6, 2010 at 3:13 PM, foop1 wrote: > > > Hi, > > > > > Iam trying to run a function in a thread assuming that threads are > > > runnable, below is my program i want to print 4 time the current date > > > > > (defn- on-thread [f] > > > (doto (Thread. #^Runnable f) > > >(.start))) > > > > > (defn prnTime [] (prn (System/currentTimeMillis))) > > > > > (defn r4t [f] > > > (dotimes [n 4] (f))) > > > > > (r4t (on-thread (prnTime))) > > > iam getting this error what is wrong with this ? > > > java.lang.Thread cannot be cast to clojure.lang.IFn > > > > > Pls let me know what is wrong and how to make it run in 4 threads so > > > that i can see 4 time the system print to the screen > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > clojure+unsubscr...@googlegroups.com > > > > > For more options, visit this group at > > >http://groups.google.com/group/clojure?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Slightly Off Topic: .NET books
Are there any good .NET books you guys could recommend? I'm looking for a range of resources. I don't need "C# in 21 days" or "C# for dummies", but something an experienced Java hacker could start out with, similar to Core Java. Also, a more advanced book so I could learn to follow the ClojureCLR source would be great too. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
In addition to that, prnTime should have no parens: #(on-thread prnTime) As it was, prnTime was running before going into on-thread, which was acting on a runnable that's nil (the return value of prn). The difference between the two can be seen in the output. When prnTime runs inside the threads, its output gets mixed up with thre repl, as you'd expect. user=> (r4t #(on-thread prnTime)) 1281109289923 nil 1281109289939 1281109289939 user=> 1281109289939 (r4t #(on-thread (prnTime))) 1281109301705 1281109301705 1281109301705 1281109301705 nil On Aug 6, 5:34 am, Nikita Beloglazov wrote: > Hi, foop > Your error in this line: > (r4t (on-thread (prnTime))) > You pass to function r4t thread instead of functions. Because > (on-thread (prnTime)) returns thread > You must pass #(on-thread (prnTime)) instead > > Regards, > Nikita Beloglazov > > > > On Fri, Aug 6, 2010 at 3:13 PM, foop1 wrote: > > Hi, > > > Iam trying to run a function in a thread assuming that threads are > > runnable, below is my program i want to print 4 time the current date > > > (defn- on-thread [f] > > (doto (Thread. #^Runnable f) > > (.start))) > > > (defn prnTime [] (prn (System/currentTimeMillis))) > > > (defn r4t [f] > > (dotimes [n 4] (f))) > > > (r4t (on-thread (prnTime))) > > iam getting this error what is wrong with this ? > > java.lang.Thread cannot be cast to clojure.lang.IFn > > > Pls let me know what is wrong and how to make it run in 4 threads so > > that i can see 4 time the system print to the screen > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]
Hi Nikita, Your function works! Could you explain the "->>" a bit? Thanks, - Dave On Aug 5, 5:53 pm, Nikita Beloglazov wrote: > See my variant of your > application:https://gist.github.com/efdb66487e899446332f > I don't know if it works, because I can't test :( > > My thoughts about your example > You shouldn't think about this procedure as about procedure where you use > loop, like in other imperative languages with mutable data. As I understand > you tried something like: > > for every line in file do > if line matches then > convert line to coords > add coords to global variable hold-coords > end if > end for > > But it's not the clojure way, I think clojure way is: > > get all lines as sequence > convert every element of this sequence to vector of coords > concat all vectors to one > > And in your example>dpa> (def y [5 6 7]) (let [x (into y [2 3 4]) y x ] y) > >[5 6 7 2 3 4] > >dpa> y > >[5 6 7] > > When you use y in let, it introduce new local variable y, which "hides" > global y > It you want to use mutable data (I don't think it's good), you can use atoms > - it's special mmm... mechanism for mutable data: > > user> (def y (atom [1 2 3])) > #'user/y > > user> @y > [1 2 > 3] > > user> (swap! y into [4 5 6]) > [1 2 3 4 5 > 6] > > user> @y > [1 2 3 4 5 > 6] > > Here you bind to variable y an atom with initial value - vector [1 2 3]. To > get value of atom you use @ before the variable name: @y > To change value you call (swap! atom func x y z). First it calculates new > value like this: (func @atom x y z), in our example it will calculate (into > @y [4 5 6]). It returns vector [1 2 3 4 5 6], and this vector is set as new > value of y. > > Regards, > Nikita Beloglazov > > > > On Thu, Aug 5, 2010 at 11:49 PM, Dave wrote: > > Thanks for the extra parentheses catch. I just noticed that while > > working on a different function (after hours of trying to figure it > > out). > > > The program is reading in a pdb file line-by-line. I only want the > > xyz-coordinates of carbon atoms, avoiding any repeats when the > > coordinate of an atom is uncertain. Also, a protein may have multiple > > sub-units, and the chains parameter can pick out the desired sub- > > unit(s). So I need to: > > 1) make sure the line is long enough > > 2) make sure I have an atom > > 3) make sure it's not a repeated measurement > > 4) make sure it's a C_{alpha} atom > > If the current pdb-file line matches those criteria, I'll then put its > > xyz-coordinates into the output matrix. > > > I tried this using let: > > > (defn process-dpa-file2 > > "This makes the matrix of CA coordinates from a pdb file." > > [pdb-file chains] > > (def hold-coords []) > > (doseq [^String line (read-lines pdb-file)] > > ;; Make sure the file line is the correct length > > ;; We only want the atom entries > > ;; We don't want any repeated measurements for an atom > > ;; Is it a CA? > > ;; Are we using this chain? > > (if (and (= (.length line) 80) > > (= (str (.substring line 0 4) (.substring line 26 27) > > (.substring line 13 15)) "ATOM CA") > > (substring? (.substring line 21 22) chains)) > > ;; These are the CA coordinates > > (let [coords (into hold-coords [ (Double. (.substring line 30 > > 37)) > > (Double. (.substring line 38 45)) > > (Double. (.substring line 46 53))]) > > hold-coords coords])) > > (matrix hold-coords 3))) > > > but the output gives: > > > dpa> (def my-mat (process-dpa-file2 "/Users/daviddreisigmeyer/MyStuff/ > > DPA_release_12-JUL-2010/1RD8.pdb" "A") ) > > #'dpa/my-mat > > dpa> my-mat > > nil > > > A simpler example: > > > dpa> (def y [5 6 7]) (let [x (into y [2 3 4]) y x ] y) > > [5 6 7 2 3 4] > > dpa> y > > [5 6 7] > > > So it seems that in process-dpa-file2 I have the coordinates of the > > 1st carbon atom in hold-coords, and then the 2nd, the 3rd ... After > > finding the 3rd carbon, I'd want: > > > hold-coords = [x1 y1 z1 x2 y2 z2 x3 y3 z3] (**) > > > but instead I get > > > hold-coords = [x3 y3 z3]. Any idea about how I could get (**) > > instead? Thanks! -Dave > > > On Aug 5, 2:46 pm, Nikita Beloglazov wrote: > > > Hi, Dave > > > Why do you use 2 parenthesis before "with-open" in the first variant? > > > And, as I know, it's not good practice to use def inside functions. Use > > let > > > instead. > > > I also advice you to split your program to smaller functions. > > > Can you describe, what your program must do? Because don't understand :( > > > > On Thu, Aug 5, 2010 at 9:28 PM, Dave > > wrote: > > > > Hi, > > > > > I don't understand why this doesn't work: > > > > > (ns dpa > > > > (:gen-class) > > > > (:use [incanter.core :only ( matrix )] > > > > [clojure.core :only ( defn doseq line-seq println with-open )] > > > > [clojure.contrib.string :only ( blank? substring? )] > > > > (:import (java.io BufferedReader FileR
Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]
Hi Dave, There are really 2 functions, -> and ->> First -> Sometimes you need to perform several functions on after another. You can write something like (func1 (func2 (func3 value))) But you also can write like: (-> value (func3) (func2) (func1)) It takes value, insert it into (func1) form as second element, so it will become (func3 value), evaluates it. Result of evaluation insert into (func2), evaluates it and etc. -> function inserts value as second element, e.g. (form3 a b c) becomes (form3 value a b c) ->> function inserts value as last element, e.g. (form3 a b c) becomes (form3 a b c value) (->> (read-lines pdb-file) (map #(parse-line % chains)) (apply concat))) First it evaluates (read-lines pdb-file), let's name the result seq1 Then it evaluates (map #(parse-line % chains) seq1) and we get seq2 And finally it evaluates (apply concat seq2) Regards, Nikita Beloglazov On Fri, Aug 6, 2010 at 7:26 PM, Dave wrote: > Hi Nikita, > > Your function works! Could you explain the "->>" a bit? Thanks, - > Dave > > On Aug 5, 5:53 pm, Nikita Beloglazov wrote: > > See my variant of your application: > https://gist.github.com/efdb66487e899446332f > > I don't know if it works, because I can't test :( > > > > My thoughts about your example > > You shouldn't think about this procedure as about procedure where you use > > loop, like in other imperative languages with mutable data. As I > understand > > you tried something like: > > > > for every line in file do > > if line matches then > > convert line to coords > > add coords to global variable hold-coords > >end if > > end for > > > > But it's not the clojure way, I think clojure way is: > > > > get all lines as sequence > > convert every element of this sequence to vector of coords > > concat all vectors to one > > > > And in your example>dpa> (def y [5 6 7]) (let [x (into y [2 3 4]) y x ] > y) > > >[5 6 7 2 3 4] > > >dpa> y > > >[5 6 7] > > > > When you use y in let, it introduce new local variable y, which "hides" > > global y > > It you want to use mutable data (I don't think it's good), you can use > atoms > > - it's special mmm... mechanism for mutable data: > > > > user> (def y (atom [1 2 3])) > > #'user/y > > > > user> @y > > [1 2 > > 3] > > > > user> (swap! y into [4 5 6]) > > [1 2 3 4 5 > > 6] > > > > user> @y > > [1 2 3 4 5 > > 6] > > > > Here you bind to variable y an atom with initial value - vector [1 2 3]. > To > > get value of atom you use @ before the variable name: @y > > To change value you call (swap! atom func x y z). First it calculates new > > value like this: (func @atom x y z), in our example it will calculate > (into > > @y [4 5 6]). It returns vector [1 2 3 4 5 6], and this vector is set as > new > > value of y. > > > > Regards, > > Nikita Beloglazov > > > > > > > > On Thu, Aug 5, 2010 at 11:49 PM, Dave > wrote: > > > Thanks for the extra parentheses catch. I just noticed that while > > > working on a different function (after hours of trying to figure it > > > out). > > > > > The program is reading in a pdb file line-by-line. I only want the > > > xyz-coordinates of carbon atoms, avoiding any repeats when the > > > coordinate of an atom is uncertain. Also, a protein may have multiple > > > sub-units, and the chains parameter can pick out the desired sub- > > > unit(s). So I need to: > > > 1) make sure the line is long enough > > > 2) make sure I have an atom > > > 3) make sure it's not a repeated measurement > > > 4) make sure it's a C_{alpha} atom > > > If the current pdb-file line matches those criteria, I'll then put its > > > xyz-coordinates into the output matrix. > > > > > I tried this using let: > > > > > (defn process-dpa-file2 > > > "This makes the matrix of CA coordinates from a pdb file." > > > [pdb-file chains] > > > (def hold-coords []) > > > (doseq [^String line (read-lines pdb-file)] > > >;; Make sure the file line is the correct length > > >;; We only want the atom entries > > >;; We don't want any repeated measurements for an atom > > >;; Is it a CA? > > >;; Are we using this chain? > > >(if (and (= (.length line) 80) > > > (= (str (.substring line 0 4) (.substring line 26 27) > > > (.substring line 13 15)) "ATOM CA") > > > (substring? (.substring line 21 22) chains)) > > > ;; These are the CA coordinates > > > (let [coords (into hold-coords [ (Double. (.substring line 30 > > > 37)) > > >(Double. (.substring line 38 > 45)) > > >(Double. (.substring line 46 > 53))]) > > > hold-coords coords])) > > >(matrix hold-coords 3))) > > > > > but the output gives: > > > > > dpa> (def my-mat (process-dpa-file2 "/Users/daviddreisigmeyer/MyStuff/ > > > DPA_release_12-JUL-2010/1RD8.pdb" "A") ) > > > #'dpa/my-mat > > > dpa> my-mat > > > nil > > > > > A simpler example: > > > > > dpa> (def y [5 6 7]) (let [x (into y [2 3
Re: (java.io BufferedReader FileReader) versus [clojure.contrib.duck-streams :only (read-lines)]
Awesome! Thank you so much for your help -- I really appreciate it. On Aug 6, 12:43 pm, Nikita Beloglazov wrote: > Hi Dave, > There are really 2 functions, -> and ->> > First -> > Sometimes you need to perform several functions on after another. You can > write something like > (func1 (func2 (func3 value))) > But you also can write like: > (-> value > (func3) > (func2) > (func1)) > It takes value, insert it into (func1) form as second element, so it will > become (func3 value), evaluates it. Result of evaluation insert into > (func2), evaluates it and etc. > -> function inserts value as second element, e.g. (form3 a b c) becomes > (form3 value a b c) > ->> function inserts value as last element, e.g. (form3 a b c) becomes > (form3 a b c value) > > (->> (read-lines pdb-file) > (map #(parse-line % chains)) > (apply concat))) > First it evaluates (read-lines pdb-file), let's name the result seq1 > Then it evaluates (map #(parse-line % chains) seq1) and we get seq2 > And finally it evaluates (apply concat seq2) > > Regards, > Nikita Beloglazov > > > > On Fri, Aug 6, 2010 at 7:26 PM, Dave wrote: > > Hi Nikita, > > > Your function works! Could you explain the "->>" a bit? Thanks, - > > Dave > > > On Aug 5, 5:53 pm, Nikita Beloglazov wrote: > > > See my variant of your application: > >https://gist.github.com/efdb66487e899446332f > > > I don't know if it works, because I can't test :( > > > > My thoughts about your example > > > You shouldn't think about this procedure as about procedure where you use > > > loop, like in other imperative languages with mutable data. As I > > understand > > > you tried something like: > > > > for every line in file do > > > if line matches then > > > convert line to coords > > > add coords to global variable hold-coords > > > end if > > > end for > > > > But it's not the clojure way, I think clojure way is: > > > > get all lines as sequence > > > convert every element of this sequence to vector of coords > > > concat all vectors to one > > > > And in your example>dpa> (def y [5 6 7]) (let [x (into y [2 3 4]) y x ] > > y) > > > >[5 6 7 2 3 4] > > > >dpa> y > > > >[5 6 7] > > > > When you use y in let, it introduce new local variable y, which "hides" > > > global y > > > It you want to use mutable data (I don't think it's good), you can use > > atoms > > > - it's special mmm... mechanism for mutable data: > > > > user> (def y (atom [1 2 3])) > > > #'user/y > > > > user> @y > > > [1 2 > > > 3] > > > > user> (swap! y into [4 5 6]) > > > [1 2 3 4 5 > > > 6] > > > > user> @y > > > [1 2 3 4 5 > > > 6] > > > > Here you bind to variable y an atom with initial value - vector [1 2 3]. > > To > > > get value of atom you use @ before the variable name: @y > > > To change value you call (swap! atom func x y z). First it calculates new > > > value like this: (func @atom x y z), in our example it will calculate > > (into > > > @y [4 5 6]). It returns vector [1 2 3 4 5 6], and this vector is set as > > new > > > value of y. > > > > Regards, > > > Nikita Beloglazov > > > > On Thu, Aug 5, 2010 at 11:49 PM, Dave > > wrote: > > > > Thanks for the extra parentheses catch. I just noticed that while > > > > working on a different function (after hours of trying to figure it > > > > out). > > > > > The program is reading in a pdb file line-by-line. I only want the > > > > xyz-coordinates of carbon atoms, avoiding any repeats when the > > > > coordinate of an atom is uncertain. Also, a protein may have multiple > > > > sub-units, and the chains parameter can pick out the desired sub- > > > > unit(s). So I need to: > > > > 1) make sure the line is long enough > > > > 2) make sure I have an atom > > > > 3) make sure it's not a repeated measurement > > > > 4) make sure it's a C_{alpha} atom > > > > If the current pdb-file line matches those criteria, I'll then put its > > > > xyz-coordinates into the output matrix. > > > > > I tried this using let: > > > > > (defn process-dpa-file2 > > > > "This makes the matrix of CA coordinates from a pdb file." > > > > [pdb-file chains] > > > > (def hold-coords []) > > > > (doseq [^String line (read-lines pdb-file)] > > > > ;; Make sure the file line is the correct length > > > > ;; We only want the atom entries > > > > ;; We don't want any repeated measurements for an atom > > > > ;; Is it a CA? > > > > ;; Are we using this chain? > > > > (if (and (= (.length line) 80) > > > > (= (str (.substring line 0 4) (.substring line 26 27) > > > > (.substring line 13 15)) "ATOM CA") > > > > (substring? (.substring line 21 22) chains)) > > > > ;; These are the CA coordinates > > > > (let [coords (into hold-coords [ (Double. (.substring line 30 > > > > 37)) > > > > (Double. (.substring line 38 > > 45)) > > > > (Double. (.substring line 46 > > 53))]) > > > > hold-coords coords])) >
eval and threads...
I have a server which loads some compiled classes/functions then starts accepting requests and handing them off onto a thread pool for processing. No problem - so far... One of the requests allows the passing and evaluation of an arbitrary piece of clojure. This is causing me to lose hair ! The code executes fine in a single threaded testsuiite, but when I move the eval onto another thread I find that expected symbols aren't defined etc. I have tried using (binding *ns* ) to force evaluation to occur in the correct namespace, but then experience more unfound symbols etc... Can someone explain to me how namespaces, threads and eval interact with each other, or point me to a resource where I can find this for myself ? Am I doing something that I shouldn't ? thanks for your time, Jules P.S. Clojure-1.2-beta1 / Java6 -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Slightly Off Topic: .NET books
On Fri, 06 Aug 2010 08:33 -0700, "Sean Devlin" wrote: > Are there any good .NET books you guys could recommend? I'm looking > for a range of resources. I don't need "C# in 21 days" or "C# for > dummies", but something an experienced Java hacker could start out > with, similar to Core Java. Also, a more advanced book so I could > learn to follow the ClojureCLR source would be great too. _CLR via C#_ is a must, Third Edition is current. I also like (and own) the following: - _Advanced .NET Debugging_ by Mario Hewardt and Patrick Dussud - _More Effective C#_ and _Effective C#, Second Edition_ by Bill Wagner - _Framework Design Guidelines, 2nd Edition_ by Krzysztof Cwalina and Brad Abrams - _The C# Programming Language, 3rd Edition_ by Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, and Peter Golde - _Annotated C# Standard_ by Jon Jagger, Nigel Perry, and Peter Sestoft - _Expert .NET 2.0 IL Assembler_ by Serge Lidin Hope this helps. If you read any of these, I would be interested in your feedback. I'm also interested in other people's recommendations. -- Dan Moniz [http://pobox.com/~dnm/] -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Slightly Off Topic: .NET books
We have a ten-week program for experienced developers moving to the .NET platform. Our recommended text is Troelson's "Pro C# 2010 and the .NET 4 Platform, Fifth Edition". http://www.apress.com/book/view/1430225491 All 1752 pages of it. It has a lot of things you won't need for understanding ClojureCLR source, such as ASP.NET, WinForms, etc. --David On Aug 6, 10:33 am, Sean Devlin wrote: > Are there any good .NET books you guys could recommend? I'm looking > for a range of resources. I don't need "C# in 21 days" or "C# for > dummies", but something an experienced Java hacker could start out > with, similar to Core Java. Also, a more advanced book so I could > learn to follow the ClojureCLR source would be great too. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
System calls
I having some trouble with system calls using clojure (actually a whole lot more than that but this is the current day's difficulty). Below, test-execute works, but get-msms-pts-OSX seems to hang, as in nothing happens and the REPL is unresponsive afterwards. If I run the output of the (str ***) commands below in a terminal it works fine. I copied execute from here: http://www.magpiebrain.com/2010/06/20/executing-a-command-line-program-with-clojure/ Thanks! -Dave * (ns msms (:gen-class) (:use [clojure.contrib.duck-streams :only (read-lines)])) (defn execute [command] (let [process (.exec (Runtime/getRuntime) command)] (if (= 0 (.waitFor process)) (read-lines (.getInputStream process)) (read-lines (.getErrorStream process) (defn test-execute [ls-arg] (execute (str "ls " ls-arg))) (defn get-msms-pts-OSX ;; Finds the msms points for a density (optional DEFAULT = 1.0) and radius (optional DEFAULT = 1.5) [pdb-file density radius] (execute (str "pdb_to_xyzr " pdb-file " > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr")) (execute (str "msms.MacOSX.2.6.1" " -if /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr" " -of /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold - no_header -density " density " -probe_radius " radius)) (execute (str "rm -f /Users/daviddreisigmeyer/lisps/clojure/dpa/src/ hold.xyzr" " /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.face"))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: Slightly Off Topic: .NET books
+1 for: _The C# Programming Language, 3rd Edition_ by Anders Hejlsberg, Mads Torgersen, Scott Wiltamuth, and Peter Golde Pretty decent book, but I'm not sure if it's been updated since 2.0 (a lot of cool stuff came in 3.0 and 4.0 [LINQ, implicit type (inference), initializers, extension methods, lambdas, named and optional parameters, to name a few]). - Mark On Fri, Aug 6, 2010 at 3:54 PM, Dan Moniz wrote: > On Fri, 06 Aug 2010 08:33 -0700, "Sean Devlin" > wrote: > > > Are there any good .NET books you guys could recommend? I'm looking > > for a range of resources. I don't need "C# in 21 days" or "C# for > > dummies", but something an experienced Java hacker could start out > > with, similar to Core Java. Also, a more advanced book so I could > > learn to follow the ClojureCLR source would be great too. > > _CLR via C#_ is a must, Third Edition is current. I also like (and own) > the following: > > - _Advanced .NET Debugging_ by Mario Hewardt and Patrick Dussud > > - _More Effective C#_ and _Effective C#, Second Edition_ by Bill Wagner > > - _Framework Design Guidelines, 2nd Edition_ by Krzysztof Cwalina and > Brad Abrams > > - _The C# Programming Language, 3rd Edition_ by Anders Hejlsberg, Mads > Torgersen, Scott Wiltamuth, and Peter Golde > > - _Annotated C# Standard_ by Jon Jagger, Nigel Perry, and Peter Sestoft > > - _Expert .NET 2.0 IL Assembler_ by Serge Lidin > > Hope this helps. If you read any of these, I would be interested in your > feedback. I'm also interested in other people's recommendations. > > > -- > Dan Moniz [http://pobox.com/~dnm/] > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from 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: System calls
Also, this only shows the 2nd call (with ls-arg2): (defn test-execute [ls-arg1 ls-arg2] (execute (str "ls -" ls-arg1)) (execute (str "ls -" ls-arg2))) so maybe the difficulty above is some problem with how the multiple system calls are performed. If I only use this: (defn get-msms-pts-OSX ;; Finds the msms points for a density (optional DEFAULT = 1.0) and radius (optional DEFAULT = 1.5) [pdb-file density radius] (execute (str "pdb_to_xyzr " pdb-file " > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr"))) I get the error: Cannot run program "pdb_to_xyzr": error=2, No such file or directory [Thrown class java.io.IOException] I've put pdb_to_xyzr on my path, and I can call it from a terminal, i.e., putting this output in a terminal works: (str "pdb_to_xyzr " "/Users/daviddreisigmeyer/lisps/clojure/dpa/src/ 1RD8.pdb" " > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr") * I use this in a terminal: * "pdb_to_xyzr /Users/daviddreisigmeyer/lisps/clojure/dpa/src/1RD8.pdb > /Users/daviddreisigmeyer/lisps/clojure/dpa/src/hold.xyzr" -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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 1.2 RC2
Clojure 1.2 RC 2 is now available, along with a corresponding Clojure Contrib, at: http://clojure.org/downloads There is one important change since RC1. Record/map equality is now symmetric in all cases. There are two variants: * In most cases, you should use =. Calls to = include type information, so instances of different record types can never be = to each other, or to plain maps. * Calls to .equals are different. They respect the Java semantics for maps, which is a requirement for correct interop. Type information is *not* included, so any kind of map can be .equals to any other. Possible impacts for your programs: * If you create a custom implementation of Clojure's IPersistentMap, you probably want it to be able to be = to other maps. If so, all you need to do is implement the marker interface clojure.lang.MapEquivalence. Note that APersistentMap does this for you. A full list of changes is available at http://github.com/clojure/clojure/blob/1.2.x/changes.txt For maven/leiningen users, your settings to get the beta from build.clojure.org/releases are: :dependencies [[org.clojure/clojure "1.2.0-RC2"] [org.clojure/clojure-contrib "1.2.0-RC2"] To everyone who has contributed to 1.2, many thanks! Stu -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: thread running throwing error java.lang.Thread cannot be cast to clojure.lang.IFn
Aha! i see what you are saying thank you for pointing the real subtleness of the way command is return, this group is really excellent and awesome in helpfullness On Aug 6, 11:51 am, Armando Blancas wrote: > In addition to that, prnTime should have no parens: > #(on-thread prnTime) > > As it was, prnTime was running before going into on-thread, which was > acting on a runnable that's nil (the return value of prn). The > difference between the two can be seen in the output. When prnTime > runs inside the threads, its output gets mixed up with thre repl, as > you'd expect. > > user=> (r4t #(on-thread prnTime)) > 1281109289923 > nil > 1281109289939 > 1281109289939 > user=> 1281109289939 > > (r4t #(on-thread (prnTime))) > 1281109301705 > 1281109301705 > 1281109301705 > 1281109301705 > nil > > On Aug 6, 5:34 am, Nikita Beloglazov wrote: > > > > > Hi, foop > > Your error in this line: > > (r4t (on-thread (prnTime))) > > You pass to function r4t thread instead of functions. Because > > (on-thread (prnTime)) returns thread > > You must pass #(on-thread (prnTime)) instead > > > Regards, > > Nikita Beloglazov > > > On Fri, Aug 6, 2010 at 3:13 PM, foop1 wrote: > > > Hi, > > > > Iam trying to run a function in a thread assuming that threads are > > > runnable, below is my program i want to print 4 time the current date > > > > (defn- on-thread [f] > > > (doto (Thread. #^Runnable f) > > > (.start))) > > > > (defn prnTime [] (prn (System/currentTimeMillis))) > > > > (defn r4t [f] > > > (dotimes [n 4] (f))) > > > > (r4t (on-thread (prnTime))) > > > iam getting this error what is wrong with this ? > > > java.lang.Thread cannot be cast to clojure.lang.IFn > > > > Pls let me know what is wrong and how to make it run in 4 threads so > > > that i can see 4 time the system print to the screen > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > clojure+unsubscr...@googlegroups.com > > > > > > For more options, visit this group at > > >http://groups.google.com/group/clojure?hl=en-Hide quoted text - > > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
lein-daemon problems
Anyone using lein-deamon and have success getting it working? When trying to start a daemon with 'lein daemon start daemon-name', I'm getting java.lang.IllegalArgumentException: No matching method: with-bindings (daemonProxy.clj:27). The entire error log is at http://gist.github.com/512327. I get this error with both clojure 1.1 and 1.2-RC1. The lein-daemon code referenced in the error is at http://github.com/arohner/lein-daemon/blob/master/src/leiningen/daemon/daemonProxy.clj. Has anyone seen this? Or can someone push me down some path? I'm stuck for the moment. 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 Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: System calls
On Aug 6, 11:50 pm, Dave wrote: > I get the error: > > Cannot run program "pdb_to_xyzr": error=2, No such file or directory > [Thrown class java.io.IOException] You may have a path problem. Try running "env" in the same fashion - I get a very basic path (just "/bin" and "/usr/bin") and none of my settings from .bashrc or .profile. Workarounds I know of: - Use clojure.contrib.shell-out and supply a map of the environment variables you need, including the path: http://richhickey.github.com/clojure-contrib/shell-out-api.html - Put the "pdb_to_xyzr" call into a shell script that sets the path for you, and call the shell script from your program. - Use the full path to the executable rather than relying on environment variables. - Use one of the Java Runtime.exec variants that takes a String array of environment variables. (Although I would recommend one of the other options - I don't think there's a direct way to create a String array in Clojure, but you could do it indirectly through String.split or similar.): http://download-llnw.oracle.com/javase/1.5.0/docs/api/java/lang/Runtime.html Regards jf -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: System calls
On Aug 7, 5:06 am, j-g-faustus wrote: > I don't think there's a direct way to create a String array > in Clojure Correction - there is: (into-array String ["a" "b"]) jf -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from 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: System calls
Hi, Am 07.08.2010 um 05:06 schrieb j-g-faustus: > I don't think there's a direct way to create a String array in Clojure (defn to-env [env-vars-map] (->> env-vars-map (map #(str (name (key %)) "=" (val %))) into-array)) And an invocation: user=> (to-env {:PATH "/bin:/usr/bin" :HOME "/Users/mb" :foo "bar"}) # user=> (seq *1) ("PATH=/bin:/usr/bin" "HOME=/Users/mb" "foo=bar") :) 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: System calls
> :) (inc ":)") On Sat, Aug 7, 2010 at 7:27 AM, Meikel Brandmeyer wrote: > Hi, > > Am 07.08.2010 um 05:06 schrieb j-g-faustus: > >> I don't think there's a direct way to create a String array in Clojure > > (defn to-env > [env-vars-map] > (->> env-vars-map > (map #(str (name (key %)) "=" (val %))) > into-array)) > > And an invocation: > > user=> (to-env {:PATH "/bin:/usr/bin" :HOME "/Users/mb" :foo "bar"}) > # > user=> (seq *1) > ("PATH=/bin:/usr/bin" "HOME=/Users/mb" "foo=bar") > > :) > > 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