Welcome to the CHICKEN Scheme pasting service

naive generators added by ari on Thu Nov 26 20:16:49 2020

;; naive implementation
(define (make-generator transformer start #!optional (retriever identity) #!rest args)
  (let ((next start))
    (lambda ()
      (let ((yield next))
        (set! next (apply transformer (cons next args)))
        (retriever yield)))))

(define (list->generator ls)
  (make-generator
   (lambda (x)
     (if (pair? x)
         (cdr x)
         #!eof))
   ls
   (lambda (x)
     (if (pair? x)
         (car x)
         #!eof))))

;; naive usage
(define listgen
  (list->generator
   '(a b c d)))

(define iotagen
  (make-generator add1 0))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which one-argument R5RS procedure returns 3 when given `'(1 2 3 4)' as input?
Visually impaired? Let me spell it for you (wav file) download WAV