1 ;;; net-trans.el --- basic transaction framework for internet protocols
3 ;; Copyright (C) 2000 Daiki Ueno
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
8 ;; This file is part of FLIM (Faithful Library about Internet Message).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
33 (eval-when-compile (require 'cl))
36 (luna-define-class net-transaction ())
38 (luna-define-internal-accessors 'net-transaction))
40 (luna-define-generic net-transaction-error-name (trans)
41 "Return error symbol of the TRANSACTION.")
43 (luna-define-generic net-transaction-error (trans error)
44 "Throw an ERROR of the TRANSACTION.")
46 (luna-define-method net-transaction-error-name ((trans net-transaction))
47 (intern (format "%s-error" (luna-class-name trans))))
49 (luna-define-method net-transaction-error ((trans net-transaction) error)
50 (throw (net-transaction-error-name trans) error))
52 (defvar net-transaction-combinator-alist
53 '((&& net-transaction-compose-&&)
54 (|| net-transaction-compose-||)))
56 (defun net-transaction-compose-&& (left right)
57 "Multiplicative combinator which composes LEFT and RIGHT operations."
59 (let ((next (funcall #',left trans)))
60 (funcall #',right next))))
62 (defun net-transaction-compose-|| (left right)
63 "Additive combinator which composes LEFT and RIGHT operations."
67 (catch (net-transaction-error-name trans)
68 (setq next (funcall #',left trans))
71 (funcall #',right trans)
74 (defun net-transaction-fold-left (function accu sequence)
75 "Apply FUNCTION to ACCU while folding SEQUENCE left to right."
78 (net-transaction-fold-left
79 function (funcall function accu (car sequence))
82 (defun net-transaction-compose-commands (commands)
83 "Compose transaction-function from COMMANDS."
85 (assq (pop commands) net-transaction-combinator-alist))
87 (if (listp (car commands))
88 (net-transaction-compose-commands (pop commands))
91 (error "Unknown operator")
93 (net-transaction-fold-left
96 #',(nth 1 combinator) accu
98 (net-transaction-compose-commands c)
101 (if (and (listp accu) (eq (car accu) 'lambda))
107 ;;; net-trans.el ends here