在序言中拆分列表
假设我在序言中有这个列表:
[-0.791666666666667-[]-[predicate(a,b,c,d)]-[predicate_2(p,e,q,d,g)]]
有办法将其拆分为:
-0.791666666666667, [], [predicate(a,b,c,d)], [predicate_2(p,e,q,d,g)] ???
拆分意味着列表中有不同的部分。
也许:
X = -0.791666666666667 Y = [] Z = [predicate(a,b,c,d)] etc...
或者另一个解决方案可以替换为“,”,这样它就变成了一个包含不同元素的列表?
suppose i have this list in prolog:
[-0.791666666666667-[]-[predicate(a,b,c,d)]-[predicate_2(p,e,q,d,g)]]
there is way to split this in:
-0.791666666666667, [], [predicate(a,b,c,d)], [predicate_2(p,e,q,d,g)] ???
Split means have different pice of the list.
Maybe:
X = -0.791666666666667 Y = [] Z = [predicate(a,b,c,d)] etc...
Or another solution can be replace - with "," so it become a list with different elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用模式匹配。与在列表上使用它的方式类似(
[H|T]
):我使用累加器,因为像
abc
这样的东西被AB
分割code> 转换为ab
和c
。编辑:如果您知道有 4 个术语,则可以使用类似
You can use pattern matching. Similar to the way you use it on lists (
[H|T]
):I'm using accumulator, because something like
a-b-c
is split byA-B
intoa-b
andc
.EDIT: If you know you have 4 terms, you can use something like
琐碎:
用法:
或者进行内联模式匹配,为这样的任务编写谓词是相当浪费的,这对我来说似乎是一次性的。
Trivial:
Usage:
Or do the pattern matching inline, it's rather wasteful to write a predicate for such a task, which seems rather one-off to me.