Blame view

code/drafts/api_01.py 394 Bytes
808facfe   Francisco Coelho   Main text adapted...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from clingo.symbol import Number
from clingo.control import Control

class Context:
    def inc(self, x):
        return Number(x.number + 1)

    def seq(self, x, y):
        return [x, y]

def on_model(m):
    print(m)

ctl = Control()
ctl.add("base", [], """\
p(@inc(10)).
q(@seq(1,2)).
""")

ctl.ground(
    [("base", [])],
    context=Context())

s = ctl.solve(on_model=on_model)

aa257377   Francisco Coelho   Post meeting 2022...
26
print(s)