关于循环的问题。
用列表做这件事总是让我感到困惑。你会怎么做这样的事情?
(define-struct song (title artist length))
(define song1 (make-song "Hey, Jude" "The Beatles" 431))
(define songs (list song
(make-song "Sing" "JB" 200)
(make-song "Yell" "LS" 188)))
(check-expect (count songs) 819)
计算所有歌曲的长度
(define (count n)
(cond
[(empty? n) 0]
[else
(first n)
(count (rest n)))
你会怎么做?使用结构,您可以简单地将它们分开。(+ (song-length)...
不知道如何在列表中继续进行此操作。例如,我不确定什么是first
and rest
in songs1
orsongs