Commits

Anonymous committed c405ce7

Better implementation of sequence

Comments (0)

Files changed (1)

 
 (define ((sequence parser . parsers) input)
   (let loop ((parsers (cons parser parsers))
-             (parts '())
              (input input))
-    (if (null? parsers)
-        (cons (reverse parts) input)
+    (if (null? (cdr parsers))
+        (car parsers)
         (and-let* ((value ((car parsers) input)))
-          (loop (cdr parsers)
-                (cons (car value) parts)
-                (cdr value))))))
+          (loop (cdr parsers) (cdr value))))))
 
 (define ((char-seq str) input)
   (let ((len (string-length str)))