potassco / clingo

🤔 A grounder and solver for logic programs.
https://potassco.org/clingo
MIT License
601 stars 79 forks source link

Python-API: default behaviour of Control.ground() #377

Closed jorgefandinno closed 2 years ago

jorgefandinno commented 2 years ago

It would be nice to be able to call Control.ground() without parameters.

This may be achievable by setting the default value of parts to be tuple (("base", ()),)

def ground(
    self,
    parts: Sequence[Tuple[str, Sequence[Symbol]]] = (("base", ()),)
    context: Any = None
) ‑> None:

The example in https://potassco.org/clingo/python-api/current/clingo/control.html could look as follows

>>> from clingo.symbol import Number
>>> from clingo.control import Control
>>>
>>> ctl = Control()
>>> ctl.add("base", [], "q.")
>>> ctl.add("p", ["t"], "q(t).")
>>>
>>> ctl.ground() # this is the only modified statement
>>> print(ctl.solve(on_model=print))
q
SAT
>>> ctl.ground([("p", [Number(1)]), ("p", [Number(2)])])
>>> print(ctl.solve(on_model=print))
q q(1) q(2)
SAT
>>> ctl.ground([("p", [Number(3)])])
>>> print(ctl.solve(on_model=print))
q q(1) q(2) q(3)
SAT
rkaminsk commented 2 years ago

I don't like it. The purpose of the example is to show how different program parts are grounded. But that's not to say we cannot make base the default part to ground. Then I would additionally overload the add function to be callable with just one string for the program to add and probably make two separate examples.

jorgefandinno commented 2 years ago

I don't like it. The purpose of the example is to show how different program parts are grounded. But that's not to say we cannot make base the default part to ground. Then I would additionally overload the add function to be callable with just one string for the program to add and probably make two separate examples.

it makes sense to me.