我对于Racket很新颖。我正在尝试编写一个程序来返回列表中的其他索引元素,并返回整个列表。我有两个单独的方法:一个递归方法给列表的索引元素,如果存在,否则给整个列表。但是,从另一个方法调用一个方法会给我错误。有人可以请指导我如何改变这个程序给我的整个列表,如果没有索引元素存在?例如,这个电话应该给我整个列表从方法中调用方法
(get-nth 2'(a b)); ==> A B
#lang racket
(define get-nth
(lambda (index lst)
(if (= index 0) ; when index is zero
(car lst) ; return the first element
(get-nth (- index 1) ; else recurse with the decrement of index
(cdr lst))))) ; and all but the first element (the rest) of lst
;; test
由于提前,
奖金信息:由于'GET-nth'没有连接到一个对象,一个使用单词“功能”来形容它。 “方法”一词用于描述附加到对象的功能。 – soegaard