Add tabulate*/pv and tabulate/pv.
This commit is contained in:
parent
8fb5bab803
commit
b07cda477f
2 changed files with 50 additions and 4 deletions
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
|
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
|
||||||
tabulate* tabulate*/strict tabulate tabulate/strict)
|
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv)
|
||||||
|
|
||||||
(unsafe-provide
|
(unsafe-provide
|
||||||
(rename-out [tabulate* tabulate*/untyped]
|
(rename-out [tabulate* tabulate*/untyped]
|
||||||
|
@ -110,6 +110,18 @@
|
||||||
'((#f #t) (#f #t)))
|
'((#f #t) (#f #t)))
|
||||||
'(((#f #f) (#f #f)) ((#f #t) (#f #t)) ((#t #f) (#f #t)) ((#t #t) (#t #t))))))
|
'(((#f #f) (#f #f)) ((#f #t) (#f #t)) ((#t #f) (#f #t)) ((#t #t) (#t #t))))))
|
||||||
|
|
||||||
|
|
||||||
|
(: tabulate*/pv (All (a b) (-> (Listof (-> a * b)) (Listof (Listof a))
|
||||||
|
(Listof (Listof (U a b))))))
|
||||||
|
(make-tabulate* tabulate*/pv append)
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "tabulate*/pv"
|
||||||
|
(check-equal? (tabulate*/pv (list (pvλ (x y) (and x y))
|
||||||
|
(pvλ (x y) (or x y)))
|
||||||
|
'((#f #t) (#f #t)))
|
||||||
|
'((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t)))))
|
||||||
|
|
||||||
(: tabulate (All (b a ...) (-> (-> a ... b) (List (Listof a) ... a)
|
(: tabulate (All (b a ...) (-> (-> a ... b) (List (Listof a) ... a)
|
||||||
(Listof (Listof (U Any b))))))
|
(Listof (Listof (U Any b))))))
|
||||||
(define (tabulate func doms)
|
(define (tabulate func doms)
|
||||||
|
@ -129,13 +141,23 @@
|
||||||
(test-case "tabulate/strict"
|
(test-case "tabulate/strict"
|
||||||
(check-equal? (tabulate/strict (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
(check-equal? (tabulate/strict (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
||||||
'(((#f #f) (#f)) ((#f #t) (#f)) ((#t #f) (#f)) ((#t #t) (#t))))))
|
'(((#f #f) (#f)) ((#f #t) (#f)) ((#t #f) (#f)) ((#t #t) (#t))))))
|
||||||
|
|
||||||
|
(: tabulate/pv (All (a b) (-> (-> a * b) (Listof (Listof a))
|
||||||
|
(Listof (Listof (U a b))))))
|
||||||
|
(define (tabulate/pv func doms)
|
||||||
|
(tabulate*/pv (list func) doms))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "tabulate/pv"
|
||||||
|
(check-equal? (tabulate/pv (pvλ (x y) (and x y)) '((#f #t) (#f #t)))
|
||||||
|
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
|
||||||
)
|
)
|
||||||
|
|
||||||
(require 'typed)
|
(require 'typed)
|
||||||
(provide
|
(provide
|
||||||
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
|
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
|
||||||
tabulate* tabulate*/strict tabulate*/untyped tabulate tabulate/strict
|
tabulate* tabulate*/strict tabulate*/pv tabulate*/untyped
|
||||||
tabulate/untyped)
|
tabulate tabulate/strict tabulate/pv tabulate/untyped)
|
||||||
|
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
|
|
|
@ -18,7 +18,7 @@ Boolean functions, etc.).
|
||||||
[sandbox-memory-limit 50])
|
[sandbox-memory-limit 50])
|
||||||
(make-evaluator 'typed/racket #:requires '((submod "functions.rkt" typed)))))
|
(make-evaluator 'typed/racket #:requires '((submod "functions.rkt" typed)))))
|
||||||
|
|
||||||
@section{Pseudovariadic functions}
|
@section[#:tag "pseudovariadic"]{Pseudovariadic functions}
|
||||||
|
|
||||||
Functions for @seclink["tabulating"]{tabulating functions} take as an argument
|
Functions for @seclink["tabulating"]{tabulating functions} take as an argument
|
||||||
a function to tabulate or a list of functions to tabulate. Writing the type of
|
a function to tabulate or a list of functions to tabulate. Writing the type of
|
||||||
|
@ -101,6 +101,17 @@ of inputs, and then the output of @racket[func].
|
||||||
(tabulate/strict (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
(tabulate/strict (λ (x y) (and x y)) '((#f #t) (#f #t)))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(tabulate/pv [func (-> a * b)]
|
||||||
|
[doms (Listof (Listof a))])
|
||||||
|
(Listof (Listof (U a b)))]{
|
||||||
|
|
||||||
|
Like @racket[tabulate], but @racket[func]
|
||||||
|
@seclink["pseudovariadic"]{pseudovariadic}.
|
||||||
|
|
||||||
|
@examples[#:eval functions-evaluator
|
||||||
|
(tabulate/pv (pvλ (x y) (and x y)) '((#f #t) (#f #t)))
|
||||||
|
]}
|
||||||
|
|
||||||
@defproc[(tabulate/untyped [funcs procedure?]
|
@defproc[(tabulate/untyped [funcs procedure?]
|
||||||
[doms (listof list?)])
|
[doms (listof list?)])
|
||||||
(listof list?)]{
|
(listof list?)]{
|
||||||
|
@ -169,6 +180,19 @@ The result of @racket[tabulate*] can be obtained by applying
|
||||||
'((#f #t) (#f #t))))
|
'((#f #t) (#f #t))))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(tabulate*/pv [funcs (Listof (-> a * b))]
|
||||||
|
[doms (Listof (Listof a))])
|
||||||
|
(Listof (Listof (U a b)))]{
|
||||||
|
|
||||||
|
Like @racket[tabulate*], but the functions in @racket[funcs]
|
||||||
|
are @seclink["pseudovariadic"]{pseudovariadic}.
|
||||||
|
|
||||||
|
@examples[#:eval functions-evaluator
|
||||||
|
(tabulate*/pv (list (pvλ (x y) (and x y))
|
||||||
|
(pvλ (x y) (or x y)))
|
||||||
|
'((#f #t) (#f #t)))
|
||||||
|
]}
|
||||||
|
|
||||||
@defproc[(tabulate*/untyped [funcs (listof procedure?)]
|
@defproc[(tabulate*/untyped [funcs (listof procedure?)]
|
||||||
[doms (listof list?)])
|
[doms (listof list?)])
|
||||||
(listof list?)]{
|
(listof list?)]{
|
||||||
|
|
Loading…
Reference in a new issue