Merge branch 'master' of github.com:wasabiz/picrin

This commit is contained in:
Yuichi Nishiwaki 2014-03-19 18:31:07 +09:00
commit 8542bc479e
1 changed files with 8 additions and 11 deletions

View File

@ -51,19 +51,16 @@
;; list= ;; list=
(define (not-pair? x) (define (not-pair? x)
(not (pair? x))) (not (pair? x)))
;; detects circular list using Floyd's cycle-finding algorithm
(define (circular-list? x) (define (circular-list? x)
(and (pair? x) (let rec ((rapid x) (local x))
(let rec ((lst (cdr x))) (if (and (pair? rapid) (pair? (cdr rapid)))
(cond ((not-pair?) #f) (if (eq? (cddr rapid) (cdr local))
((null? lst) #f) #t
((eq? x lst) #t) (rec (cddr rapid) (cdr local)))
(else (rec (cdr lst))))))) #f)))
;; if list? is support circular list, (define proper-list? list?) (define proper-list? list?)
(define (proper-list? x)
(if (not (circular-list? x))
(list? x)))
(define (dotted-list? x) (define (dotted-list? x)
(and (pair? x) (and (pair? x)