方案错误对象不适用 [英] Scheme Error Object Is Not Applicable

查看:20
本文介绍了方案错误对象不适用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Scheme 函数来检测某个单词是否在单词列表中.我的代码使用 if 语句和 memq 来返回 #t 或 #f.但是,某些原因导致第一个参数返回对象不适用的错误.

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

推荐答案

括号很重要:

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

所以

  • if
  • 前面有双括号
  • 你把 memq 参数放在括号之间
  • 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)))

这篇关于方案错误对象不适用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆