Anonymous committed 4253a2b

Implement typed-records based version (negligible performance gains)

Comments (0)

Files changed (2)

 (module lazy-seq
-(lazy-seq make-lazy-seq
+((lazy-seq make-lazy-seq)
  lazy-seq? lazy-seq-realized?
  lazy-null lazy-null?
  lazy-seq->list list->lazy-seq
-(import chicken scheme)
-(use srfi-1 extras)
+(import (except chicken define-record) scheme)
+(use srfi-1 extras (only typed-records define-record))
 (define-record lazy-seq
-  body value)
-(define %make-lazy-seq
-  make-lazy-seq)
-(define (make-lazy-seq body)
-  (%make-lazy-seq body #f))
+  (body : (or boolean procedure))
+  (value : (or boolean pair null)))
 (define-syntax lazy-seq
   (syntax-rules ()
     ((_ body ...)
-      (lambda () body ...)))))
+      (lambda () body ...) #f))))
 (define-record-printer (lazy-seq seq out)
   (display "#<lazy-" out)
   (not (lazy-seq-body seq)))
 (define lazy-null
-  (%make-lazy-seq #f '()))
+  (make-lazy-seq #f '()))
 (define (lazy-null? seq)
   (null? (realized-lazy-seq seq)))
 (define (list->lazy-seq list)
   (if (null? list)
-      (%make-lazy-seq
+      (make-lazy-seq
        #f (cons (car list)
                 (list->lazy-seq (cdr list))))))
-(compile -d0 -O2 -J -s "lazy-seq.scm")
-(compile -d0 -O2 -s "lazy-seq.import.scm")
+(compile -d0 -O3 -specialize -J -s "lazy-seq.scm")
+(compile -d0 -O3 -s "lazy-seq.import.scm")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.