|
322 | 322 | (let loop ([to-cover coverable] |
323 | 323 | [candidates candidates] |
324 | 324 | [coverage '()]) |
325 | | - (cond [(null? to-cover) ; done |
326 | | - (define coverage-names (map car coverage)) |
327 | | - ;; to allow :type to cue the user on unexpanded aliases |
328 | | - ;; only union types can flow here, and any of those could be expanded |
329 | | - (set-box! (current-print-unexpanded) |
330 | | - (append coverage-names (unbox (current-print-unexpanded)))) |
331 | | - ;; reverse here to retain the old ordering from when srfi/1 was |
332 | | - ;; used to process the list sets |
333 | | - (values coverage-names (reverse uncoverable))] ; we want the names |
334 | | - [else |
335 | | - ;; pick the candidate that covers the most uncovered types |
336 | | - (define (covers-how-many? c) |
337 | | - (length (set-intersect (cdr c) to-cover))) |
338 | | - (define-values (next _) |
339 | | - (for/fold ([next (car candidates)] |
340 | | - [max-cover (covers-how-many? (car candidates))]) |
341 | | - ([c (in-list candidates)]) |
342 | | - (let ([how-many? (covers-how-many? c)]) |
343 | | - (if (> how-many? max-cover) |
344 | | - (values c how-many?) |
345 | | - (values next max-cover))))) |
346 | | - (loop (set-subtract to-cover (cdr next)) |
347 | | - (remove next candidates) |
348 | | - (cons next coverage))]))) |
| 325 | + (cond |
| 326 | + [(null? to-cover) ; done |
| 327 | + (define coverage-names (map car coverage)) |
| 328 | + ;; to allow :type to cue the user on unexpanded aliases |
| 329 | + ;; only union types can flow here, and any of those could be expanded |
| 330 | + (set-box! (current-print-unexpanded) |
| 331 | + (append coverage-names (unbox (current-print-unexpanded)))) |
| 332 | + ;; reverse here to retain the old ordering from when srfi/1 was |
| 333 | + ;; used to process the list sets |
| 334 | + (values coverage-names (reverse uncoverable))] ; we want the names |
| 335 | + [else |
| 336 | + ;; pick the candidate that covers the most uncovered types |
| 337 | + (define (covers-how-many? c) |
| 338 | + (length (set-intersect (cdr c) to-cover))) |
| 339 | + (define next |
| 340 | + (for/fold ([next (car candidates)] |
| 341 | + [max-cover (covers-how-many? (car candidates))] |
| 342 | + #:result next) |
| 343 | + ([c (in-list candidates)]) |
| 344 | + (let ([how-many? (covers-how-many? c)]) |
| 345 | + (if (> how-many? max-cover) |
| 346 | + (values c how-many?) |
| 347 | + (values next max-cover))))) |
| 348 | + (loop (set-subtract to-cover (cdr next)) (remove next candidates) (cons next coverage))]))) |
349 | 349 |
|
350 | 350 | ;; arr->sexp : arr -> s-expression |
351 | 351 | ;; Convert an arr (see type-rep.rkt) to its printable form |
|
0 commit comments