开发者

syntax errors in a scheme search program

"Define a function called search that takes a symbol and a list and returns the position of the first occurrence of the symbol in the list using zero based indexing. (If the first element of the list is equal to the symbol, return 0.) Only search the top level elements. If the list does not contain the symbol, return -1."

I wrote a program like this but I get syntax err开发者_运维知识库ors. Can someone help me out please.

(define search (lambda (n x)
                 (let ( (i 0)))
                   (if (empty? x)
                    -1
                    (if (equal? n (car x))
                        0
                     (let ((index (+ i 1)) (tail (cdr x))))
                     (if (equal? n (search (n tail)))                       
                       index)))))


It looks like you have too many closing parentheses on this line:

             (let ( (i 0)))

Remove the last one, and try again. This is not the only syntax error in your code, so you will have to take care to make all the parentheses match up properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜