From 5eaba0326f827f9fcb50f9bcaea73bba904cd98a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 2 Jul 2017 12:09:57 -0700 Subject: [PATCH] refac --- pitfall/restructure/bitfield.rkt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pitfall/restructure/bitfield.rkt b/pitfall/restructure/bitfield.rkt index d902c582..9ade64a9 100644 --- a/pitfall/restructure/bitfield.rkt +++ b/pitfall/restructure/bitfield.rkt @@ -8,13 +8,15 @@ https://github.com/mbutterick/restructure/blob/master/src/Bitfield.coffee |# (define-subclass Streamcoder (Bitfield type [flags empty]) + (unless (andmap (λ (f) (or (key? f) (not f))) flags) + (raise-argument-error 'Bitfield "list of keys" flags)) (define/augment (decode stream . _) (define flag-hash (mhasheq)) (for* ([val (in-value (send type decode stream))] [(flag i) (in-indexed flags)] #:when flag) - (hash-set! flag-hash (if (symbol? flag) flag (string->symbol "~a" flag)) (bitwise-bit-set? val i))) + (hash-set! flag-hash flag (bitwise-bit-set? val i))) flag-hash) (define/override (size . _) (send type size))