You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
br-parser-tools/collects/tests/mzscheme/ttt/listlib.ss

43 lines
949 B
Scheme

;; --------------------------------------------------------------------------
;; list-library.ss
;; export:
;; collect:
;; (A ((cons B (listof B)) (listof B) (union A C) -> (union A C))
;; ->
;; ((listof B) -> (union A C)))
; #|
; (unit/sig
; (collect filter set-minus subset?)
; (import plt:userspace^)
; |#
(define collect
(lambda (base combine)
(local ((define C
(lambda (l)
(cond
((null? l) base)
(else (combine l (car l) (C (cdr l))))))))
C)))
(define filter
(lambda (p? l)
[(collect null (lambda (_ x rest) (if (p? x) (cons x rest) rest))) l]))
;; set library
(define set-minus
(lambda (set1 set2)
[(collect null (lambda (_ e1 rest) (if (member e1 set2) rest (cons e1 rest))))
set1]))
(define subset?
(lambda (state1 state2)
(cond
((null? state1) #t)
(else (and (member (car state1) state2)
(subset? (cdr state1) state2))))))
; #|
; )
; |#