【发布时间】:2017-04-16 18:21:19
【问题描述】:
注意:我这样做是为了做作业。我不是在寻找解决问题的算法,只是想了解 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 为我修复了它。
-
您不应手动将您的问题标记为“[已解决]”。单击灰色复选标记符号接受 Sylwester 的答案,问题的缩影将自动标记为绿色。