2016-12-03 46 views
2

我正在玩DCG,我有这个代码。这显示x号码0 s和x号码A s。DCG加倍计数

y --> test(Count), as(Count). 

test(0) --> []. 
test(succ(0)) --> [0]. 
test(succ(succ(Count))) --> [0], test(Count), [0]. 

as(0) --> []. 
as(succ(Count)) --> [a],as(Count). 

我的问题是我如何通过一个函子,以使A S的0双打的数目。这是我的尝试,但它不起作用。

y --> test(Count), as(add(Count,Count,R)). 

如果我只想添加一个,这是什么,它工作正常。

y --> test(Count), as(succ(Count)). 
+0

两个备注:使用而'到位SUCC的''S(X)(X )'。 ''set_prolog_flag(double_quotes,chars)'和'“0”'代替'[0]''。 – false

回答

1
y --> test(Count), as(Count), as(Count). 

y --> test(Count), {add(Count,Count,DCount)}, as(DCount). 
0

或者你可以双击该succtest

y --> test(Count), as(Count). 

test(0) --> []. 
test(succ(succ(Count))) --> [0], test(Count). 

as(0) --> []. 
as(succ(Count)) --> [a], as(Count).