如何在scheme中创建列表列表?

如何在scheme中创建列表列表?,scheme,nested-lists,chicken-scheme,Scheme,Nested Lists,Chicken Scheme,我可能在R5RS文档中遗漏了这一点,但如何在(Chicken)Scheme中创建列表列表?我希望能够获取一个列表,a,调用(列表引用ab),将结果分配给c,然后调用(列表引用cd),其中b和d是索引值 编辑:为了澄清,假设我有以下列表: (define citrus (list "oranges" "limes")) (define apples (list "macintosh" "rome" "delicious")) 然后我想创建一个名为水果的列表,其中柑橘和苹果作为列表条目。以下是创建

我可能在R5RS文档中遗漏了这一点,但如何在(Chicken)Scheme中创建列表列表?我希望能够获取一个列表,
a
,调用
(列表引用ab)
,将结果分配给
c
,然后调用
(列表引用cd)
,其中
b
d
是索引值

编辑:为了澄清,假设我有以下列表:

(define citrus (list "oranges" "limes"))
(define apples (list "macintosh" "rome" "delicious"))

然后我想创建一个名为
水果
的列表,其中
柑橘
苹果
作为列表条目。

以下是创建列表的方法:

(list (list 1 2) (list 3 4))   
或者更简单:

'((1 2) (3 4))
现在,如果已经将其他子列表定义为单独的列表,请将它们放在外部列表中,再次对其调用
list

(define the-first  (list 1 2))
(define the-second (list 3 4))
(define list-of-lists (list the-first the-second))
list-of-lists
=> '((1 2) (3 4)) 
要访问给定两个索引的位置,请执行以下操作-记住,索引是基于零的:

(define lst '((1 2) (3 4)))
(list-ref (list-ref lst 1) 0)
=> 3
因此,问题中的第一个示例如下所示:

(define a '((1 2) (3 4)))
(define b 1)
(define c (list-ref a b))
(define d 0)
(list-ref c d)
=> 3
(define citrus (list "oranges" "limes"))
(define apples (list "macintosh" "rome" "delicious"))
(define fruit (list citrus apples)) ; here's the list of lists
第二个示例(编辑后)如下所示:

(define a '((1 2) (3 4)))
(define b 1)
(define c (list-ref a b))
(define d 0)
(list-ref c d)
=> 3
(define citrus (list "oranges" "limes"))
(define apples (list "macintosh" "rome" "delicious"))
(define fruit (list citrus apples)) ; here's the list of lists
现在,要访问一个元素,我们必须首先传递最外层列表的索引(假设我们想要苹果,它位于最外层列表的索引
1
),然后传递最内层列表的索引(假设我们想要一个苹果机,它位于苹果子列表的索引
0
):


如果要创建包含这些列表的列表,只需将它们作为参数调用
list

(define fruit (list citrus apples))

(list-ref (list-ref fruit 0) 1)
=> "lime"

代码错误,给定的索引返回的是
“limes”
,而不是
“rome”