如何结合这两个功能(方案)?

时间:2017-10-19 04:03:03

标签: scheme racket

我想将以下代码合并为一个:

   (define (foundList x)
        (when (pair? x)
         ((hash-ref *function-table* (car x)) (cdr x))))

(define (endofstring x)
  (if (not (null?(cdr x)))
    (endofstring (cdr x))
    (foundList (car x))))

我试图做以下但是我得到" hash-ref:找不到键值#34;

(define (endofstring x)
  (if (not (null?(cdr x)))
    (endofstring (cdr x))
    (if (when (pair? x) 
      ((hash-ref *function-table* (car x)) (cdr x)))
      (car x) (void))))

需要帮助thanx

1 个答案:

答案 0 :(得分:1)

我认为x中的endofstringx中的foundList混淆了(foundList (car x))

foundList替换为x的正文,并将(car x)替换为(when (pair? (car x)) ((hash-ref *function-table* (car (car x))) (cdr (car x))))
也就是说,用

(define (endofstring x)
  (if (not (null?(cdr x)))
    (endofstring (cdr x))
    (when (pair? (car x))
        ((hash-ref *function-table* (car (car x))) (cdr (car x))))))

你得到了

git checkout orphan
git merge --no-commit --squash master
git commit