Fix typo.
[elisp/flim.git] / tram.el
diff --git a/tram.el b/tram.el
index 3a2f61c..18c930b 100644 (file)
--- a/tram.el
+++ b/tram.el
 (luna-define-generic tram-stream-error (stream error)
   "Throw an ERROR of the STREAM.")
 
-(luna-define-method tram-stream-error-name ((trans tram-stream))
-  (intern (format "%s-error" (luna-class-name trans))))
+(luna-define-method tram-stream-error-name ((stream tram-stream))
+  (intern (format "%s-error" (luna-class-name stream))))
 
-(luna-define-method tram-stream-error ((trans tram-stream) error)
-  (throw (tram-stream-error-name trans) error))
+(luna-define-method tram-stream-error ((stream tram-stream) error)
+  (throw (tram-stream-error-name stream) error))
 
 (put '&& 'tram-compose-function #'tram-compose-&&)
 (put '|| 'tram-compose-function #'tram-compose-||)
 
 (defun tram-compose-&& (left right)
   "Multiplicative combinator which composes LEFT and RIGHT operations."
-  `(lambda (trans)
-     (let ((next (closure-call ',left trans)))
-       (closure-call ',right next))))
+  `(lambda (stream)
+     (let ((next
+           ,(if (functionp left)
+                `(closure-call #',left stream)
+              `(closure-call ',left stream))))
+       ,(if (functionp right)
+           `(closure-call #',right next)
+         `(closure-call ',right next)))))
 
 (defun tram-compose-|| (left right)
   "Additive combinator which composes LEFT and RIGHT operations."
-  `(lambda (trans)
+  `(lambda (stream)
      (let (next error)
        (setq error
-            (catch (tram-stream-error-name trans)
-              (setq next (closure-call ',left trans))
+            (catch (tram-stream-error-name stream)
+              (setq next
+                    ,(if (functionp left)
+                          `(closure-call #',left stream)
+                        `(closure-call ',left stream)))
               nil))
        (if error
-          (closure-call ',right trans)
+          ,(if (functionp right)
+               `(closure-call #',right next)
+             `(closure-call ',right next))
         next))))
 
 (defun tram-fold-left (function accu sequence)
-  "Apply FUNCTION to ACCU while folding SEQUENCE left to right."
+  "Apply FUNCTION to ACCU while folding SEQUENCE from left to right."
   (if (null sequence)
       accu
     (tram-fold-left
   (if (not (symbolp (car tram-transaction)))
       tram-transaction
     (let ((combinator
-          (get (pop tram-transaction) 'tram-compose-function))
-         accu)
-      (if (null combinator)
-         (error "Unknown operator")
-       (setq accu
-             (tram-fold-left
-              `(lambda (accu c)
-                 (funcall
-                  #',combinator accu
-                  (if (listp c)
-                      (tram-compose-transaction c)
-                    c)))
-              (if (listp (car tram-transaction))
-                  (tram-compose-transaction (pop tram-transaction))
-                (pop tram-transaction))
-              tram-transaction))
-       (if (and (listp accu) (eq (car accu) 'lambda))
-           (byte-compile accu)
-         accu)))))
+          (get (pop tram-transaction) 'tram-compose-function)))
+      (or combinator
+         (error "Unknown operator"))
+      (tram-fold-left
+       `(lambda (accu c)
+         (funcall
+          #',combinator accu
+          (if (listp c)
+              (tram-compose-transaction c)
+            c)))
+       (if (listp (car tram-transaction))
+          (tram-compose-transaction (pop tram-transaction))
+        (pop tram-transaction))
+       tram-transaction))))
 
 (provide 'tram)