如何从列表中以球拍语言给定索引的项目? [英] How do I get an item from a list at a given index in racket language?

查看:68
本文介绍了如何从列表中以球拍语言给定索引的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从列表中的给定索引的列表中获取一项,用于循环语句.

I'm trying to get an item from a list at a given index for a loop statement.

(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索引处获取其值.你能帮我吗?

In this case, best is the list and I need to get its value at the countdown index. Could you help me on that?

推荐答案

示例:

> (list-ref '(a b c d e f) 2)
'c

请参阅:

http://docs.racket-lang.org/reference/pairs.html

这篇关于如何从列表中以球拍语言给定索引的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆