implemented Filtering & partitioning
This commit is contained in:
parent
4e00cfc86a
commit
2f550aee49
|
@ -412,14 +412,37 @@
|
||||||
(filter pred (cdr list)))
|
(filter pred (cdr list)))
|
||||||
(filter pred (cdr list)))))
|
(filter pred (cdr list)))))
|
||||||
|
|
||||||
|
;; means for inter-referential definition
|
||||||
|
(define remove #f)
|
||||||
|
|
||||||
(define (partition pred list)
|
(define (partition pred list)
|
||||||
(values (filter pred list)
|
(values (filter pred list)
|
||||||
(filter (lambda (x) (not (pred x))) list)))
|
(remove pred list)))
|
||||||
|
|
||||||
(define (remove pred list)
|
(define (remove pred list)
|
||||||
(filter (lambda (x) (not (pred x))) list))
|
(filter (lambda (x) (not (pred x))) list))
|
||||||
|
|
||||||
(export filter partition remove)
|
(define (filter! pred list)
|
||||||
|
(let rec ((lst list))
|
||||||
|
(if (null? lst)
|
||||||
|
lst
|
||||||
|
(if (pred (car lst))
|
||||||
|
(begin (set-cdr! lst (rec (cdr lst)))
|
||||||
|
lst)
|
||||||
|
(rec (cdr lst))))))
|
||||||
|
|
||||||
|
;; means for inter-referential definition
|
||||||
|
(define remove! #f)
|
||||||
|
|
||||||
|
(define (partition! pred list)
|
||||||
|
(values (filter! pred list)
|
||||||
|
(remove! pred list)))
|
||||||
|
|
||||||
|
(define (remove! pred list)
|
||||||
|
(filter! (lambda (x) (net (pred x))) list))
|
||||||
|
|
||||||
|
(export filter partition remove
|
||||||
|
filter! partition! remove!)
|
||||||
|
|
||||||
;; # Searching
|
;; # Searching
|
||||||
;; member memq memv
|
;; member memq memv
|
||||||
|
|
Loading…
Reference in New Issue