Gist updated to use watchers for table state reporting, instead of coupling
the reporting with the transaction.
Also, as cgrand pointed to me, note that this implementation using the STM
is somehow related to the "Monitor solution" described in :
http://en.wikipedia.org/wiki/Dining_philosophers_pr
of course there's a little rampant bug, (take) should read (take (count
phils) ..) not (take (* 3 (count phils)...), gist updated.
2010/12/30 Laurent PETIT
> And here's the gist, if it's more readable :
> https://gist.github.com/759364
>
> 2010/12/30 Laurent PETIT
>
> Here's my attempt at provi
And here's the gist, if it's more readable : https://gist.github.com/759364
2010/12/30 Laurent PETIT
> Here's my attempt at providing a simple solution to this problem:
>
> 18 lines of code, not too bad if it's not buggy ;-)
>
> ;;; Dining philosophers. Solution using Clojure STM.
> ;;; What are
Here's my attempt at providing a simple solution to this problem:
18 lines of code, not too bad if it's not buggy ;-)
;;; Dining philosophers. Solution using Clojure STM.
;;; What are our identities?
;;; The problem talks about forks, and philosophers.
;;; Conceptually, forks have a "taken-by
Edit: Mine has a minor bug: The conditional in eat should be inside
the same dosync as the result, so it should be:
(if (not (dosync (let [first-fork @(nth...) second-fork @(nth...)]
(if (and first-fork second-fork)
(do (ref-set ...) (ref-set ...)))
(and first
Yeah, I'm new to clojure, but your code seems a tad wonky. I just gave
dining philosophers a shot in clojure, and it was 32 non-empty non-
comment lines (though the printing blocks are non-atomic, so the
printout, while readable, is slightly bizarre at moments).
Okay, the first thing I have to say
Hi Todd,
2010/12/29 Todd
> Thanks Ken, Mark, David and Alex for your comments regarding Binary Search
> trees. I've read that thread several times, and ordered Okasaki's Purely
> Functional Data Structures, too. I'll return to this a bit later.
>
> Meanwhile, I decided to tackle learning Clojure