使用Scheme (DrRacket) 搜索列表
所以这是我的代码:
(define *graph* (read(open-input-file "starbucks4.sxml")))
(define get-artifacts
(lambda (l)
(member (list 'opm:artifact) l)))
当我输入 get-artifacts(*graph*)
时,我收到一条错误消息 procedure application: Expected procedure, 鉴于:...(我的整个文件内容)
有人看到我做错了什么吗?谢谢大家:)
PS:我对Scheme真的很陌生,所以这可能是我忘记的一些愚蠢的语法!
So here's my code:
(define *graph* (read(open-input-file "starbucks4.sxml")))
(define get-artifacts
(lambda (l)
(member (list 'opm:artifact) l)))
When I type get-artifacts(*graph*)
I get an error saying procedure application: expected procedure, given:...(the whole of my file contents)
Anyone see what I'm doing wrong? Thanks guys :)
PS: I'm really new to Scheme so it's probably some stupid syntax I'm forgetting!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在方案中调用函数的语法是
(函数名参数)
,而不是函数名(参数)
。当您编写
get-artifacts(*graph*)
时,racket 首先评估get-artifacts
,然后再评估其自身。然后它尝试计算
(*graph*)
,它认为这是一个不带参数的函数调用。这是行不通的,因为*graph*
是一个列表而不是一个函数。所以你会得到错误。The syntax for calling a function in scheme is
(function-name arguments)
, notfunction-name(arguments)
.When you write
get-artifacts(*graph*)
, racket first evaluatesget-artifacts
which evaluates to itself.Then it tries to evaluate
(*graph*)
, which it takes to be a function call with no arguments. That does not work because*graph*
is a list and not a function. So you get the error.看我对你另一个问题的回答;看起来您正在寻找 sxpath,在这里。
See my answer to your other question; it looks like you're in search of sxpath, here.