2017-10-19 82 views
0

我想下面的代碼合併到一個:如何結合這兩個功能(方案)?

(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)))) 

我試着做以下,但我得到「哈希REF:沒有發現鍵值」

(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)))) 

需要幫助感謝名單

回答

1

我覺得你很困惑xendofstringxfoundList

(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)))))) 
+0

它沒有工作...我得到以下結果......「時:語法錯誤 在:(時(對?(car x)((hash-ref * fun-table *(car(car x)))(cdr(car x)))))「 – mike123

+0

@ mike123壞括號。現在修復。 – molbdnilo