我很难处理这个结构,我想编写一个函数来告诉讨论中出现了多少主题。
; a Discussion is (make-discussion String Digressions)
(define-struct discussion [topic digressions])
; Digressions is [ListOf Discussion]
; count-topics : Discussion -> Number
; counts the number of total topics in a discussion, including repeated topics
(define (count-topics d)
(cond
[(empty? (discussion-digressions d)) 0]
[(cons? (discussion-digressions d)) (add1 (count-topics (make-discussion (first (discussion-topic d))
(list (make-discussion (rest (discussion-digressions d)))))))]))
(check-expect (count-topics (make-discussion "music" (list (make-discussion "politics" empty)))) 2)
我已经尝试了几个小时,但还没有解决它。我不知道从哪里开始,有人对球拍有敏锐的眼光吗?我试图先处理这个话题,但没有任何运气这样做。