From 47f7f702412d416e677fbc8952801a85fb2999f8 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 22 Apr 2022 15:12:41 +0200 Subject: [PATCH] Add tabulate*/list tabulate/list. --- functions.rkt | 30 ++++++++++++++++++++++++++++++ scribblings/functions.scrbl | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/functions.rkt b/functions.rkt index ed2ee21..9a34767 100644 --- a/functions.rkt +++ b/functions.rkt @@ -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 diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index f7737d8..0c26fae 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -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))]{