我将确定字符串供应列表中的任何字符串是否比提供的字符串长。我尝试使用 sting-length 来计算字符串的长度,但它不起作用。我知道因为 los 不是一个字符串,但我怎样才能把 LoS -> String. 或者我不需要使用字符串长度。我查看了文档。有一个列表字符串函数,但列表只包含字符。
(define LOS-0 '())
(define LOS-1 (cons "POG" LOS-0))
(define LOS-2 (cons "WooooW" LOS-1))
(define LOS-3 (cons "Yee" LOS-2))
(define (any-longer? los)
(cond
[(empty? los) '()]
[(cons? los)
(if
(< (string-length (first los) (string-length (rest los))))
#true
#false)]))
或者只是递归:
(define (any-longer? s los)
(cond ((empty? los) #false)
((< (string-length s) (string-length (car los))) #true)
(else (any-longer? s (cdr los)))))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句