diff --git a/functions.rkt b/functions.rkt index a21f6ac..fcd33db 100644 --- a/functions.rkt +++ b/functions.rkt @@ -23,7 +23,8 @@ tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01 table->function/list table->function table->function/pv - enumerate-boolean-tables enumerate-boolean-functions) + enumerate-boolean-tables enumerate-boolean-functions + enumerate-boolean-functions/pv) (module+ test (require typed/rackunit)) @@ -288,6 +289,17 @@ (check-false (bool-f1 #f)) (check-false (bool-f1 #t)))) + (: enumerate-boolean-functions/pv (-> Integer (Sequenceof (-> Boolean * Boolean)))) + (define (enumerate-boolean-functions/pv n) + (stream-map (inst table->function/pv Boolean) (enumerate-boolean-tables n))) + + (module+ test + (test-case "enumerate-boolean-functions/pv" + (define bool-f1/pv (stream-first (enumerate-boolean-functions/pv 1))) + (check-false (bool-f1/pv #f)) + (check-false (bool-f1/pv #t)) + (check-exn exn:fail? (λ () (bool-f1/pv #f #f))))) + (module untyped racket (module+ test (require rackunit)) @@ -370,7 +382,8 @@ tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01 table->function/list table->function table->function/pv - enumerate-boolean-tables enumerate-boolean-functions) + enumerate-boolean-tables enumerate-boolean-functions + enumerate-boolean-functions/pv) (require (rename-in (submod 'typed untyped) [tabulate tabulate/untyped] diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index fcce689..5d4052f 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -2,7 +2,7 @@ @(require scribble/example racket/sandbox (for-label typed/racket/base "../functions.rkt" dds/utils typed/racket/unsafe - (only-in racket stream->list))) + (only-in racket stream->list stream-first))) @title[#:tag "functions"]{dds/functions: Formal Functions} @@ -314,6 +314,18 @@ There are @tt{2^(2^n)} Boolean functions of arity @racket[n]. (length (stream->list (enumerate-boolean-functions 2))) ]} +@defproc[(enumerate-boolean-functions/pv [n Integer]) + (Sequenceof (-> Boolean * Boolean))]{ + +Like @racket[enumerate-boolean-functions], but the returned functions are +@seclink["pseudovariadic"]{pseudovariadic}. + +@examples[#:eval functions-evaluator +(define bool-f1/pv (stream-first (enumerate-boolean-functions/pv 2))) +(bool-f1/pv #f #f) +(eval:error (bool-f1/pv #f)) +]} + @section{Random functions} @section{Threshold Boolean functions}