实施法规。序言中的表达
我有一个关于在序言中实现一些谓词的问题。(对于正则表达式。) 我需要实现 4 个谓词
我的实现是
sublist( Sublist, List ) :- append( [_, Sublist, _], List ). %true if SubList is a sublist of a List
match(one(List),W) :- sublist(List,W). %true if there is a single occurence of List
match(opt(_),[]). %true if there are 0 or 1 occurences of List
match(opt(List),W) :- sublist(List,W).
match(star(_),[]). %true if there are 0 or more occurences of List
%more occurences
match(plus(List),W) :- sublist(List,W). %true if there are 1 or more occurences of List
%more occurences
现在,我的问题是。
- 我不知道如何实现更多的发生。
- 例如,如果我想像 match([这里有更多表达式],S) 那样调用它
length(S,3),match([star[1],opt[2,3]],S)
这样可以吗?
编辑:
2)问题很容易解决,我只是遍历列表。
I have a question regarding implementing some predicates in prolog.(for regular expression.)
I need to implement 4 predicates
My implementation is
sublist( Sublist, List ) :- append( [_, Sublist, _], List ). %true if SubList is a sublist of a List
match(one(List),W) :- sublist(List,W). %true if there is a single occurence of List
match(opt(_),[]). %true if there are 0 or 1 occurences of List
match(opt(List),W) :- sublist(List,W).
match(star(_),[]). %true if there are 0 or more occurences of List
%more occurences
match(plus(List),W) :- sublist(List,W). %true if there are 1 or more occurences of List
%more occurences
Now, my problem is.
- I have no idea how to implement more occurences.
- If I wanted to call it like match([here would be more expressions],S), for example
length(S,3),match([star[1],opt[2,3]],S)
Would that work?
EDIT:
2) problem is easily fixable, I am just iterating through the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的“match(one(...”可以使用:
并且您的“match(plus(...”可以使用标准Prolog
once/1
),以确保大于零的匹配。Your "match(one(..." can use:
And your "match(plus(..." can use the standard Prolog
once/1
, to ensure more-than-zero matches.