2

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 Answers1

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)))
uselpa
  • 18,732
  • 2
  • 34
  • 52
  • Thanks a ton! I'm new to Scheme and much more accustomed to C++ and Java where you can have a billion unneeded ()'s and not suffer for it. –  Oct 09 '14 at 20:22
  • You are welcome. I was looking for a duplicate but actually didn't find any with this precise error message (which Scheme implementation are you using?). If you search for "application: not a procedure" which is the error you'd get in Racket, you'll find similar questions here on SO. – uselpa Oct 09 '14 at 20:25