Metadata-Version: 2.1
Name: cons
Version: 0.1.2
Summary: An implementation of Lisp/Scheme-like cons in Python.
Home-page: https://github.com/brandonwillard/python-cons
Author: Brandon T. Willard
Author-email: brandonwillard+cons@gmail.com
License: LGPL-3
Platform: any
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: DFSG approved
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.5
Description-Content-Type: text/markdown
Requires-Dist: toolz
Requires-Dist: multipledispatch
Requires-Dist: unification

[![Build Status](https://travis-ci.org/brandonwillard/python-cons.svg?branch=master)](https://travis-ci.org/brandonwillard/python-cons) [![Coverage Status](https://coveralls.io/repos/github/brandonwillard/python-cons/badge.svg?branch=master)](https://coveralls.io/github/brandonwillard/python-cons?branch=master) [![PyPI](https://img.shields.io/pypi/v/cons)](https://pypi.org/project/cons/)

Python `cons`
==================

An implementation of [`cons`][cons] in Python.

Usage and Design
======================

The `cons` package attempts to emulate the semantics of Lisp/Scheme's `cons` as closely as possible while incorporating all the built-in Python sequence types:
```python
>>> from cons import cons, car, cdr
>>> cons(1, [])
[1]

>>> cons(1, ())
(1,)

>>> cons(1, [2, 3])
[1, 2, 3]

>>> cons(1, "a string")
ConsPair(1 'a string')
```

According to `cons`, `None` corresponds to the empty built-in `list`:
```python
>>> cons(1, None)
[1]
```

The `cons` package follows Scheme-like semantics for empty sequences:
```python
>>> car([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ConsError: Not a cons pair

>>> cdr([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ConsError: Not a cons pair

```

Features
===========

* Support for the standard Python ordered collection types: i.e. `list`, `tuple`, `Iterator`, `OrderedDict`.
```python
>>> from collections import OrderedDict
>>> cons(('a', 1), OrderedDict())
OrderedDict([('a', 1)])

```
* Existing `cons` behavior is easy to change and new collections are straightforward to add through [`multipledispatch`][md].
* Built-in support for [`unification`][un].
```python
>>> from unification import unify, reify, var
>>> unify([1, 2], cons(var('car'), var('cdr')), {})
{~car: 1, ~cdr: [2]}

>>> reify(cons(1, var('cdr')), {var('cdr'): [2, 3]})
[1, 2, 3]

>>> reify(cons(1, var('cdr')), {var('cdr'): None})
[1]

```

Installation
================

```python
pip install cons
```


[cons]: https://en.wikipedia.org/wiki/Cons
[md]: https://github.com/mrocklin/multipledispatch
[un]: https://github.com/mrocklin/unification


