An implementation of Lisp/Scheme-like cons in Python.
Project description
Python cons
An implementation of 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:
>>> 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
:
>>> cons(1, None)
[1]
The cons
package follows Scheme-like semantics for empty sequences:
>>> 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
.
>>> 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 throughmultipledispatch
. - Built-in support for
unification
.
>>> 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
pip install cons
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cons-0.1.2.tar.gz
(4.9 kB
view details)
Built Distribution
cons-0.1.2-py3-none-any.whl
(5.2 kB
view details)
File details
Details for the file cons-0.1.2.tar.gz
.
File metadata
- Download URL: cons-0.1.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c11d3e50c68cea886d7b675f25ca599e8f0e487f1d7d819e0e3000bde68f9f |
|
MD5 | d78b5819ecb5172d59ffb583ee4cb2b2 |
|
BLAKE2b-256 | 1126878c8e098d479fd6c1b9a0edb264a04c3a4095c0949674eaebadea0dbef3 |
File details
Details for the file cons-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: cons-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cacdb732c9899d02f10f6a6f486b08c8bde0f955d8b9a4c00e2ce697f97cae76 |
|
MD5 | c59b7c9b1f388d8277420908cc7747f1 |
|
BLAKE2b-256 | 18d35f4903bf19a3cf46226e2d63bfe91d9bbe7010ba6ef7061d5de3d2f5eb30 |