Please critique my code (barber problem with core.async)

2015-01-02 Thread Thomas
Happy New to all of you!!! Recently I came across the barber problem (again) and while reading it I thought that code.async would be ideal for this kind of problem. Below is the code I have come up with. I think it does the trick but I am not entirely happy with it, for instance the fact that I

Re: Please critique my code (barber problem with core.async)

2015-01-02 Thread Erik Price
;(async/timeout (* 10 1000)) ;; not sure why this doesn’t work here, would make it portable to clojureScript I think Did you forget to use wrote: > Happy New to all of you!!! > > Recently I came across the barber problem (again) and while reading it I > thought that code.async would be ideal fo

Re: Please critique my code (barber problem with core.async)

2015-01-02 Thread Thomas
On Friday, 2 January 2015 16:45:14 UTC, Erik Price wrote: > > ;(async/timeout (* 10 1000)) ;; not sure why this doesn’t work here, > would make it portable to clojureScript I think > > Did you forget to use > e > .. :) thank you!!! Thomas -- You received this message b

Re: Please critique my code (barber problem with core.async)

2015-01-04 Thread Russell
Looks like the barber's loop doesn't check the "running" atom, so it will never stop... If you wanted to get rid of the atom for counting haircuts you could use a go-loop with a haircut count as an argument. Something like: (go-loop [haircuts 0] (if @running (do (cut-hair!) (recur

Re: Please critique my code (barber problem with core.async)

2015-01-04 Thread Udayakumar Rayala
Your code is simple and easy to understand but it would look to see if atoms can be removed. Also the use go/while loop makes your code not stop and hence atom like @running is required. This is my attempt to solve the problem. I started with your code as the base and refactored it. Following are

Re: Please critique my code (barber problem with core.async)

2015-01-05 Thread Thomas
Thank you all for you valuable feedback. I really appreciate it and the suggestions are really good. Thomas -- 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 member

Re: Please critique my code (barber problem with core.async)

2015-01-06 Thread Gary Verhaegen
I'd suggest taking a look at the alts! function in core.async (or the equivalent alt! macro). On Monday, 5 January 2015, Thomas wrote: > Thank you all for you valuable feedback. I really appreciate it and the > suggestions are really good. > > Thomas > > -- > You received this message because yo