0
我发现列表的最大值,现在我想返回数字,除了所有具有MAX值的模数等于零的数字,我不太清楚如何使用整个列表以获得我需要的任何人都可以引导我这个方向是正确的号码上模运算符是我迄今为止在列表上使用模运算符的方案
(define (findlargest a_list)
(if (null? a_list) ;if its a empty list
#f ;its false
(let loop ((a_list (cdr a_list)) ;binds the loop variable a_list to value of cdr a_list(second and all subsequent items in a list)
(maxval (car a_list))) ;maxval is set to car of a_list (first item of the list)
(cond ((null? a_list) maxval) ;if the list is empty return max
((> (car a_list) maxval) ;checks to see if the current element > max
(loop (cdr a_list) (car a_list))) ;find a new max
(else
(loop (cdr a_list) maxval)));keeps the same max