Search code examples
prologdcgsuccessor-arithmetics

DCG doubling a count


I am playing around with DCGs and I have this code. This displays x number of 0s and x numbers of As.

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). 

my question is how do I pass a functor to make the number of As double the number of 0s. Here's what I tried, but it doesn't work.

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

If i only want to add one, this is what did and it works fine.

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

Solution

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

    or

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