1 ;;; tram.el --- basic session 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.
34 (eval-when-compile (require 'cl))
37 (luna-define-class tram-stream ())
39 (luna-define-internal-accessors 'tram-stream))
41 (luna-define-generic tram-stream-error-name (stream)
42 "Return error symbol of the STREAM.")
44 (luna-define-generic tram-stream-error (stream error)
45 "Throw an ERROR of the STREAM.")
47 (luna-define-method tram-stream-error-name ((trans tram-stream))
48 (intern (format "%s-error" (luna-class-name trans))))
50 (luna-define-method tram-stream-error ((trans tram-stream) error)
51 (throw (tram-stream-error-name trans) error))
53 (put '&& 'tram-compose-function #'tram-compose-&&)
54 (put '|| 'tram-compose-function #'tram-compose-||)
56 (defun tram-compose-&& (left right)
57 "Multiplicative combinator which composes LEFT and RIGHT operations."
61 `(closure-call #',left trans)
62 `(closure-call ',left trans))))
63 ,(if (functionp right)
64 `(closure-call #',right next)
65 `(closure-call ',right next)))))
67 (defun tram-compose-|| (left right)
68 "Additive combinator which composes LEFT and RIGHT operations."
72 (catch (tram-stream-error-name trans)
75 `(closure-call #',left trans)
76 `(closure-call ',left trans)))
79 ,(if (functionp right)
80 `(closure-call #',right next)
81 `(closure-call ',right next))
84 (defun tram-fold-left (function accu sequence)
85 "Apply FUNCTION to ACCU while folding SEQUENCE left to right."
89 function (funcall function accu (car sequence))
93 (defmacro tram-define-transaction (name tram-transaction &optional doc)
94 "Set NAME the compiled code of TRAM-TRANSACTION."
96 ,(tram-compose-transaction (eval tram-transaction))))
97 (defconst ,name transaction ,doc)))
100 (defun tram-compose-transaction (tram-transaction)
101 "Compose transaction-function from TRAM-TRANSACTION."
102 (if (not (symbolp (car tram-transaction)))
105 (get (pop tram-transaction) 'tram-compose-function))
107 (if (null combinator)
108 (error "Unknown operator")
115 (tram-compose-transaction c)
117 (if (listp (car tram-transaction))
118 (tram-compose-transaction (pop tram-transaction))
119 (pop tram-transaction))
121 (if (and (listp accu) (eq (car accu) 'lambda))
127 ;;; tram.el ends here