some clarifying comments
svn: r9046
This commit is contained in:
parent
fb8efd4816
commit
3b1d5169f9
|
@ -40,7 +40,8 @@
|
|||
alist-cons
|
||||
alist-copy
|
||||
alist-delete
|
||||
#;alist-delete!)
|
||||
#; alist-delete! ; lists are immutable
|
||||
)
|
||||
|
||||
;; Extended from R4RS to take an optional comparison argument.
|
||||
(define (my-assoc x lis [= equal?])
|
||||
|
@ -54,7 +55,7 @@
|
|||
(define (alist-delete key alist [= equal?])
|
||||
(filter (lambda (elt) (not (= key (car elt)))) alist))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (alist-delete! key alist [= equal?])
|
||||
(filter! (lambda (elt) (not (= key (car elt)))) alist))
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
(define (delete x lis [= equal?])
|
||||
(filter (lambda (y) (not (= x y))) lis))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define delete! (x lis [= equal?])
|
||||
(filter! (lambda (y) (not (= x y))) lis))
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
(new-tail (recur (delete x tail elt=))))
|
||||
(if (eq? tail new-tail) lis (cons x new-tail))))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (delete-duplicates! lis [elt= equal?])
|
||||
(check-arg procedure? elt= 'delete-duplicates!)
|
||||
(let recur ((lis lis))
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
;; It just zips down contiguous runs of in and out elts in LIS doing the
|
||||
;; minimal number of SET-CDR!s to splice the tail of one run of ins to the
|
||||
;; beginning of the next.
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (filter! pred lis)
|
||||
(check-arg procedure? pred 'filter!)
|
||||
(let lp ((ans lis))
|
||||
|
@ -130,7 +130,7 @@
|
|||
;; It just zips down contiguous runs of in and out elts in LIS doing the
|
||||
;; minimal number of SET-CDR!s to splice these runs together into the result
|
||||
;; lists.
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (partition! pred lis)
|
||||
(check-arg procedure? pred 'partition!)
|
||||
(if (null-list? lis) (values lis lis)
|
||||
|
@ -172,7 +172,7 @@
|
|||
|
||||
;; Inline us, please.
|
||||
(define (my-remove pred l) (filter (lambda (x) (not (pred x))) l))
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (remove! pred l) (filter! (lambda (x) (not (pred x))) l))
|
||||
|
||||
;;; filter.ss ends here
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
|
||||
(define (append-map f lis1 . lists)
|
||||
(really-append-map append-map append f lis1 lists))
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (append-map! f lis1 . lists)
|
||||
(really-append-map append-map! append! f lis1 lists))
|
||||
|
||||
|
@ -185,7 +185,7 @@
|
|||
(lp tail))))))
|
||||
|
||||
;; We stop when LIS1 runs out, not when any list runs out.
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (map! f lis1 . lists)
|
||||
(check-arg procedure? f 'map!)
|
||||
(if (pair? lists)
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
ans lis))))
|
||||
'() lists))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (lset-union! = . lists)
|
||||
(check-arg procedure? = 'lset-union!)
|
||||
(reduce (lambda (lis ans) ; Splice new elts of LIS onto the front of ANS.
|
||||
|
@ -131,7 +131,7 @@
|
|||
(every (lambda (lis) (s:member x lis =)) lists))
|
||||
lis1)))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (lset-intersection! = lis1 . lists)
|
||||
(check-arg procedure? = 'lset-intersection!)
|
||||
(let ((lists (delete lis1 lists eq?))) ; Throw out any LIS1 vals.
|
||||
|
@ -151,7 +151,7 @@
|
|||
lists))
|
||||
lis1)))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (lset-difference! = lis1 . lists)
|
||||
(check-arg procedure? = 'lset-difference!)
|
||||
(let ((lists (filter pair? lists))) ; Throw out empty lists.
|
||||
|
@ -182,7 +182,7 @@
|
|||
b)))))
|
||||
'() lists))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (lset-xor! = . lists)
|
||||
(check-arg procedure? = 'lset-xor!)
|
||||
(reduce (lambda (b a) ; Compute A xor B:
|
||||
|
@ -214,7 +214,7 @@
|
|||
lists)))
|
||||
lis1))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (lset-diff+intersection! = lis1 . lists)
|
||||
(check-arg procedure? = 'lset-diff+intersection!)
|
||||
(cond ((every null-list? lists) (values lis1 '())) ; Short cut
|
||||
|
|
|
@ -127,7 +127,7 @@
|
|||
;; append! append-reverse append-reverse! concatenate concatenate!
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (my-append! . lists)
|
||||
;; First, scan through lists looking for a non-empty one.
|
||||
(let lp ((lists lists) (prev '()))
|
||||
|
@ -161,7 +161,7 @@
|
|||
(if (null-list? rev-head) tail
|
||||
(lp (cdr rev-head) (cons (car rev-head) tail)))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (append-reverse! rev-head tail)
|
||||
(let lp ((rev-head rev-head) (tail tail))
|
||||
(if (null-list? rev-head) tail
|
||||
|
@ -170,10 +170,10 @@
|
|||
(lp next-rev rev-head)))))
|
||||
|
||||
(define (concatenate lists) (reduce-right append '() lists))
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (concatenate! lists) (reduce-right my-append! '() lists))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (my-reverse! lis)
|
||||
(let lp ((lis lis) (ans '()))
|
||||
(if (null-list? lis) ans
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
((pred (car lis)) (lp (cdr lis)))
|
||||
(else lis))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (take-while! pred lis)
|
||||
(check-arg procedure? pred 'take-while!)
|
||||
(if (or (null-list? lis) (not (pred (car lis)))) '()
|
||||
|
@ -104,7 +104,7 @@
|
|||
(values (cons x prefix) suffix))
|
||||
(values '() lis))))))
|
||||
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (span! pred lis)
|
||||
(check-arg procedure? pred 'span!)
|
||||
(if (or (null-list? lis) (not (pred (car lis)))) (values '() lis)
|
||||
|
@ -117,7 +117,7 @@
|
|||
(values lis suffix))))
|
||||
|
||||
(define (break pred lis) (span (lambda (x) (not (pred x))) lis))
|
||||
#;
|
||||
#; ; lists are immutable
|
||||
(define (break! pred lis) (span! (lambda (x) (not (pred x))) lis))
|
||||
|
||||
(define (any pred lis1 . lists)
|
||||
|
|
Loading…
Reference in New Issue
Block a user