Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 3.09 KB | None | 0 0
  1. (define (types-in-ref-cycle tn0)
  2.   ;; todo is (listof Type): a worklist accumulator
  3.   ;; current-cycle is (listof Type): a context preserving accumulator
  4.   (local [(define (fn-for-type-name tn todo current-cycle)
  5.             (if (member? tn0 current-cycle)
  6.                 current-cycle
  7.                 (fn-for-typedef (lookup-typedef tn) todo current-cycle)))
  8.          
  9.           (define (fn-for-typedef td todo current-cycle)
  10.             (fn-for-type (typedef-type td) todo current-cycle))
  11.          
  12.           (define (fn-for-type t todo current-cycle)
  13.             (cond [(string? t)    (fn-for-type-name t todo current-cycle)]
  14.                   [(primitive? t) (fn-for-lot todo current-cycle)]
  15.                   [(distinct? t)  (fn-for-lot todo current-cycle)]
  16.                   [(oneof? t)     (fn-for-lot (append (oneof-subclasses t) todo) current-cycle)]
  17.                   [(compound? t)  (fn-for-lot (append (compound-types t) todo) current-cycle)]))
  18.          
  19.           (define (fn-for-lot todo current-cycle)
  20.             (cond [(empty? todo) empty]
  21.                   [else
  22.                    (fn-for-type (first todo) (rest todo) (cond [(and (string? (first todo))
  23.                                                                      (not (or (string=? "String" (first todo))
  24.                                                                               (string=? "Image" (first todo))
  25.                                                                               (string=? "Number" (first todo))))
  26.                                                              
  27.                                                                      (local [(define c (typedef-type (lookup-typedef (first todo))))
  28.  
  29.                                                                              (define (compound-or-oneof--c? type)
  30.                                                                                (or (compound? (typedef-type (lookup-typedef type)))
  31.                                                                                    (oneof? (typedef-type (lookup-typedef type)))))
  32.  
  33.                                                                              (define (compound-or-oneof--of? type)
  34.                                                                                (or (compound? type)
  35.                                                                                    (oneof? type)))]
  36.                                                                        
  37.                                                                        (cond [(compound? c) (ormap compound-or-oneof--c? (compound-types c))]
  38.                                                                              [(oneof? c) (ormap compound-or-oneof--of? (oneof-subclasses c))])))
  39.                                                                
  40.                                                                 (cons (first todo) current-cycle)]
  41.                                                                
  42.                                                                [else current-cycle]))]))]
  43.    
  44.     (fn-for-type-name tn0 empty empty)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement