On 18 February 2013 21:41, Tom Hall <thattommyh...@gmail.com> wrote:
>>> Why does Clojure not need retry or orElse when another implementer of
>>> STM considers them essential?
>> What are retry and orElse? What do they do?
>
> I had hoped to get a reply from someone with experience of both, as
> the quote suggests they are for blocking and choice (The article was
> the first time I'd seen STM so am absolutely not an expert)
>
> From the Haskell docs:
> retry :: STM a
> Retry execution of the current memory transaction because it has seen
> values in TVars which mean that it should not continue (e.g. the TVars
> represent a shared buffer that is now empty). The implementation may
> block the thread until one of the TVars that it has read from has been
> udpated. (GHC only)
> (this is what made me think of watchers in clojure,
> http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/add-watch)
>
> orElse :: STM a -> STM a -> STM a
> Compose two alternative STM actions (GHC only). If the first action
> completes without retrying then it forms the result of the orElse.
> Otherwise, if the first action retries, then the second action is
> tried in its place. If both actions retry then the orElse as a whole
> retries.

They sound like very interesting features. They also sound lower-level
than Clojure's STM -- if a Clojure STM transaction fails, it will
automatically retry until it succeeds (or hits
LockingTransaction/RETRY_LIMIT, currently 10000, when it throws an
exception.) Is this the case in Haskell?

Clojure automatically detects the conditions under which a transaction
is considered to have failed (modulo the need to avoid write skew with
the #'ensure fn) -- does Haskell provide this or are you expected to
do all the checking yourself and call retry directly? Does Haskell
provide a way to easily achieve Clojure's auto-retrying behaviour?

Given the behaviour, I don't think it would be possible to implement
retry or orElse without significant modifications to
LockingTransaction.java and possibly exposing a different set of
abstractions as STM primitives -- the retrying behaviour is written
into the java source:

https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LockingTransaction.java#L252

>> "Santa repeatedly sleeps until wakened by either all of his nine
>> reindeer, back from their holidays, or by a group of three of his ten
>> elves. If awakened by the reindeer, he harnesses each of them to his
>> sleigh, delivers toys with them and finally unharnesses them (allowing
>> them to go off on holiday). If awakened by a group of elves, he shows
>> each of the group into his study, consults with them on toy R&D and
>> finally shows them each out (allowing them to go back to work). Santa
>> should give priority to the reindeer in the case that there is both a
>> group of elves and a group of reindeer waiting."
>
> I think it's a shame he wrote the article around Christmas and chose a
> less well known problem, I have looked at several Clojure Barbershop
> Problem solutions so have a better idea now what an idiomatic solution
> to this sort of problem might be.
>
> Cheers Phil,
> Tom
>
> --
> --
> 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/groups/opt_out.
>
>

-- 
-- 
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/groups/opt_out.


Reply via email to