Add tabulate*/list tabulate/list.

This commit is contained in:
Sergiu Ivanov 2022-04-22 15:12:41 +02:00
parent cf49a6f087
commit 47f7f70241
2 changed files with 57 additions and 0 deletions

View file

@ -22,6 +22,7 @@
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
tabulate*/list tabulate/list
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv enumerate-boolean-functions/list
@ -128,6 +129,22 @@
'((#f #t) (#f #t)))
'((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t)))))
(define-syntax-parse-rule (simple-apply func:expr arg:expr)
(func arg))
(: tabulate*/list (All (a b) (-> (Listof (-> (Listof a) b)) (Listof (Listof a))
(Listof (Listof (U a b))))))
(make-tabulate* tabulate*/list append simple-apply)
(module+ test
(test-case "tabulate*/list"
(check-equal? (tabulate*/list (list (λ ([xs : (Listof Boolean)])
(and (car xs) (cadr xs)))
(λ ([xs : (Listof Boolean)])
(or (car xs) (cadr xs))))
'((#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)
(Listof (Listof (U Any b))))))
(define (tabulate func doms)
@ -158,6 +175,18 @@
(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)))))
(: tabulate/list (All (a b) (-> (-> (Listof a) b) (Listof (Listof a))
(Listof (Listof (U a b))))))
(define (tabulate/list func doms)
(tabulate*/list (list func) doms))
(module+ test
(test-case "tabulate/list"
(check-equal? (tabulate/list (λ ([xs : (Listof Boolean)])
(and (car xs) (cadr xs)))
'((#f #t) (#f #t)))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
(: tabulate/pv/boolean (-> Positive-Integer (-> Boolean * Boolean) (Listof (Listof Boolean))))
(define (tabulate/pv/boolean arity func)
(tabulate/pv func (make-list arity '(#f #t))))
@ -505,6 +534,7 @@
tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean
tabulate*/pv/01 tabulate/pv/01
tabulate*/list tabulate/list
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv enumerate-boolean-functions/list

View file

@ -113,6 +113,18 @@ Like @racket[tabulate], but @racket[func]
(tabulate/pv (pvλ (x y) (and x y)) '((#f #t) (#f #t)))
]}
@defproc[(tabulate/list [func (-> (Listof a) b)]
[doms (Listof (Listof a))])
(Listof (Listof (U a b)))]{
Like @racket[tabulate/list], but @racket[func] takes its arguments as a list.
@examples[#:eval functions-evaluator
(tabulate/list (λ ([xs : (Listof Boolean)])
(and (car xs) (car xs)))
'((#f #t) (#f #t)))
]}
@defproc[(tabulate* [funcs (Listof (-> a ... b))]
[doms (List (Listof a) ... a)])
(Listof (Listof (U Any b)))]{
@ -167,6 +179,21 @@ are @seclink["pseudovariadic"]{pseudovariadic}.
'((#f #t) (#f #t)))
]}
@defproc[(tabulate*/list [funcs (Listof (-> (Listof a) b))]
[doms (Listof (Listof a))])
(Listof (Listof (U a b)))]{
Like @racket[tabulate*], but the functions in @racket[funcs] take their
arguments as a list.
@examples[#:eval functions-evaluator
(tabulate*/list (list (λ ([xs : (Listof Boolean)])
(and (car xs) (cadr xs)))
(λ ([xs : (Listof Boolean)])
(or (car xs) (cadr xs))))
'((#f #t) (#f #t)))
]}
@defproc[(tabulate/pv/boolean [arity Positive-Integer] [func (-> Boolean * Boolean)])
(Listof (Listof Boolean))]{