Created
March 25, 2010 04:32
cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; cycle | |
;; Scheme:初心者の質問箱:log00 - http://goo.gl/Clv8 | |
(define (make-cycle ls) | |
(let ((rest ls)) | |
(lambda () | |
(begin0 | |
(car (if (null? rest) | |
(begin | |
(set! rest ls) | |
rest) | |
rest)) | |
(set! rest (cdr rest)))))) | |
(define c (make-cycle '(1 2 3))) | |
(dotimes (i 5) | |
(print (c))) | |
;; 1 | |
;; 2 | |
;; 3 | |
;; 1 | |
;; 2 | |
;; #t | |
; again | |
(define (make-cycle ls) | |
(let ((l ls)) | |
(lambda () | |
(begin0 | |
(car l) | |
(set! l (if (null? (cdr l)) | |
ls | |
(cdr l))))))) | |
(define c (make-cycle '(1 2 3))) | |
(dotimes (i 5) | |
(print (c))) | |
;; 1 | |
;; 2 | |
;; 3 | |
;; 1 | |
;; 2 | |
;; #t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment