Add CONS-STREAM* and CIRCULAR-STREAM macros.
authorJoe Marshall <jmarshall@alum.mit.edu>
Mon, 6 Jul 2015 20:01:55 +0000 (13:01 -0700)
committerJoe Marshall <jmarshall@alum.mit.edu>
Mon, 6 Jul 2015 20:01:55 +0000 (13:01 -0700)
src/runtime/mit-macros.scm
src/runtime/runtime.pkg

index a99db41614cbc5741f97808c42d92210643be178..5e47f7115c6914480c94c9305360972732c87508 100644 (file)
@@ -571,6 +571,17 @@ USA.
           (else
            (ill-formed-syntax form))))))
 
+(define-syntax :circular-stream
+  (er-macro-transformer
+   (lambda (form rename compare)
+     compare                           ;ignore
+     (syntax-check '(KEYWORD EXPRESSION * EXPRESSION) form)
+     (let ((self (make-synthetic-identifier 'SELF)))
+       `(,(rename 'LETREC) ((,self (,(rename 'CONS-STREAM*)
+                                   ,@(cdr form)
+                                   ,self)))
+        ,self)))))
+
 (define-syntax :cons-stream
   (er-macro-transformer
    (lambda (form rename compare)
@@ -578,6 +589,18 @@ USA.
      (syntax-check '(KEYWORD EXPRESSION EXPRESSION) form)
      `(,(rename 'CONS) ,(cadr form)
                       (,(rename 'DELAY) ,(caddr form))))))
+
+(define-syntax :cons-stream*
+  (er-macro-transformer
+   (lambda (form rename compare)
+     compare                           ;ignore
+     (cond ((syntax-match? '(EXPRESSION EXPRESSION) (cdr form))
+           `(,(rename 'CONS-STREAM) ,(cadr form) ,(caddr form)))
+          ((syntax-match? '(EXPRESSION * EXPRESSION) (cdr form))
+           `(,(rename 'CONS-STREAM) ,(cadr form)
+             (,(rename 'CONS-STREAM*) ,@(cddr form))))
+          (else
+           (ill-formed-syntax form))))))
 \f
 (define-syntax :define-integrable
   (er-macro-transformer
index 656e729d4c90843ab0e2a4c046c6ba2ca7738d71..03df60fe0efb540ace3b63410bc18fc7de88e65d 100644 (file)
@@ -4828,9 +4828,11 @@ USA.
          (assert :assert)
          (begin0 :begin0)
          (case :case)
+         (circular-stream :circular-stream)
          (cond :cond)
          (cond-expand :cond-expand)
          (cons-stream :cons-stream)
+         (cons-stream* :cons-stream*)
          (define :define)
          (define-integrable :define-integrable)
          (define-record-type :define-record-type)