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]
In general, cons is designed to work with collections.abc.Sequence types.
According to the cons package, None corresponds to the empty built-in list, as nil does in some Lisps:
>>> 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
By default, str types are not considered cons-pairs, although they are sequences:
>>> cons("a", "string")
ConsPair('a' 'a string')
This setting can be overridden and other types can be similarly excluded from consideration by registering classes with the abc-based classes MaybeCons and NonCons.
Features
- Built-in support for the standard Python ordered sequence types: i.e.
list,tuple,Iterator,OrderedDict.
>>> from collections import OrderedDict
>>> cons(('a', 1), OrderedDict())
OrderedDict([('a', 1)])
- Existing
consbehavior can be changed and support for new collections can be added through the generic functionscons.core._carandcons.core._cdr. - 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
Metadata
Release files for cons 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cons-0.3.0.tar.gz | 21.3 kB | Without provenance | Details for cons-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cons-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for cons-0.3.0-py3-none-any.whl |
Total release size: 27.4 kB
Release files / cons-0.3.0.tar.gz
| Download URL | cons-0.3.0.tar.gz |
|---|---|
| Size | 21.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a8e9bb4ed715fe701b8a03b2b93d3f8dfff4bd38944bf47b0a2230ef98efb1a
|
|
BLAKE2b-256 checksum How to use checksums |
98a79971261a064bf47239c396477b4fe39ad4f6c622ff9b81fff7807f88b059
|
| 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.3.0-py3-none-any.whl
| Download URL | cons-0.3.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bd08cb4d7e2f6589238abcee7282a6b03d0686adfacc875b59242deb9e528ad7
|
|
BLAKE2b-256 checksum How to use checksums |
73a5d402c4d155e9ae0400f96d84203c2057e8b8456f8358668850083b207786
|
| 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
|
Security for cons 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.