Scheme Error Object Is Not Applicable

2019-02-27 16:22发布

I am writing a Scheme function that detects if a word is in a list of words. My code uses an if statement and memq to return either #t or #f. However, something is causing the first parameter to return the error that the object is not applicable.

(define in?                                                                     
  (lambda (y xs)                                                                
    ((if (memq( y xs )) #t #f)))) 

标签: scheme
1条回答
倾城 Initia
2楼-- · 2019-02-27 17:06

Parentheses matter:

(define in?                                                                     
  (lambda (y xs)                                                                
    (if (memq y xs) #t #f)))

so

  • you have double parentheses before if
  • you put memq parameters between parentheses

BTW, you can also express this as

(define in?                                                                     
  (lambda (y xs)                                                                
    (and (memq y xs) #t)))
查看更多
登录 后发表回答