Skip to content

Commit

Permalink
Merge 9e0810d into 0daa3ad
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonwillard committed Jul 28, 2022
2 parents 0daa3ad + 9e0810d commit 7bc3288
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 145 deletions.
54 changes: 32 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
exclude: |
(?x)^(
versioneer\.py|
kanren/_version\.py|
doc/.*|
bin/.*
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: debug-statements
exclude: |
(?x)^(
kanren/core\.py|
)$
- id: check-merge-conflict
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
language_version: python3
exclude: |
(?x)^(
versioneer\.py|
kanren/_version\.py|
doc/.*|
bin/.*
)$
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
exclude: |
(?x)^(
versioneer\.py|
kanren/_version\.py|
doc/.*|
bin/.*
)$
- repo: https://github.com/pycqa/isort
rev: 5.5.2
rev: 5.6.4
hooks:
- id: isort
- repo: https://github.com/humitos/mirrors-autoflake.git
rev: v1.1
hooks:
- id: autoflake
exclude: |
(?x)^(
versioneer\.py|
kanren/_version\.py|
doc/.*|
bin/.*
)$
(?x)^(
.*/?__init__\.py|
)$
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
hooks:
- id: mypy
additional_dependencies:
- types-setuptools
1 change: 1 addition & 0 deletions examples/commutative.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from kanren.assoccomm import associative, commutative
from kanren.assoccomm import eq_assoccomm as eq


# Define some dummy Operationss
add = "add"
mul = "mul"
Expand Down
1 change: 1 addition & 0 deletions examples/corleone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from kanren import Relation, conde, facts, run, var


father = Relation()
mother = Relation()

Expand Down
1 change: 1 addition & 0 deletions examples/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
from kanren import Relation, fact, run, var


adjacent = Relation()
coastal = Relation()

Expand Down
1 change: 1 addition & 0 deletions examples/user_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from kanren.core import lall
from kanren.term import applyo, term # noqa: F401


unifiable(Account) # Register Account class

accounts = (
Expand Down
54 changes: 45 additions & 9 deletions examples/zebra-puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
Zebra puzzle as published in Life International in 1962.
https://en.wikipedia.org/wiki/Zebra_Puzzle
"""
from typing import Union
from dataclasses import dataclass, field
from typing import Union

from kanren import eq, conde, lall, membero, run
from unification import unifiable, var, vars, Var
from unification import Var, unifiable, var, vars

from kanren import conde, eq, lall, membero, run


@unifiable
@dataclass
class House():
class House:
nationality: Union[str, Var] = field(default_factory=var)
drink: Union[str, Var] = field(default_factory=var)
animal: Union[str, Var] = field(default_factory=var)
Expand All @@ -24,6 +25,7 @@ def righto(right, left, houses):
neighbors = tuple(zip(houses[:-1], houses[1:]))
return membero((left, right), neighbors)


def nexto(a, b, houses):
"""Express that `a` and `b` are next to each other."""
return conde([righto(a, b, houses)], [righto(b, a, houses)])
Expand Down Expand Up @@ -53,8 +55,42 @@ def nexto(a, b, houses):

results = run(0, houses, goals)
print(results)
# ([House(nationality='Norwegian', drink='water', animal='fox', cigarettes='Kools', color='yellow'),
# House(nationality='Ukrainian', drink='tea', animal='horse', cigarettes='Chesterfields', color='blue'),
# House(nationality='Englishman', drink='milk', animal='snails', cigarettes='Old Gold', color='red'),
# House(nationality='Spaniard', drink='orange juice', animal='dog', cigarettes='Lucky Strike', color='ivory'),
# House(nationality='Japanese', drink='coffee', animal='zebra', cigarettes='Parliaments', color='green')],)
# (
# [
# House(
# nationality="Norwegian",
# drink="water",
# animal="fox",
# cigarettes="Kools",
# color="yellow",
# ),
# House(
# nationality="Ukrainian",
# drink="tea",
# animal="horse",
# cigarettes="Chesterfields",
# color="blue",
# ),
# House(
# nationality="Englishman",
# drink="milk",
# animal="snails",
# cigarettes="Old Gold",
# color="red",
# ),
# House(
# nationality="Spaniard",
# drink="orange juice",
# animal="dog",
# cigarettes="Lucky Strike",
# color="ivory",
# ),
# House(
# nationality="Japanese",
# drink="coffee",
# animal="zebra",
# cigarettes="Parliaments",
# color="green",
# ),
# ],
# )
1 change: 1 addition & 0 deletions kanren/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
)
from .term import arguments, operator, term, unifiable_with_term


__version__ = get_versions()["version"]
del get_versions
1 change: 1 addition & 0 deletions kanren/assoccomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .graph import term_walko
from .term import term


associative = Relation("associative")
commutative = Relation("commutative")

Expand Down
3 changes: 2 additions & 1 deletion kanren/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abc import ABC, abstractmethod
from collections import UserDict
from collections.abc import Mapping
from typing import Optional

from cons.core import ConsPair
from toolz import groupby
Expand All @@ -26,7 +27,7 @@ class ConstraintStore(ABC):
"""

__slots__ = ("lvar_constraints",)
op_str = None
op_str: Optional[str] = None

def __init__(self, lvar_constraints=None):
# self.lvar_constraints = weakref.WeakKeyDictionary(lvar_constraints)
Expand Down
Loading

0 comments on commit 7bc3288

Please sign in to comment.