-2
我知道如何獲得第一n
元素的列表,獲取在DrRacket列表中最後n個元素,而無需列表裁判
(define (countup n ls)
(cond
[(zero? n) '()]
[else (cons (first ls) (countup (sub1 n) (rest ls)))]))
,但我怎麼能爲最後做這樣的事情n
列表中的元素(不使用list-ref)?
如果我打電話(countup 3 '(a b c d e))
,我得到(list a b c)
。我需要能夠輸入(counter 3 '(a b c d e))
並獲得(list c d e)
。
如果數字n
大於列表長度,我需要錯誤消息。
我需要能夠做到這一點而不使用take-right – KrissyMichaelsson
altho I謝謝你的幫助,我不能使用trim,take,move或list-ref。 – KrissyMichaelsson
我不使用任何這些,我只是定義了兩個名爲'move'和'trim-left'的幫助程序。無需使用額外的助手即可,無法輕鬆解決此問題。 –