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 one mp3
(println (take 1 get-mp3))

This code is gathered from various unrelated Clojure forum posts.  The 
resultant collection, I must admit defeats my understanding.



My first question is the println statement returns "(#/My/files/path/to/Some of/My Music Collection.mp3>)", would someone 
explain this data structure for me, bearing in mind that white spaces 
and commas are synonymous.

It's not a data structure, it's just the way clojure prints out java object:

   user=> f
   #


In the REPL Clojure tries to print out readable output, meaning 
something that can be read again by the reader as input:


   user=> (def a '(1 2 3))
   #'user/a
   user=> #'user/a
   #'user/a
   user=> (var a)
   #'user/a
   user=> map
   #

In the case of object instances, it cannot be printed into such readable 
form, so it uses the #< to indicate this is unreadable:


   user=> #

   clojure.lang.LispReader$ReaderException: java.lang.RuntimeException:
   Unreadable form
 java.lang.RuntimeException: Unreadable form

See also the answer to this stackoverflow question:
http://stackoverflow.com/questions/17263929/clojure-read-string-on-functions

If you want to know more about reader macros:
http://en.wikibooks.org/wiki/Learning_Clojure/Reader_Macros

There's also this chapter from an online beginner's book I recommend 
(you may want to read the stuff before):

http://www.braveclojure.com/read-and-eval/


Please note, while I have programmed a little in the past this does 
not prevent me from asking dumb questions.  Thus finally, if this is 
not the appropriate place for this sort question could you point me in 
the right direction?

You're perfectly fine here, newbies welcome.
In fact your question is about something that isn't much talked or 
written about in clojure.


HTH

--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 concurrent process are
all banging on the same mutable state, racing each other, so to speak.

I can't tell if that's intentional, but if you could describe the algorithm
as work-splitting and result-combining, then it's likely reducers might
work.
http://clojure.com/blog/2012/05/08/reducers-a-library-and-model-for-collection-processing.html

It would help to see a well-commented sequential version where all
necessary state is contained within a loop/recur or a reduce accumulator,
that doesn't rely on dynamic scoping (max-diff and max-factor).

For instance:
Here's how to find the max of a sequence of random ints using reduce:
(reduce
  (fn [cur-max next-candidate] (max cur-max next-candidate))
  ;; initial max
  Long/MIN_VALUE
  (take 1 (repeatedly (partial rand-int 1

To parallelize this, throw the input into a vector, then run it through
reducers/fold.




On Sat, Apr 12, 2014 at 3:18 PM, Cecil Westerhof wrote:

> 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 here by accident).  You are effectively
>> preventing later parts from getting realized until the earlier futures
>> return.
>>
>
> I want the threads to be finished when I do the deinit, that does not
> happen when I use the doall.
>
>
> But of course, there's likely a better approach, we'd need to know what
>> you're trying to do to address it.
>>
>
> I just started playing with Clojure a few days ago, so I am a tabula rasa.
> I attached what I have until now. If it can be improved, I like to know it.
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 (take 1 get-mp3))

This code is gathered from various unrelated Clojure forum posts.  The
resultant collection, I must admit defeats my understanding.


My first question is the println statement returns "(#)", would someone explain
this data structure for me, bearing in mind that white spaces and commas
are synonymous.

Next, I'd like to outline what I'd like to achieve.  I want to learn how to
program in Clojure.  To do this I decided on what I hope is a simple enough
project for a novice.  The goal of this project is to take a number of
files compare them, then identify the duplicates and allow the user to
delete one or more set of duplicate files, creating a selection based on a
common attribute i.e. a set being those files belonging to a distinct
parent directory.


Please note, while I have programmed a little in the past this does not
prevent me from asking dumb questions.  Thus finally, if this is not the
appropriate place for this sort question could you point me in the right
direction?


--
Kind regards

Stephen.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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, 2014 10:07:21 AM UTC-7, James Trunk wrote:
>
> Hi everyone,
>
> I thought some of you might be interested to watch my screencast about game 
> development in Clojure with 
> play-clj
> .
>
> Cheers,
> James
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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))

(def needed-times (atom []))

(doseq [number numbers]
  (let [start   (now)
elapsed (fn elapsed []
  (- (.getTimeInMillis (now)) (.getTimeInMillis start)))]
(foo number)
(swap! needed-times conj (elapsed

--
John



>
> 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 '(4 6 8 10))
>
> (def ^:dynamic needed-times ())
> (doseq [number numbers]
>(let [start (now)]
> (foo number)
> (def ^:dynamic needed-times
>(cons (- (.getTimeInMillis (now))
(.getTimeInMillis start))
>  needed-times
>
>
>
> Also if I need to use several points in time, do I keep nesting ‘let’,
> or is there a better way?
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 things. Changing the use to require fixed this issue.

On Monday, October 28, 2013 11:26:31 PM UTC-4, Aysylu Greenberg wrote:
>
> Thank you for the link, but I don't think what you outlined there is the 
> same as what I have. I'm referring to records by class and protocols 
> defined in the namespace, so I think my situation is different.
>
> On Monday, October 28, 2013 12:08:52 PM UTC-4, red...@gmail.com wrote:
>>
>> I don't know about the rest of this thread, but loom seems to suffer 
>> from what I've outlined in 
>>
>> http://dev.clojure.org/jira/browse/CLJ-322?focusedCommentId=32246&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-32246
>>  
>> pulling in the interface that the protocol generates instead of the 
>> protocol. 
>>
>> On 10/26/13, 5:42 PM, Aysylu Greenberg wrote: 
>> > I was wondering if anybody has found a solution to this problem. I'm 
>> > experiencing the same issue in this project <
>> https://github.com/aysylu/loom>. 
>> > If you disable aot (this line<
>> https://github.com/aysylu/loom/blob/master/project.clj#L9>), 
>> > the tests start failing with a similar error message. 
>> > 
>> > Thanks, 
>> > Aysylu 
>> > 
>> > On Thursday, April 18, 2013 8:27:53 AM UTC-4, Ragnar Dahlén wrote: 
>> >> 
>> >> Thank you for your explanation. I also suspect there is some subtle 
>> >> issue with the class file being used by the different constructors. 
>> >> 
>> >> However, I would be surprised if this behaviour is intended, and that 
>> >> the 'hackery' you proposed is the only, and prefered way of solving 
>> this. 
>> >> 
>> >> To better illustrate the core issue, I updated the example slightly 
>> >> as follows: 
>> >> 
>> >> Premise: 
>> >> defrecordissue.arecord and defrecordissue.protocol constitute some 
>> >> library. 
>> >> 
>> >> 1. defrecordissue.arecord defines a record type, and a function that 
>> >>will return an instance of the record: 
>> >> 
>> >> (ns defrecordissue.arecord) 
>> >> 
>> >> (defrecord ARecord []) 
>> >> 
>> >> (defn make-record 
>> >>   [] 
>> >>   (->ARecord)) 
>> >> 
>> >> 2. defrecordissue.protocol defines a protocol, and extends it to the 
>> >>record type defined in 1. It also defines a public function 
>> >>intended to be used by libraries: 
>> >> 
>> >> (ns defrecordissue.aprotocol 
>> >>   (:require [defrecordissue.arecord]) 
>> >>   (:import [defrecordissue.arecord ARecord])) 
>> >>   
>> >> (defprotocol AProtocol 
>> >>   (afn [this])) 
>> >>   
>> >> (extend-protocol AProtocol 
>> >>   ARecord 
>> >>   (afn [this] 42)) 
>> >> 
>> >> (defn some-public-fn 
>> >>   [] 
>> >>   (afn (defrecordissue.arecord/make-record))) 
>> >> 
>> >> 3. defrecordissue.consumer is a consumer of the library, knows 
>> >>nothing of any protocols or records, but only wants to call a 
>> >>function thats part of the public api: 
>> >> 
>> >> (ns defrecordissue.consumer 
>> >>   (:require [defrecordissue.aprotocol])) 
>> >>   
>> >> (defrecordissue.aprotocol/some-public-fn) 
>> >> 
>> >> This fails with the same root cause. 
>> >> 
>> >> I've created a new branch for this in the GitHub repo. 
>> >> 
>> >> https://github.com/ragnard/defrecordissue/tree/more-realistic 
>> >> 
>> >> /Ragge 
>> >> 
>> >> On Thursday, 18 April 2013 12:19:35 UTC+1, Andrew Sernyak wrote: 
>> >>> 
>> >>> I guess extend-type does changes only to generated java class and the 
>> var defrecordissue.arecord->ARecord 
>> >>> contains the 'old' version of ARecord constructor. Obviously it would 
>> be 
>> >>> weird for defprotocol to change the variable in another namespace. 
>> >>> Especially when you can extend a record from anywhere. 
>> >>> 
>> >>> So If you want to create a record that implements your protocol via 
>> var 
>> >>> from record namespace, you should do some hackery to update that 
>> variable. 
>> >>> I've done a pull-request for you, but using direct constructor will 
>> be more 
>> >>> idiomatic 
>> >>> 
>> >>> ; 
>>  ; this won't work unless you update manualy a variable ->ARecord in 
>> the 
>>  namespace 
>>  ; 
>>  ;(defrecordissue.aprotocol/afn (defrecordissue.arecord/->ARecord)) 
>>  ; 
>>  ; like 
>>  (defmacro from-ns[nmsps & body] 
>>    "launches body from namespace" 
>>    `(binding 
>>   [*ns* (find-ns ~nmsps)] 
>> (eval 
>>    (quote (do ~@body) 
>>  (from-ns 'defrecordissue.arecord 
>>   (import '(defrecordissue.arecord.ARecord)) 
>>   (alter-var-root 
>> ('->ARecord (ns-publics 'defrecordissue.arecord)) 
>> (fn[x

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 here by accident).  You are effectively
> preventing later parts from getting realized until the earlier futures
> return.
>

I want the threads to be finished when I do the deinit, that does not
happen when I use the doall.


But of course, there's likely a better approach, we'd need to know what
> you're trying to do to address it.
>

I just started playing with Clojure a few days ago, so I am a tabula
rasa. I attached what I have until now. If it can be improved, I like to
know it.

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


check-power.clj
Description: Binary data


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: %s" (. time-format format (.
> (now) getTime)) msg)))
> message))
>

I implemented it. Only changed *logger* to logger, because I got the
following message:
Warning: *logger* not declared dynamic and thus is not dynamically
rebindable, but its name suggests otherwise. Please either indicate
^:dynamic *logger* or change the name.

I would have expected that it would make the code slower, but it makes the
code actually faster. The more threads, the more positive result:
2 threads: 3% faster
4 threads: 5% faster
6 threads: 6% faster
7 threads: 8% faster
8 threads: 11% faster

What could be the reason that it makes the code faster? I find it even a
little bit strange, because the logging is only a small part of what I am
doing.

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 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 sure.
>>>
>>
>> The now function is not called often, so it does not really matter, but I
>> changed it anyway. As expected the time is the same, but good code is also
>> nice to have.
>>
>
-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 sure.
>>
>
> The now function is not called often, so it does not really matter, but I
> changed it anyway. As expected the time is the same, but good code is also
> nice to have.
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 your (now) using criterium.bench to be sure.
>

The now function is not called often, so it does not really matter, but I
changed it anyway. As expected the time is the same, but good code is also
nice to have.

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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))
>

That was my first thought also, but that displays nothing.

But the following works:
(doseq [i (->> numbers
 (reduce timed-foo [])
 (map format-time))]
 (println i))

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 better Chris Zheng's lein-midje-doc. Look at my
recent post about it at http://inbits.com (he explains it better in his
video at the end than I would have) - that has saved me weeks of work over
fewer weeks than it saved.


On Sat, Apr 12, 2014 at 5:00 PM, Cecil Westerhof wrote:

> 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 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 
> 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 -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. How do you make a jar file with everything in it?
>>
>> --
>> Cecil Westerhof
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 -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. How do you make a jar file with everything in it?
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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-time)
>  println)
>

I do not know this construction yet. But it works. The only problem is
that the output is:
( 2 threads took6148 milliseconds  4 threads took3069 milliseconds
6 threads took2477 milliseconds  7 threads took2249 milliseconds  8
threads took2079 milliseconds)

and I would like:
 2 threads took6148 milliseconds
 4 threads took3069 milliseconds
 6 threads took2477 milliseconds
 7 threads took2249 milliseconds
 8 threads took2079 milliseconds

How would I do that?

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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. How do you make a jar file with everything in it?


-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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)))
(.availableProcessors runtime) 




> 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 (getRuntime)) availableProcessors)
>>
>
-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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/clojure/core.clj#L6417
clojure.lang.Agent/soloExecutor
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Agent.java#L53

Notice that IFn (any clojure function) implements callable/runnable:
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java#L23

Which is what executors need.


On Sat, Apr 12, 2014 at 11:19 AM, Gary Trakhman wrote:

> 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 later parts from getting realized until the earlier futures
> return.
>
> But of course, there's likely a better approach, we'd need to know what
> you're trying to do to address it.
>
> My first thoughts:
> reducers?
> executors?
> core.async?
>
> You're not actually using the value returned from the future here, so it's
> really a mild abuse of future just to get at the underlying thread-pool and
> binding-conveyance (if you need it).  You could use a lower-level
> abstraction like executors or other things to have more control.
>
>
> On Sat, Apr 12, 2014 at 7:52 AM, Cecil Westerhof 
> wrote:
>
>> 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 check-until 4))]
>>@c1 @c2 @c3 @c4)
>>   (deinit @max-factor))
>>
>> But I did not like it, because it is ‘difficult’ to change. So I changed
>> it to:
>> (defn check-concurrent3 [number]
>>   (init (format "concurrent3 with %d threads" number))
>>   (let [concurrent-list (for [i (range 1 (+ number 1))]
>>  (future (do-sequential i check-until
>> number)))]
>>(doseq [this-thread concurrent-list]
>>   @this-thread))
>>   (deinit @max-factor))
>>
>> Is a little bit clearer and also allows me to do the following:
>> (def threads '(4 6 8 10))
>>
>> (doseq [number threads]
>>(check-concurrent3 number))
>>
>> Is this the right way to do things, or is there a better way?
>>
>> --
>> Cecil Westerhof
>>
>> --
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 (getRuntime)) availableProcessors)
>
>
>
>> 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 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 system where the program is running. Preferable system independent.
>>>
>>> Is there also a possibility to get the load of a system? When the load
>>> is low, I could start more threads as when the load is high.
>>>
>>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 later parts from getting realized until the earlier futures
return.

But of course, there's likely a better approach, we'd need to know what
you're trying to do to address it.

My first thoughts:
reducers?
executors?
core.async?

You're not actually using the value returned from the future here, so it's
really a mild abuse of future just to get at the underlying thread-pool and
binding-conveyance (if you need it).  You could use a lower-level
abstraction like executors or other things to have more control.


On Sat, Apr 12, 2014 at 7:52 AM, Cecil Westerhof wrote:

> 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 check-until 4))]
>@c1 @c2 @c3 @c4)
>   (deinit @max-factor))
>
> But I did not like it, because it is ‘difficult’ to change. So I changed
> it to:
> (defn check-concurrent3 [number]
>   (init (format "concurrent3 with %d threads" number))
>   (let [concurrent-list (for [i (range 1 (+ number 1))]
>  (future (do-sequential i check-until
> number)))]
>(doseq [this-thread concurrent-list]
>   @this-thread))
>   (deinit @max-factor))
>
> Is a little bit clearer and also allows me to do the following:
> (def threads '(4 6 8 10))
>
> (doseq [number threads]
>(check-concurrent3 number))
>
> Is this the right way to do things, or is there a better way?
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 system where the program is running. Preferable system independent.
>>
>> Is there also a possibility to get the load of a system? When the load is
>> low, I could start more threads as when the load is high.
>>
>
-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 system where the program is running. Preferable system independent.
>
> Is there also a possibility to get the load of a system? When the load is 
> low, I could start more threads as when the load is high.
>
> -- 
> Cecil Westerhof 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 system where the program is running. Preferable system independent.

Is there also a possibility to get the load of a system? When the load is
low, I could start more threads as when the load is high.

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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/currentTimeMillis)
 ret# ~expr
 end# (System/currentTimeMillis)]
 (send ~agnt conj {:expression '~expr
   :start start#
   :end end#
   :duration (- end# start#)})
 ret#))

(send-timing timings (Thread/sleep 3000))

@timings
=> [{:expression (Thread/sleep 3000), :duration 3000, :start 1397313034715, 
:end 1397313037715}]

On Saturday, April 12, 2014 2:13:44 PM UTC+2, Cecil Westerhof wrote:
>
> 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 '(4 6 8 10))
>
> (def ^:dynamic needed-times ())
> (doseq [number numbers]
>(let [start (now)]
> (foo number)
> (def ^:dynamic needed-times
>(cons (- (.getTimeInMillis (now)) 
> (.getTimeInMillis start))
>  needed-times
>
> But it looks a ‘little’ cumbersome. Is there a better way to do this?
>
> Also if I need to use several points in time, do I keep nesting ‘let’,
> or is there a better way?
>
> -- 
> Cecil Westerhof 
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 your (now) using criterium.bench to be sure
> .
>

OK, I'll look into a rewrite.



> Also note that reduce in the last line is lazy by default, so ensure to
> wrap it in a doall or vec to make it greedy.
>

The doseq also good I think?

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 Westerhof wrote:

> 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 []
>>   (new java.util.GregorianCalendar))
>>
>> I use it for other things also.
>>
>>
>>
>>> (def numbers '(4 6 8 10))
>>>
>>> (defn foo [n] (reverse (map #(* % %) (range (Math/pow n 5)
>>>
>>> (count (foo 10))
>>>
>>> (defn timed-foo [times n]
>>>   (let [start (now)]
>>> (foo n)
>>> (conj times (- (now) start
>>>
>>> (reduce timed-foo [] numbers) => [0 0 4 14]
>>>
>>
>> I am going to look into this.
>>
>
> I made it in the following:
> (defn timed-foo [times n]
>   (let [start (.getTimeInMillis (now))]
> (foo n)
> (conj times (format "%2d threads took %7d milliseconds"
> n (- (.getTimeInMillis (now)) start)
>
>
> (doseq [i (reduce timed-foo [] numbers)]
>(println i))
> That looks a lot better. Thanks. (It would be better to move the format to
> the doseq I think, but at the moment, it is good enough.)
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 sure.

Also note that reduce in the last line is lazy by default, so ensure to
wrap it in a doall or vec to make it greedy.

Regards

Fergal


On Sat, Apr 12, 2014 at 2:49 PM, Cecil Westerhof wrote:

> 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 including defns
>> for now and foo):
>>
>> (defn now [] (. System currentTimeMillis))
>>
>
> I already defined it as:
> (defn now []
>   (new java.util.GregorianCalendar))
>
> I use it for other things also.
>
>
>
>> (def numbers '(4 6 8 10))
>>
>> (defn foo [n] (reverse (map #(* % %) (range (Math/pow n 5)
>>
>> (count (foo 10))
>>
>> (defn timed-foo [times n]
>>   (let [start (now)]
>> (foo n)
>> (conj times (- (now) start
>>
>> (reduce timed-foo [] numbers) => [0 0 4 14]
>>
>
> I am going to look into this.
>
>
>
>> On Sat, Apr 12, 2014 at 1:13 PM, Cecil Westerhof 
>> wrote:
>>
>>> 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 '(4 6 8 10))
>>>
>>> (def ^:dynamic needed-times ())
>>> (doseq [number numbers]
>>>(let [start (now)]
>>> (foo number)
>>> (def ^:dynamic needed-times
>>>(cons (- (.getTimeInMillis (now))
>>> (.getTimeInMillis start))
>>>  needed-times
>>>
>>> But it looks a 'little' cumbersome. Is there a better way to do this?
>>>
>>> Also if I need to use several points in time, do I keep nesting 'let',
>>> or is there a better way?
>>>
>>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 []
>   (new java.util.GregorianCalendar))
>
> I use it for other things also.
>
>
>
>> (def numbers '(4 6 8 10))
>>
>> (defn foo [n] (reverse (map #(* % %) (range (Math/pow n 5)
>>
>> (count (foo 10))
>>
>> (defn timed-foo [times n]
>>   (let [start (now)]
>> (foo n)
>> (conj times (- (now) start
>>
>> (reduce timed-foo [] numbers) => [0 0 4 14]
>>
>
> I am going to look into this.
>

I made it in the following:
(defn timed-foo [times n]
  (let [start (.getTimeInMillis (now))]
(foo n)
(conj times (format "%2d threads took %7d milliseconds"
n (- (.getTimeInMillis (now)) start)


(doseq [i (reduce timed-foo [] numbers)]
   (println i))

That looks a lot better. Thanks. (It would be better to move the format to
the doseq I think, but at the moment, it is good enough.)

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 including defns
> for now and foo):
>
> 
> (defn now [] (. System currentTimeMillis))
>

I already defined it as:
(defn now []
  (new java.util.GregorianCalendar))

I use it for other things also.




> (def numbers '(4 6 8 10))
>
> (defn foo [n] (reverse (map #(* % %) (range (Math/pow n 5)
>
> (count (foo 10))
>
> (defn timed-foo [times n]
>   (let [start (now)]
> (foo n)
> (conj times (- (now) start
>
> (reduce timed-foo [] numbers) => [0 0 4 14]
>

I am going to look into this.



> On Sat, Apr 12, 2014 at 1:13 PM, Cecil Westerhof 
> wrote:
>
>> 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 '(4 6 8 10))
>>
>> (def ^:dynamic needed-times ())
>> (doseq [number numbers]
>>(let [start (now)]
>> (foo number)
>> (def ^:dynamic needed-times
>>(cons (- (.getTimeInMillis (now))
>> (.getTimeInMillis start))
>>  needed-times
>>
>> But it looks a 'little' cumbersome. Is there a better way to do this?
>>
>> Also if I need to use several points in time, do I keep nesting 'let',
>> or is there a better way?
>>
>
-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 
SimpleDateFormat.

There's an example of that here: 
https://github.com/clojure/clojure/blob/clojure-1.6.0/src/clj/clojure/instant.clj#L160

--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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 foo [n] (reverse (map #(* % %) (range (Math/pow n 5)

(count (foo 10))

(defn timed-foo [times n]
  (let [start (now)]
(foo n)
(conj times (- (now) start

(reduce timed-foo [] numbers) => [0 0 4 14]

[1] https://github.com/hugoduncan/criterium

Regards,

Fergal


On Sat, Apr 12, 2014 at 1:13 PM, Cecil Westerhof wrote:

> 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 '(4 6 8 10))
>
> (def ^:dynamic needed-times ())
> (doseq [number numbers]
>(let [start (now)]
> (foo number)
> (def ^:dynamic needed-times
>(cons (- (.getTimeInMillis (now))
> (.getTimeInMillis start))
>  needed-times
>
> But it looks a 'little' cumbersome. Is there a better way to do this?
>
> Also if I need to use several points in time, do I keep nesting 'let',
> or is there a better way?
>
> --
> Cecil Westerhof
>
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Fergal Byrne, Brenter IT

Author, Real Machine Intelligence with Clortex and NuPIC
https://leanpub.com/realsmartmachines

http://inbits.com - Better Living through
Thoughtful Technology
http://ie.linkedin.com/in/fergbyrne/
https://github.com/fergalbyrne

e:fergalbyrnedub...@gmail.com t:+353 83 4214179
Formerly of Adnet edi...@adnet.ie http://www.adnet.ie

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 '(4 6 8 10))

(def ^:dynamic needed-times ())
(doseq [number numbers]
   (let [start (now)]
(foo number)
(def ^:dynamic needed-times
   (cons (- (.getTimeInMillis (now))
(.getTimeInMillis start))
 needed-times

But it looks a 'little' cumbersome. Is there a better way to do this?

Also if I need to use several points in time, do I keep nesting 'let',
or is there a better way?

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 check-until 4))]
   @c1 @c2 @c3 @c4)
  (deinit @max-factor))

But I did not like it, because it is 'difficult' to change. So I changed
it to:
(defn check-concurrent3 [number]
  (init (format "concurrent3 with %d threads" number))
  (let [concurrent-list (for [i (range 1 (+ number 1))]
 (future (do-sequential i check-until
number)))]
   (doseq [this-thread concurrent-list]
  @this-thread))
  (deinit @max-factor))

Is a little bit clearer and also allows me to do the following:
(def threads '(4 6 8 10))

(doseq [number threads]
   (check-concurrent3 number))

Is this the right way to do things, or is there a better way?

-- 
Cecil Westerhof

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.