如果没有,则删除序言 [英] Prolog removing IF THEN ELSE
本文介绍了如果没有,则删除序言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在没有if then else条件的情况下重新格式化我的代码。是否有捷径可寻?这只是代码的一个示例。我认为在序言中使用IF-THEN-ELSE很奇怪:\而且我正在寻找一些更递归的案例。像模式匹配
I would like to reformat my code without the if then else condition. Is there an easy way to do this? This is just an exemple of code. I think using IF-THEN-ELSE in prolog is weird :\ And I'm looking to get something more recursive cases. Like pattern matching
rules(Param1, Param2) :-
(
A ->
B, C, D,
(
E -> F
;
G, H
)
;
I
).
编辑:编辑我的代码,使其看起来更像
Edited my code to look like more what it should look
推荐答案
The general translation scheme for
pred(X):-
( A -> B
; C -> D
; G
).
pred(Y):- Q.
是
pred(X):- pred1(X).
pred(Y):- Q.
pred1(X):- call(A), !, B.
pred1(X):- call(C), !, D.
pred1(X):- G.
非常感谢 j4n bur53 指出需要通话
-如果在 A内有切痕
或 C
!
Big thanks to j4n bur53 for pointing out the need for call
-- in case there's a cut inside the A
or the C
!
另请参见 ->
文档。
See also ->
documentation.
这篇关于如果没有,则删除序言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文