【发布时间】:2014-07-21 14:23:48
【问题描述】:
我需要编写一个方案函数(iterator (start step end)),它返回一个函数,该函数在重复调用时会返回序列(range (start step end)) 中的数字。当序列用完时,返回的函数应该返回()。
示例:(define next (iterator '(0 2 7)))、(begin (next) (next) (next) (next) (next)) => 0, 2, 4, 6, ()
; lab 1
(define (range L)
(let ((start (car L))
(step (car (cdr L)))
(end (car (cdr (cdr L)))))
(if (> start end)
cons '()
(cons start (range (list (+ start step) step end))))))
当我打电话给range '(0 2 7) 我得到(0 2 4 6) 但是我需要得到(0 2 4 6) ()
为什么cons '() 没有附加到我的列表中
【问题讨论】:
-
Protip:学习格式化和缩进方案代码。
-
你可能只想要
'()(或者'(())) -
我希望 range '(0 2 7) 返回 0 2 4 6 '()
-
是我的 cons '() 问题吗?
-
您的文字和代码不匹配。
标签: scheme