networks: Rewrite tabulate-state to use tabulate-state*.

This commit is contained in:
Sergiu Ivanov 2020-06-02 21:29:00 +02:00
parent 42ffc37eeb
commit a34b08e477

View file

@ -715,13 +715,12 @@
;;; a listing the names of the variables of the domain and ending with
;;; the symbol 'f, which indicates the values of the function.
(define (tabulate-state func domains #:headers [headers #t])
(define (st-vals st) (hash-map st (λ (x y) y) #t))
(define tab (for/list ([st (build-all-states domains)])
(append (st-vals st) (list (func st)))))
(define tab (tabulate-state* `(,func) domains #:headers headers))
(cond
[headers
(define vars (append (hash-map domains (λ (x y) x) #t) '(f)))
(cons vars tab)]
;; Replace 'f1 in the headers by 'f.
(match tab [(cons hdrs vals)
(cons (append (drop-right hdrs 1) '(f)) vals)])]
[else tab]))
;;; Like tabulate-state, but assumes the function is a Boolean