Scheme Error Object Is Not Applicable

后端 未结 1 1046
南笙
南笙 2021-01-22 20:25

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 f

相关标签:
1条回答
  • 2021-01-22 21:05

    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)))
    
    0 讨论(0)
提交回复
热议问题