Re: newbie seq question

2014-04-12 Thread François Rey
On 13/04/14 02:21, Stephen Feyrer wrote: // Get the java file io library (import '(java.io File)) // Get some files (def f (File. "/My/files/")) (def fs (file-seq f)) // Filters for suffixes ".mp3" (def get-mp3 (filter #(.endsWith (.getName %) ".mp3") fs)) // Get the path of

Re: My experiments with concurrent programming

2014-04-12 Thread Gary Trakhman
I took a look at the code, but it's not clear to me what it's supposed to be doing. But, my suspicion is this algorithm could be expressed as a reduce, which means you could potentially use reducers on it and get fork/join concurrency for free. I think that's the case because it seems like these

newbie seq question

2014-04-12 Thread Stephen Feyrer
Hey, I have hacked together this code: // Get the java file io library (import '(java.io File)) // Get some files (def f (File. "/My/files/")) (def fs (file-seq f)) // Filters for suffixes ".mp3" (def get-mp3 (filter #(.endsWith (.getName %) ".mp3") fs)) // Get the path of one mp3 (println (t

Re: [Video] Game development in Clojure (with play-clj)

2014-04-12 Thread Kris Calabio
Great video! I've looked through Zach's examples, and even started coding a game myself. But your screencast helped me have a better understanding of some of the concepts and code that I was having trouble understanding just by looking at the example games. Thanks! -Kris On Thursday, March 27,

Re: How to work with variables that need to change

2014-04-12 Thread John Mastro
On Sat, Apr 12, 2014 at 5:13 AM, Cecil Westerhof wrote: > But it looks a ‘little’ cumbersome. Is there a better way to do this? Here's another way. Not the best way, but I offer it to introduce you to atoms [1] if you're not familiar yet. [1] http://clojure.org/atoms (def numbers '(4 6 8 10))

Re: Surprising behaviour related to records, protocols and AOT

2014-04-12 Thread Aysylu Greenberg
As discovered by Kevin Downey , (use [loom.graph] :reload) in tests was causing the namespace to be reloaded, which redefined the records in loom.graph, but didn't reload loom.attrs , so the extends didn't get run again for the new record type breaking all kinds of

Re: My experiments with concurrent programming

2014-04-12 Thread Cecil Westerhof
2014-04-12 17:19 GMT+02:00 Gary Trakhman : > I'd recommend running a doall on concurrent-list in order to realize the > futures, if you simply deref as you are, then you're going to delay the > execution of futures down the line as the sequence is realized bit by bit > (except chunking helps you h

Re: Is it possible to give an atomic message?

2014-04-12 Thread Cecil Westerhof
2014-04-11 18:12 GMT+02:00 Alex Vzorov : > You could use a clojure agent , that would > output your messages on a separate thread, one by one. > > (def *logger* (agent 0)) > > (defn give-message [message] > (send *logger* > (fn [_ & [msg]] (println (format "%s:

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 20:36 GMT+02:00 Fergal Byrne : > It's always best to see how best to do something, one day it'll make all > the difference. > I agree. Most people call it gold-plating. And of-course you have to be careful about that, but things like this are good to do is my opinion. > On Sat, Apr

Re: How to work with variables that need to change

2014-04-12 Thread Fergal Byrne
Cheers Cecil, It's always best to see how best to do something, one day it'll make all the difference. On Sat, Apr 12, 2014 at 7:03 PM, Cecil Westerhof wrote: > 2014-04-12 16:18 GMT+02:00 Fergal Byrne : > > That's fine, but note that creating new Calendar objects has an overhead, >> using Syste

Re: Is it possible to give an atomic message?

2014-04-12 Thread Max Penet
One of the possibility is to use joda-time DateTimeFormatter (directly or via one of the clojure wrappers). On Saturday, April 12, 2014 1:24:22 PM UTC+2, Cecil Westerhof wrote: > > 2014-04-12 11:40 GMT+02:00 Max Penet >: > >> Be aware that SimpleDateFormat is not threadsafe though. >> > > What s

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 16:18 GMT+02:00 Fergal Byrne : > That's fine, but note that creating new Calendar objects has an overhead, > using System.currentTimeMillis() is a static OS call which your now() > probably uses, as well as object creation. It probably won't be millisecond > sized, but you can measure y

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 18:19 GMT+02:00 Fergal Byrne : > > On Sat, Apr 12, 2014 at 4:55 PM, Cecil Westerhof > wrote: > >> (->> numbers >> (reduce timed-foo []) >> (map format-time) >> println) >> > > (->> numbers > (reduce timed-foo []) > (map format-time) > (map println)) > Tha

Re: Get rid of the clojure.jar

2014-04-12 Thread Fergal Byrne
+1 Gary I'd just run the Leiningen install process, then create a new project with it, and move your code into that. Do this right now, I can't imagine doing anything in Clojure that doesn't begin with lein new your-project. It will save you hours in fewer hours. Bonus: add Midje, or even be

Re: How to work with variables that need to change

2014-04-12 Thread Fergal Byrne
On Sat, Apr 12, 2014 at 4:55 PM, Cecil Westerhof wrote: > (->> numbers > (reduce timed-foo []) > (map format-time) > println) > (->> numbers (reduce timed-foo []) (map format-time) (map println)) -- Fergal Byrne, Brenter IT Author, Real Machine Intelligence with

Re: Get rid of the clojure.jar

2014-04-12 Thread Cecil Westerhof
2014-04-12 17:56 GMT+02:00 Gary Trakhman : > Oh man, please consider using leiningen. It's a whole new world :-) > > http://leiningen.org/ > That was on my list. I'll leave this problem for the moment being then, because it will be solved 'automatically'. :-D -- Cecil Westerhof -- You receive

Re: Get rid of the clojure.jar

2014-04-12 Thread Gary Trakhman
In your case, once you've created a leiningen project, it's as easy as 'lein uberjar'. On Sat, Apr 12, 2014 at 11:56 AM, Gary Trakhman wrote: > Oh man, please consider using leiningen. It's a whole new world :-) > > http://leiningen.org/ > > > On Sat, Apr 12, 2014 at 11:49 AM, Cecil Westerhof >

Re: Get rid of the clojure.jar

2014-04-12 Thread Gary Trakhman
Oh man, please consider using leiningen. It's a whole new world :-) http://leiningen.org/ On Sat, Apr 12, 2014 at 11:49 AM, Cecil Westerhof wrote: > I am not so far yet that I need it, but it never hurts to look ahead. > > When compiling your Clojure program you call it with: > > java -clas

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 16:27 GMT+02:00 Fergal Byrne : > (defn timed-foo [times n] > (let [start (now)] > (foo n) > (conj times [n (- (now) start)]))) > > (defn format-time [[n t]] > (format "%2d threads took %7d milliseconds" n t)) > > (->> numbers > (reduce timed-foo []) > (map format-t

Get rid of the clojure.jar

2014-04-12 Thread Cecil Westerhof
I am not so far yet that I need it, but it never hurts to look ahead. When compiling your Clojure program you call it with: java -classpath *path*/classes:*path*/clojure.jar com.ociweb.talk *args* But when distributing a program, it would be better to give just one jar file I would think. Ho

Re: Is it possible to find the number of cores

2014-04-12 Thread Cecil Westerhof
2014-04-12 17:20 GMT+02:00 Fergal Byrne : > (.. Runtime getRuntime availableProcessors) is a bit cleaner > Did not know that one. Definitely better. But I already changed the way I do it. I think I will use Runtime more often, so I do now: (def runtime (. Runtime (getRuntime))) (.availablePro

Re: My experiments with concurrent programming

2014-04-12 Thread Gary Trakhman
Also, 'doall' is a bad idea if the number of threads is large :-). You might want more control over the threadpool at that point. Futures uses http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool() https://github.com/clojure/clojure/blob/master/src/clj

Re: Is it possible to find the number of cores

2014-04-12 Thread Fergal Byrne
(.. Runtime getRuntime availableProcessors) is a bit cleaner On Sat, Apr 12, 2014 at 4:18 PM, Cecil Westerhof wrote: > 2014-04-12 16:51 GMT+02:00 Patrick Kristiansen : > >> http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java >> > > Thanks. I use now: > (. (. Runtime (g

Re: My experiments with concurrent programming

2014-04-12 Thread Gary Trakhman
I'd recommend running a doall on concurrent-list in order to realize the futures, if you simply deref as you are, then you're going to delay the execution of futures down the line as the sequence is realized bit by bit (except chunking helps you here by accident). You are effectively preventing la

Re: Is it possible to find the number of cores

2014-04-12 Thread Cecil Westerhof
2014-04-12 16:51 GMT+02:00 Patrick Kristiansen : > http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java > Thanks. I use now: (. (. Runtime (getRuntime)) availableProcessors) > On Saturday, April 12, 2014 4:43:56 PM UTC+2, Cecil Westerhof wrote: >> >> I am experimentin

Re: Is it possible to find the number of cores

2014-04-12 Thread Patrick Kristiansen
http://stackoverflow.com/questions/4759570/finding-number-of-cores-in-java On Saturday, April 12, 2014 4:43:56 PM UTC+2, Cecil Westerhof wrote: > > I am experimenting with concurrent programming. Is it possible to > determine how many cores there are on a system? Because it is in the case I > am

Is it possible to find the number of cores

2014-04-12 Thread Cecil Westerhof
I am experimenting with concurrent programming. Is it possible to determine how many cores there are on a system? Because it is in the case I am working on at the moment not profitable to use more threads as there are cores. (That slows the program down.) Can I find out the number of cores of the s

Re: How to work with variables that need to change

2014-04-12 Thread Niels van Klaveren
For storing timing results of expressions, I make use of an agent to store them in, and a modified time macro. (def timings (agent [])) (defmacro send-timing "Evaluates expr and prints the time it took. Returns the value of expr." {:added "1.0"} [agnt expr] `(let [start# (System/curren

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 16:18 GMT+02:00 Fergal Byrne : > That's fine, but note that creating new Calendar objects has an overhead, > using System.currentTimeMillis() is a static OS call which your now() > probably uses, as well as object creation. It probably won't be millisecond > sized, but you can measure y

Re: How to work with variables that need to change

2014-04-12 Thread Fergal Byrne
(defn timed-foo [times n] (let [start (now)] (foo n) (conj times [n (- (now) start)]))) (defn format-time [[n t]] (format "%2d threads took %7d milliseconds" n t)) (->> numbers (reduce timed-foo []) (map format-time) println) On Sat, Apr 12, 2014 at 3:15 PM, Cecil We

Re: How to work with variables that need to change

2014-04-12 Thread Fergal Byrne
Hi Cecil, That's fine, but note that creating new Calendar objects has an overhead, using System.currentTimeMillis() is a static OS call which your now() probably uses, as well as object creation. It probably won't be millisecond sized, but you can measure your (now) using criterium.bench to be su

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 15:49 GMT+02:00 Cecil Westerhof : > 2014-04-12 15:06 GMT+02:00 Fergal Byrne : > or to convert your code to something more functional (and including defns > for now and foo): > >> >> (defn now [] (. System currentTimeMillis)) >> > > I already defined it as: > (defn now [] > (ne

Re: How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
2014-04-12 15:06 GMT+02:00 Fergal Byrne : > For precise timing benchmarks, use criterium [1]. > For simple, gross timing, use > > (map #(time (foo %)) numbers) > That is not going to work, time prints the time instead of giving it back. or to convert your code to something more functional (and

Re: Is it possible to give an atomic message?

2014-04-12 Thread Stephen Gilardi
On Apr 12, 2014, at 7:24 AM, Cecil Westerhof wrote: > 2014-04-12 11:40 GMT+02:00 Max Penet : > Be aware that SimpleDateFormat is not threadsafe though. > > What should I use instead of SimpleDateFormat then? One solution to that facet of the problem is to use a ThreadLocal instance of Simpl

Re: How to work with variables that need to change

2014-04-12 Thread Fergal Byrne
Hi Cecil, For precise timing benchmarks, use criterium [1]. For simple, gross timing, use (map #(time (foo %)) numbers) or to convert your code to something more functional (and including defns for now and foo): (defn now [] (. System currentTimeMillis)) (def numbers '(4 6 8 10)) (defn fo

How to work with variables that need to change

2014-04-12 Thread Cecil Westerhof
At the moment I have the following: (def numbers '(4 6 8 10)) (doseq [number numbers] (foo number)) The call foo generates some output, but I also want to save the time it took for the call to complete. At the moment I am thinking about something like: (def numbers

My experiments with concurrent programming

2014-04-12 Thread Cecil Westerhof
I first had the following function: (defn check-concurrent2 [] (init "concurrent2") (let [c1 (future (do-sequential 1 check-until 4)) c2 (future (do-sequential 2 check-until 4)) c3 (future (do-sequential 3 check-until 4)) c4 (future (do-sequential 4

Re: Is it possible to give an atomic message?

2014-04-12 Thread Cecil Westerhof
2014-04-12 11:40 GMT+02:00 Max Penet : > Be aware that SimpleDateFormat is not threadsafe though. > What should I use instead of SimpleDateFormat then? -- Cecil Westerhof -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send

Re: Is it possible to give an atomic message?

2014-04-12 Thread Max Penet
Be aware that SimpleDateFormat is not threadsafe though. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first