开发者

syntax errors in a scheme search program

开发者 https://www.devze.com 2023-02-13 08:03 出处:网络
\"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

"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

精彩评论

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