注意:我正在做这个作业。我不是在寻找算法来解决我的问题,只是想了解Scheme如何工作。在计划中返回列表中的最小项目
我是新来的计划,并试图编写一个小程序来查找列表中的最小项。该程序正在工作,因为它找到了正确的答案(所以逻辑有点合理),但我只知道这一点,因为一个错误即将出现,它试图将我的答案作为一个函数来处理并称之为函数。
(DEFINE (startmin mylist)
(
(repeatmin (CAR mylist) (CDR mylist))
))
(DEFINE (repeatmin curmin mylist)
(
(IF (NULL? mylist) ;If the list is empty
;This is where I'm at a loss. I want a way for this value to be
;sent out once the list is empty
curmin ;return the current minimum
(IF (< curmin (CAR mylist)) ;if the current minimum is less than the head of the list
(repeatmin curmin (CDR mylist)) ;recurse with curmin
(repeatmin (CAR mylist) (CDR mylist)) ;otherwise recurse with the head of the list.
)
)
))
我真的在我如何获得价值的损失,一经发现,退了出去,因为它不停地尝试把值作为函数的递归。
[Sylwester's answer](http://stackoverflow.com/a/43430528/7872323)为我修复了它。 –
您不应该手动将问题标记为“[解决]”。通过点击灰色复选标记符号来接受Sylwester的回答,并且问题的微型图标将自动标记为绿色。 – suchtgott