'conjoin
predicates))
-(define (is-list-of predicate)
- (make-predicate (lambda (object)
- (and (list? object)
- (every predicate object)))
- 'is-list-of
- (list predicate)))
-
-(define (is-non-empty-list-of predicate)
- (make-predicate (lambda (object)
- (and (non-empty-list? object)
- (every predicate object)))
- 'is-non-empty-list-of
- (list predicate)))
-
-(define (is-pair-of car-predicate cdr-predicate)
- (make-predicate (lambda (object)
- (and (pair? object)
- (car-predicate (car object))
- (cdr-predicate (cdr object))))
- 'is-pair-of
- (list car-predicate cdr-predicate)))
-
(define (make-predicate datum-test operator operands)
(if (every predicate? operands)
(tag->predicate
unspecific)
(register-predicate! compound-operator? 'compound-predicate '<= symbol?)))
-(add-boot-init!
- (lambda ()
-
- (define (make-listish-memoizer)
- (simple-list-memoizer eq?
- (lambda (datum-test operator tags)
- (declare (ignore datum-test operator))
- tags)
- make-compound-tag))
-
- (define-compound-operator 'is-list-of
- (make-listish-memoizer))
-
- (define-compound-operator 'is-non-empty-list-of
- (make-listish-memoizer))
-
- (define-compound-operator 'is-pair-of
- (make-listish-memoizer))))
-
(add-boot-init!
(lambda ()
patterned-tags
tag-name
caller))
- (make-data-test (lambda () tag))
+ (apply make-data-test
+ (map-template-pattern pattern
+ patterned-tags
+ tag->predicate
+ caller))
tagging-strategy
(get-template)
(match-template-pattern pattern
(define (template-pattern->names pattern)
(map template-pattern-element-name pattern))
-
+\f
(define (match-template-pattern pattern values value-predicate caller)
(guarantee list? values caller)
(if (not (= (length values) (length pattern)))
(else (error:not-a template-pattern? pattern caller))))
pattern
object))
-\f
+
(define-record-type <parameter-binding>
(make-parameter-binding element value)
parameter-binding?
(parameter-binding-element binding))
(list (parameter-binding-value binding))
(parameter-binding-value binding)))
-
+\f
(add-boot-init!
(lambda ()
(register-predicate! parametric-predicate? 'parametric-predicate
tags1
tags2))))
(parametric-tag-bindings tag1)
- (parametric-tag-bindings tag2)))))))
\ No newline at end of file
+ (parametric-tag-bindings tag2)))))))
+
+(define is-list-of)
+(define is-non-empty-list-of)
+(define is-pair-of)
+(add-boot-init!
+ (lambda ()
+ (set! is-list-of
+ (predicate-template-constructor
+ (make-predicate-template 'is-list-of
+ '((? elt-predicate))
+ predicate-tagging-strategy:optional
+ (lambda (elt-predicate)
+ (lambda (object)
+ (list-of-type? object elt-predicate))))))
+ (set! is-non-empty-list-of
+ (predicate-template-constructor
+ (make-predicate-template 'is-non-empty-list-of
+ '((? elt-predicate))
+ predicate-tagging-strategy:optional
+ (lambda (elt-predicate)
+ (lambda (object)
+ (and (pair? object)
+ (list-of-type? object
+ elt-predicate)))))))
+ (set! is-pair-of
+ (predicate-template-constructor
+ (make-predicate-template 'is-non-empty-list-of
+ '((? car-predicate) (? cdr-predicate))
+ predicate-tagging-strategy:optional
+ (lambda (car-predicate cdr-predicate)
+ (lambda (object)
+ (and (pair? object)
+ (car-predicate (car object))
+ (cdr-predicate (cdr object))))))))
+ unspecific))
\ No newline at end of file