2013-02-10 65 views
1

我很難弄清楚如何在類型球拍中使用本地表格。本地定義球拍類型的用法

什麼是錯的:

(: make-random-emetype-list (Range -> (Listof EmeType))) 
(define (make-random-emetype-list range) 
(local ([define how-many-types (random-integer (Range-lower range) (Range-upper range))] 
     [define: (bld-lst lst remaining) : ((Listof EmeType) Integer -> (Listof EmeType)) 
      (cond [(< remaining 1) lst] 
       [else (bld-lst (cons (new-emetype) lst) (- remaining 1))])])   
(bld-lst '() how-many-types))) 

我敢肯定,問題是,我不太明白在TS-參考語法規範,但它是有一個例子非常有幫助或兩個本地定義的類型化球拍功能。

回答

1

答案是,使用letrec :.那麼,現在我知道了。

(: make-random-emetype-list (Range -> (Listof EmeType))) 
(define (make-random-emetype-list range) 
    (letrec: ([lower : Integer (Range-lower range)] 
     [upper : Integer (Range-upper range)] 
     [how-many : Integer (random-integer lower upper)] 
     [bld-lst : (Integer (Listof EmeType) -> (Listof EmeType)) (lambda: ([remaining : Integer] [lst : (Listof EmeType)]) 
                    (cond [(< remaining 1) lst] 
                      [else (bld-lst (- remaining 1) (cons (new-emetype) lst))]))]) 
    (bld-lst how-many '())))