From b07cda477f86448443c9fd02c11af7524c2a4c09 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 21 Mar 2022 00:04:21 +0100 Subject: [PATCH] Add tabulate*/pv and tabulate/pv. --- functions.rkt | 28 +++++++++++++++++++++++++--- scribblings/functions.scrbl | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/functions.rkt b/functions.rkt index a2bc77f..31c1dc4 100644 --- a/functions.rkt +++ b/functions.rkt @@ -16,7 +16,7 @@ (provide pseudovariadic-lambda pvλ pseudovariadic-define pvdefine - tabulate* tabulate*/strict tabulate tabulate/strict) + tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv) (unsafe-provide (rename-out [tabulate* tabulate*/untyped] @@ -110,6 +110,18 @@ '((#f #t) (#f #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) (Listof (Listof (U Any b)))))) (define (tabulate func doms) @@ -129,13 +141,23 @@ (test-case "tabulate/strict" (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)))))) + + (: 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) (provide pseudovariadic-lambda pvλ pseudovariadic-define pvdefine - tabulate* tabulate*/strict tabulate*/untyped tabulate tabulate/strict - tabulate/untyped) + tabulate* tabulate*/strict tabulate*/pv tabulate*/untyped + tabulate tabulate/strict tabulate/pv tabulate/untyped) (provide diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index d4c59cd..d24c178 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -18,7 +18,7 @@ Boolean functions, etc.). [sandbox-memory-limit 50]) (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 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))) ]} +@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?] [doms (listof list?)]) (listof list?)]{ @@ -169,6 +180,19 @@ The result of @racket[tabulate*] can be obtained by applying '((#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?)] [doms (listof list?)]) (listof list?)]{