Skip to main content

[![](https://travis-ci.org/logpy/unification.png)](https://travis-ci.org/logpy/unification)

Straightforward Unification, extensible via dispatch.

Examples

>>> from unification import *
>>> unify(1, 1)
{}
>>> unify(1, 2)
False
>>> x = var('x')

>>> unify((1, x), (1, 2))
{~x: 2}

>>> unify((x, x), (1, 2))
False

@unifiable
class Account(object):
    def __init__(self, id, name, balance):
        self.id = id
        self.name = name
        self.balance = balance

data = [Account(1, 'Alice', 100),
        Account(2, 'Bob', 0),
        Account(2, 'Charlie', 0),
        Account(2, 'Denis', 400),
        Account(2, 'Edith', 500)]

id, name, balance = var('id'), var('name'), var('balance')

>>> [unify(Account(id, name, balance), acct) for acct in data]
[{~name: 'Alice', ~balance: 100, ~id: 1},
 {~name: 'Bob', ~balance: 0, ~id: 2},
 {~name: 'Charlie', ~balance: 0, ~id: 2},
 {~name: 'Denis', ~balance: 400, ~id: 2},
 {~name: 'Edith', ~balance: 500, ~id: 2}]

>>> [unify(Account(id, name, 0), acct) for acct in data]
[False,
 {~name: 'Bob', ~id: 2},
 {~name: 'Charlie', ~id: 2},
 False,
 False]

History

This was carved out from the LogPy project.

Author

Matthew Rocklin

Metadata

Release files for unification 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for unification 0.3.1
File Size Uploaded
unification-0.3.1.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for unification 0.3.1
File Interpreter ABI Platform
unification-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / unification-0.3.1.tar.gz

Download URL unification-0.3.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e59bb12cf3252c57436e9b65cb4eeb516fd6e07427ffad073d2d304a6da73c87
BLAKE2b-256 checksum
How to use checksums
a2e266aa8756f2a5c3f9f8c857c9f7b9ec036ea4e53eca52ffb2a372c1ec3d56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / unification-0.3.1-py3-none-any.whl

Download URL unification-0.3.1-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf92f5d3338bc108c1fb742cb792321cc58458b70ca271e32486e2c0bcbec915
BLAKE2b-256 checksum
How to use checksums
89414adbaafba55513ceda4e178eb9f9f77b967c783d1ecce4e07c0c4d04b90c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.2.2

2 release files

0.2.1

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page