2015-09-21 25 views
3

我一直在玩方案約10分鐘,偶然發現了這個錯誤:錯誤的類型適用?

[email protected](guile-user) [2]> (define (a one two) ((* one two))) 
[email protected](guile-user) [2]> (a 2 3) 
ERROR: In procedure 6: 
ERROR: Wrong type to apply: 6 

我期待這個返回6.如何「應用」進入到這個? 這個錯誤是什麼意思?

+0

試試[SICP](https://mitpress.mit.edu/sicp/full-text/book/book.html),特別是關於[評估]的章節(https://mitpress.mit.edu/ SiC顆粒/全文/電子書/圖書ZH-10.html#%_ sec_1.1.4)。 – ceving

回答

5

Scheme中的括號不只是一個分組構造。它們通常意味着功能應用。

錯誤與您的define的正文有關。具體來說,

((* one two)) 

意味着

Call the result of multiplying one by two

的JS相當於是一樣的東西

function a (one, two) { (one * two)(); } 

你最有可能意在定義功能

(define (a one two) (* one two)) 

這僅僅是multipli陽離子,應該工作得很好。

+0

這很簡單,並且做同樣的事情:'(define a *)' – ceving