From bf45cf6382bc70abecbc2106940b396cf813646b Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 14 Jul 2020 23:37:38 +0200 Subject: [PATCH] functions: Add list->sbf. --- functions.rkt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/functions.rkt b/functions.rkt index 8c6f537..50055ca 100644 --- a/functions.rkt +++ b/functions.rkt @@ -40,7 +40,8 @@ [tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))] [tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))] [tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))] - [sbf (-> (vectorof number?) tbf?)]) + [sbf (-> (vectorof number?) tbf?)] + [list->sbf (-> (listof number?) sbf?)]) ;; Predicates (contract-out [sbf? (-> any/c boolean?)])) @@ -383,3 +384,10 @@ (module+ test (check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0))) + +;;; Converts a list of numbers to an SBF. The elements of the list +;;; are taken to be the weights of the SBF. +(define list->sbf (compose sbf list->vector)) + +(module+ test + (check-equal? (list->sbf '(1 -1)) (tbf '#(1 -1) 0)))