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
consbehavior 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
Release files for cons 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cons-0.1.2.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cons-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / cons-0.1.2.tar.gz
| Download URL | cons-0.1.2.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43c11d3e50c68cea886d7b675f25ca599e8f0e487f1d7d819e0e3000bde68f9f
|
|
BLAKE2b-256 checksum How to use checksums |
1126878c8e098d479fd6c1b9a0edb264a04c3a4095c0949674eaebadea0dbef3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / cons-0.1.2-py3-none-any.whl
| Download URL | cons-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cacdb732c9899d02f10f6a6f486b08c8bde0f955d8b9a4c00e2ce697f97cae76
|
|
BLAKE2b-256 checksum How to use checksums |
18d35f4903bf19a3cf46226e2d63bfe91d9bbe7010ba6ef7061d5de3d2f5eb30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|