diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index ead2f56..740c4d7 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -2,10 +2,10 @@ name: PyPI on: push: branches: - - master + - main - auto-release pull_request: - branches: [master] + branches: [main] release: types: [published] diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bf1ed1d..cc6cf6c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,10 +3,10 @@ name: Tests on: push: branches: - - master + - main pull_request: branches: - - master + - main jobs: changes: diff --git a/README.md b/README.md index c1ad666..97b943a 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ make check ## Examples -`unification` has built-in support for most Python data types: +`unification` has built-in support for unifying most Python data types via the function `unify`: ```python >>> from unification import * @@ -33,13 +33,20 @@ make check {} >>> unify(1, 2) False ->>> x = var('x') +>>> x = var() >>> unify((1, x), (1, 2)) {~x: 2} >>> unify((x, x), (1, 2)) False ``` +Unifiable objects containing logic variables can also be reified using `reify`: + +```python +>>> reify((1, x), {x: 2}) +(1, 2) +``` + And most Python data structures: ``` python @@ -48,7 +55,7 @@ And most Python data structures: >>> unify({"a": 1, "b": 2}, {"a": x, "b": 2, "c": 3}) False >>> from collections import namedtuples ->>> ntuple = namedtuple("ntuple", ("a", "b")) +>>> ntuple = namedtuple("ntuple", ("a", "b")) >>> unify(ntuple(1, 2), ntuple(x, 2)) {~x: 1} ``` diff --git a/unification/core.py b/unification/core.py index 680ffbb..cfd827b 100644 --- a/unification/core.py +++ b/unification/core.py @@ -25,11 +25,11 @@ def assoc(s, u, v): def stream_eval(z, res_filter=None): - """Evaluate a stream of `_reify`/`_unify` results. + r"""Evaluate a stream of `_reify`/`_unify` results. This implementation consists of a deque that simulates an evaluation stack of `_reify`/`_unify`-produced generators. We're able to overcome - `RecursionError`s this way. + `RecursionError`\s this way. """ if not isinstance(z, Generator): @@ -79,7 +79,7 @@ def _reify_Var(o, s): def _reify_Iterable_ctor(ctor, t, s): - """Create a generator that yields _reify generators. + """Create a generator that yields `_reify` generators. The yielded generators need to be evaluated by the caller and the fully reified results "sent" back to this generator so that it can finish @@ -237,7 +237,7 @@ def _unify_slice(u, v, s): @dispatch(object, object, Mapping) def unify(u, v, s): - """Find substitution so that u == v while satisfying s. + """Find substitution so that ``u == v`` while satisfying `s`. >>> x = var('x') >>> unify((1, x), (1, 2), {})