我試圖從列表中獲取循環語句的給定索引的項目。如何從球拍語言的給定索引的列表中獲取項目?
(define decision-tree-learning
(lambda (examples attribs default)
(cond
[(empty? examples) default]
[(same-classification? examples) (caar examples)] ; returns the classification
[else (lambda()
(let ((best (choose-attribute attributes examples))
(tree (make-tree best))
(m (majority-value examples))
(i 0)
(countdown (length best)) ; starts at lengths and will decrease by 1
(let loop()
(let example-sub ; here, totally stuck now
; more stuff
(set! countdown (- countdown 1))
; more stuff
)))))])))
在這種情況下,best
是列表,我需要在countdown
指數來獲得它的值。你能幫助我嗎?
不是循環遍歷索引並使用'list-ref',爲什麼不直接在列表中循環? –
另請注意,如果您發現自己在通過列表進行隨機訪問,那麼它可能不是適合您數據的容器類型。球拍(以及Scheme)提供支持恆定時間隨機訪問的* vector *類型。 http://docs.racket-lang.org/guide/vectors.html – dyoo
感謝您的評論。我非常喜歡拍拍朗,我非常欣賞這一切。 – lu1s