Add tabulate/pv/boolean and tabulate*/pv/boolean.

This commit is contained in:
Sergiu Ivanov 2022-04-09 02:03:51 +02:00
parent c19d18122c
commit 1b22ba4a7e
2 changed files with 67 additions and 2 deletions

View File

@ -17,7 +17,8 @@
(provide
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv)
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean)
(module+ test
(require typed/rackunit))
@ -147,6 +148,26 @@
(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/pv/boolean (-> Integer (-> Boolean * Boolean) (Listof (Listof Boolean))))
(define (tabulate/pv/boolean arity func)
(tabulate/pv func (make-list arity '(#f #t))))
(module+ test
(test-case "tabulate/pv/boolean"
(check-equal? (tabulate/pv/boolean 2 (pvλ (x y) (and x y)))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
(: tabulate*/pv/boolean (-> Integer (Listof (-> Boolean * Boolean))
(Listof (Listof Boolean))))
(define (tabulate*/pv/boolean arity funcs)
(tabulate*/pv funcs (make-list arity '(#f #t))))
(module+ test
(test-case "tabulate*/pv/boolean"
(check-equal? (tabulate*/pv/boolean 2 (list (pvλ (x y) (and x y))
(pvλ (x y) (or x y))))
'((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t)))))
(module untyped racket
(module+ test
(require rackunit))
@ -207,7 +228,8 @@
(provide
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
tabulate* tabulate*/strict tabulate*/pv
tabulate tabulate/strict tabulate/pv)
tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]

View File

@ -166,6 +166,49 @@ are @seclink["pseudovariadic"]{pseudovariadic}.
'((#f #t) (#f #t)))
]}
@defproc[(tabulate/pv/boolean [arity Integer] [func (-> Boolean * Boolean)])
(Listof (Listof Boolean))]{
Like @racket[tabulate/pv], but assumes the domains of all variables of the
function are Boolean. The arity of @racket[func] must be explicitly supplied.
@examples[#:eval functions-evaluator
(tabulate/pv/boolean 2 (pvλ (x y) (and x y)))
]
Explicitly supplying the arity is necessary because the actual arity of
a pseudovariadic function cannot be determined programmatically. Note that
@racket[tabulate] can be applied directly to a function, but the type of
@racket[tabulate] requires a cast is required the domains argument
@racket[doms].
@examples[#:eval functions-evaluator
(tabulate (λ (x y) (and x y))
(cast (make-list 2 '(#f #t))
(List (Listof Boolean) (Listof Boolean))))
]
This cast is what makes it necessary to resort to pseudovariadic functions and
explicit @racket[arity] to be able to write a type for
@racket[tabulate/pv/boolean].
See also @secref{fuctions/untyped} for simpler, but untyped version of
this function.
}
@defproc[(tabulate*/pv/boolean [arity Integer]
[func (Listof (-> Boolean * Boolean))])
(Listof (Listof Boolean))]{
Like @racket[tabulate/pv/boolean], but takes a list of functions of the
same arity.
@examples[#:eval functions-evaluator
(tabulate*/pv/boolean 2 (list (pvλ (x y) (and x y))
(pvλ (x y) (or x y))))
]}
@section{Constructing functions}
@section{Random functions}