Uyet123
Uyet123

Reputation: 47

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

Upvotes: 3

Views: 85

Answers (2)

max66
max66

Reputation: 66190

Or you can double the succ for test

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

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

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

Upvotes: 0

false
false

Reputation: 10102

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

or

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

Upvotes: 2

Related Questions