Hacker News new | past | comments | ask | show | jobs | submit login
Comprehensive Clojure STM Article (ociweb.com)
52 points by fogus on Aug 30, 2009 | hide | past | favorite | 4 comments



They must ensure that no data that requires coordinated changes is modified outside an STM transaction.

How does Clojure handle this? In Haskell, the type system ensures that STM operations can only happen where expected. (Reading a TMVar, for example, returns something of type STM (TMVar a). This means that the enclosing function must also return something of the type STM a. To get the actual data out, you run the transaction, which is of type STM a -> IO a. The type system automatically ensures that STM operations don't happen anywhere else.)


In Clojure they require that all operations that affect STM are explicitly done inside a transaction, otherwise an error is raised.


I see, so it complains at runtime when when a transaction is not "in effect" and someone calls a transactional function?


Yes, I believe it is correct.

Keep in mind Clojure is running on top of jvm so they had to, first, figure out a balance between being practical and being "pretty" and, second, work within the constraints of the environment. I think Rich Hickey has done a tremendous job here (and keeps doing it).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: