Scheme Error Object Is Not Applicable

北战南征 提交于 2019-12-20 04:22:41

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/26287081/scheme-error-object-is-not-applicable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!