Add table->unary-function.
This commit is contained in:
parent
b9b224fc6a
commit
09c14907ca
2 changed files with 26 additions and 1 deletions
|
@ -23,7 +23,7 @@
|
||||||
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
|
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
|
||||||
tabulate*/list tabulate/list
|
tabulate*/list tabulate/list
|
||||||
tabulate*/list/boolean tabulate/list/boolean tabulate*/list/01 tabulate/list/01
|
tabulate*/list/boolean tabulate/list/boolean tabulate*/list/01 tabulate/list/01
|
||||||
table->function/list table->function table->function/pv
|
table->function/list table->unary-function table->function table->function/pv
|
||||||
enumerate-boolean-tables enumerate-boolean-functions
|
enumerate-boolean-tables enumerate-boolean-functions
|
||||||
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
||||||
random-boolean-table random-boolean-function random-boolean-function/list
|
random-boolean-table random-boolean-function random-boolean-function/list
|
||||||
|
@ -292,6 +292,19 @@
|
||||||
(check-true (negation/list '(#f)))
|
(check-true (negation/list '(#f)))
|
||||||
(check-false (negation/list '(#t)))))
|
(check-false (negation/list '(#t)))))
|
||||||
|
|
||||||
|
(: table->unary-function (All (a b) (-> (Listof (List a b)) (-> a b))))
|
||||||
|
(define (table->unary-function table)
|
||||||
|
(define ht-tab
|
||||||
|
(for/hash ([line (in-list table)]) : (HashTable a b)
|
||||||
|
(values (car line) (cadr line))))
|
||||||
|
(λ (x) (hash-ref ht-tab x)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "table->unary-function"
|
||||||
|
(define unary-negation (table->unary-function '((#t #f) (#f #t))))
|
||||||
|
(check-false (unary-negation #t))
|
||||||
|
(check-true (unary-negation #f))))
|
||||||
|
|
||||||
(: table->function (All (a) (-> (Listof (Listof a)) (-> a * a))))
|
(: table->function (All (a) (-> (Listof (Listof a)) (-> a * a))))
|
||||||
(define (table->function table)
|
(define (table->function table)
|
||||||
(define func (table->function/list table))
|
(define func (table->function/list table))
|
||||||
|
|
|
@ -344,6 +344,18 @@ last element.
|
||||||
(and/list '(#t #t))
|
(and/list '(#t #t))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(table->unary-function [table (Listof (List a b))])
|
||||||
|
(-> a b)]{
|
||||||
|
|
||||||
|
Like @racket[table->function/list], but the @racket[table] contains
|
||||||
|
exactly 2 columns: one column for the inputs and one column for the
|
||||||
|
outputs, and the result is a unary function.
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(let ([unary-negation (table->unary-function '((#t #f) (#f #t)))])
|
||||||
|
(unary-negation #t))
|
||||||
|
]}
|
||||||
|
|
||||||
@defproc[(table->function [table (Listof (Listof a))])
|
@defproc[(table->function [table (Listof (Listof a))])
|
||||||
(-> a * a)]{
|
(-> a * a)]{
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue