(defmacro try (&body body) "Return a transaction that executes each transaction in BODY atomically from left to right until one succeeds. The return value of the transaction is the value of the transaction that succeeds." (reduce [list 'orelse] body :from-end t))
(defun retry () "Return a transaction that when executed, aborts the current transaction and re-executes it from scratch. The transaction will wait on all variables that have been read so far during the transaction." (trans (throw 'retry (current-tlog))))
(defmacro trans (body) "Create a new anonymous transaction." `(new 'standard-transaction :thunk (lambda () ,body)))
(defun untrans (transaction) (funcall (thunk-of transaction)))
(defmacro deftransaction (name (&rest args) &body body) "Define a new transaction called NAME. DEFTRANSACTION is just like DEFMETHOD but the body is walked into an STM action." `(progn (eval-always (pushnew ',name *trans-funs*)) (defmethod ,name ,args ,(stm `(progn ,@body))) ',name))