scheme error: Error: argument 1 of map has wrong type (NoneType)

问题描述 投票:0回答:0

我正在上cs61a课程,我打的和教授在屏幕上打的一模一样(链接:https://www.youtube.com/watch?v=0GcZKmdzPWU&list=PL6BsET-8jgYXHupEH2vUfhlvwbJddZdJM&index=4),我查了一下逐个字母,但我不断出错。

这是我的方案代码:

(define (evenSub s)
  (if (null? s) nil
    (append (evenSub (cdr s))
      (map (lambda (t) (cons (car s) t))
        (if (even? (car s))
          (evenSub (cdr s))
          (oddSub (cdr s))
          )
        )
      (if (even? (car s)) (list (list (car s))) nil))))

(define (oddSub s)
  (if (null? s) nil
    (append (oddSub (cdr s))
      (map (lambda (t) (cons (car s) t))
        (if (odd? (car s))
          (evenSub (cdr s))
          (oddSub (cdr s))))
      (if (odd? (car s)) (list(list((car s))) nil)))))

这是来自解释器的错误跟踪信息:

XL@mbp lab11 % python3 scheme -i evensub.scm
Welcome to the CS 61A Scheme Interpreter (version 1.2.5)

scm> (evenSub '(3 4))
Traceback (most recent call last):
  0 (append (evensub (cdr s)) (map (lambda (t) (cons (car s) t)) (if (even? (car s)) (evensub (cdr s)) (oddsub (cdr s)))) (if (even? (car s)) (list (list (car s))) ()))
  1 (map (lambda (t) (cons (car s) t)) (if (even? (car s)) (evensub (cdr s)) (oddsub (cdr s))))
Error: argument 1 of map has wrong type (NoneType)
scm> 

我不明白为什么我得不到教授在讲座中展示的结果。有人可以帮忙吗?

scheme
© www.soinside.com 2019 - 2024. All rights reserved.