Skip to content

Commit 454f6ed

Browse files
Update unification extension for stream-processing
1 parent 5d12759 commit 454f6ed

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

cons/unify.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from itertools import tee
2-
from collections import OrderedDict
32
from collections.abc import Iterator, Mapping
43

5-
from unification.core import unify, _unify, reify, _reify
4+
from unification.core import (
5+
_unify,
6+
_reify,
7+
construction_sentinel,
8+
)
69

710
from .core import car, cdr, ConsPair, cons, MaybeCons, ConsError
811

912

10-
def _cons_unify(lcons, rcons, s):
13+
def _unify_Cons(lcons, rcons, s):
1114

1215
lcons_ = lcons
1316
rcons_ = rcons
@@ -19,27 +22,23 @@ def _cons_unify(lcons, rcons, s):
1922
rcons, rcons_ = tee(rcons)
2023

2124
try:
22-
s = unify(car(lcons), car(rcons), s)
25+
s = yield _unify(car(lcons), car(rcons), s)
2326

2427
if s is not False:
25-
return unify(cdr(lcons_), cdr(rcons_), s)
28+
s = yield _unify(cdr(lcons_), cdr(rcons_), s)
2629
except ConsError:
27-
pass
30+
yield False
31+
else:
32+
yield s
2833

29-
return False
3034

31-
32-
_unify.add((ConsPair, (ConsPair, MaybeCons), Mapping), _cons_unify)
33-
_unify.add((MaybeCons, ConsPair, Mapping), _cons_unify)
34-
35-
36-
@_reify.register(OrderedDict, Mapping)
37-
def reify_OrderedDict(od, s):
38-
return OrderedDict((k, reify(v, s)) for k, v in od.items())
35+
_unify.add((ConsPair, (ConsPair, MaybeCons), Mapping), _unify_Cons)
36+
_unify.add((MaybeCons, ConsPair, Mapping), _unify_Cons)
3937

4038

4139
@_reify.register(ConsPair, Mapping)
42-
def reify_cons(lcons, s):
43-
rcar = reify(car(lcons), s)
44-
rcdr = reify(cdr(lcons), s)
45-
return cons(rcar, rcdr)
40+
def _reify_Cons(lcons, s):
41+
rcar = yield _reify(car(lcons), s)
42+
rcdr = yield _reify(cdr(lcons), s)
43+
yield construction_sentinel
44+
yield cons(rcar, rcdr)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
name="cons",
1010
version=versioneer.get_version(),
1111
cmdclass=versioneer.get_cmdclass(),
12-
install_requires=["logical-unification"],
12+
install_requires=["logical-unification>=0.4.0"],
1313
packages=find_packages(exclude=["tests"]),
1414
tests_require=["pytest"],
1515
author="Brandon T. Willard",

0 commit comments

Comments
 (0)