【发布时间】:2012-05-18 09:32:29
【问题描述】:
我正在尝试从给定索引处的列表中获取一个项目以用于循环语句。
(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,不如直接循环遍历列表? -
另请注意,如果您发现自己通过列表进行随机访问,那么它可能不适合您的数据的容器类型。 Racket(以及 Scheme)提供了支持恒定时间随机访问的 vector 类型。 docs.racket-lang.org/guide/vectors.html
-
感谢 cmets。我真的是球拍语言的新手,我很感激这一切。