我怎样才能计算列表中的所有自然元素(使用mzscheme)

时间:2014-09-25 13:46:18

标签: list count scheme

function name = mycount

这是输出示例:

(mycount 20) -> error(must standard error)
(mycount `()) -> 0
(mycount `(1 2 3)) - > 6
(mycount `((1 2) ((3)) (4 (5)))) -> 15

1 个答案:

答案 0 :(得分:-1)

function count-numbers takes a list:
    define a counter
    is it a number?
       ERROR
    is it a list?
        for each element of list:
            cond
                - is it a number? -> increase the counter
                - is it a list?   -> apply (count-numbers) to it and add the result to counter
                - do nothing

那样的东西?我们不会做你的作业:))