Matthew Butterick 9 years ago
parent 6047bd2452
commit 5bcfae5aed

@ -19,7 +19,8 @@
(define-type QuadAttrValue Any)
(define-predicate QuadAttrValue? QuadAttrValue)
(define-type QuadAttrs (HashTable QuadAttrKey QuadAttrValue))
(define-type HashableList (All (A) (Rec duo (U Null (List* QuadAttrKey A duo)))))
(define-type HashableList (Rec duo (U Null (List* QuadAttrKey Any duo))))
(define-predicate HashableList? HashableList)
(: quad-attrs? (Any . -> . Boolean))

@ -1,6 +1,6 @@
#lang racket/base
(require "utils.rkt" "wrap.rkt" "quads-typed.rkt" "world.rkt" racket/list racket/format)
(require "utils-typed.rkt" "quads-typed.rkt" "world-typed.rkt" racket/list racket/format)
(require rackunit)
(check-equal? (join-attrs (list (box '(width 10)) (box #f "foobar") (hash 'x 10) (list 'width 20)))
(check-equal? (join-attrs (list (box '(width 10)) (quad-attrs (box '(x 10))) (list 'width 20)))
(list (cons 'width 10) (cons 'x 10) (cons 'width 20)))

@ -13,24 +13,16 @@
(: pairs? (Any . -> . Boolean))
(define (pairs? x) (and (list? x) (andmap pair? x)))
;; push together multiple attr sources into one list of pairs.
;; mostly a helper function for the two attr functions below.
(: join-attrs ((Listof (U Quad QuadAttrs HashableList)) . -> . Any)) ;; temp: end with QuadAttrs
(provide join-attrs)
(: join-attrs ((Listof (U Quad QuadAttrs HashableList)) . -> . (Listof QuadAttrPair)))
(define (join-attrs quads-or-attrs-or-lists)
(append-map (inst hash->list QuadAttrs HashableList) (filter-not false? (map (λ(x)
((inst append-map QuadAttrPair QuadAttrs) (inst hash->list QuadAttrKey QuadAttrValue) (map (λ(x)
(cond
[(quad? x) (quad-attrs x)]
[(quad-attrs? x) x]
[(quad-attrs? x) (cast x QuadAttrs)]
[(hashable-list? x) (quadattrs (cast x (Listof Any)))]
[else #f])) quads-or-attrs-or-lists))))
[else (cast hash QuadAttrs)])) quads-or-attrs-or-lists)))
#|
(append-map hash->list (filter-not false? (map (λ(x)
(cond
[(quad? x) (quad-attrs x)]
[(quad-attrs? x) x]
[(hashable-list? x) (quadattrs x)]
[else #f])) quads-or-attrs-or-lists)))
|#

Loading…
Cancel
Save