Skip to main content

An efficient implementation of cons

Project description

fastcons

Fastcons is a Python extension module that provides an efficient implementation of cons lists.

The fastcons module provides two types: nil and cons. The nil type represents the empty list, while the cons type represents a pair - an immutable cell containing two elements.

Installation

You can install fastcons using pip:

pip install fastcons

Usage

The fastcons module provides two types:

  • nil: represents the empty list; and
  • cons: represents a pair.

You can create the nil object by calling nil().

You can create a cons object by calling cons(head, tail). cons can be used to create linked lists: a chain of cons objects is considered a list if it is terminated by nil(), e.g. cons(1, cons(2, cons(3, nil()))).

You can efficiently create cons lists from Python sequences using the cons.from_xs method, where xs is a sequence.

from fastcons import cons, nil

# Create a cons list using the cons function
lst = cons(1, cons(2, cons(3, nil())))

# Create a cons list from a Python sequence
lst2 = cons.from_xs([1, 2, 3])

# Access the head and tail of a cons list
assert lst.head == 1
assert lst.tail.head == 2

# Test for equality
assert lst == lst2

The cons objects are printed using Lisp-style notation, which makes it easier to read long lists.

>>> cons.from_xs(range(1, 4))
(1 2 3)
>>> cons("foo", "bar")
('foo' . 'bar')
>>> cons(cons(1, 2), cons(cons(3, 4), nil()))
((1 . 2) (3 . 4))

API Reference

nil()

Returns the singleton nil object.

cons(head, tail)

Returns a cons object with the given head and tail.

cons.from_xs(xs)

Returns a cons object created from the Python sequence xs.

License

fastcons is released under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

fastcons-0.1.3-cp311-cp311-musllinux_1_1_x86_64.whl (28.1 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

fastcons-0.1.3-cp311-cp311-musllinux_1_1_i686.whl (27.1 kB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

fastcons-0.1.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (25.0 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fastcons-0.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (23.5 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

fastcons-0.1.3-cp311-cp311-macosx_10_9_x86_64.whl (7.6 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

File details

Details for the file fastcons-0.1.3-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for fastcons-0.1.3-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 716777d59980858939fea136364fed77265672872ecc58d6b164a851dde1fb0a
MD5 6dcbaf77fe04a508495b9318316b5a42
BLAKE2b-256 0a5e07f9e87bf5699d200f88019eb5abe06c0e4ef4ba95392a83f70d2be9fbc1

See more details on using hashes here.

File details

Details for the file fastcons-0.1.3-cp311-cp311-musllinux_1_1_i686.whl.

File metadata

File hashes

Hashes for fastcons-0.1.3-cp311-cp311-musllinux_1_1_i686.whl
Algorithm Hash digest
SHA256 bc1796048fe2b69f1370eff19365876967bfb4e90628f73da867ccf9cc0063b8
MD5 b0311cb18d6255cd0d5e643bbc2da1b5
BLAKE2b-256 08f02bb6b72b3d687db25cbc40e42742a810e11c1f9969f5df85d5d4384a61d1

See more details on using hashes here.

File details

Details for the file fastcons-0.1.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastcons-0.1.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 571577dfdd8b8c9fee875c90e0b74173599286647a926700ec0c244bc6d29128
MD5 f0bad49b5c3d740ed9a1b2f771534646
BLAKE2b-256 499740cdcd5afd75ac9c3cd4a3e24e072def7e94e0fdd0ae4ff7157b03a80002

See more details on using hashes here.

File details

Details for the file fastcons-0.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for fastcons-0.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 628b91bcdaf792b3c7035da56f1644e86ae80c8f25c86b2e39af0c60c2452e46
MD5 e43383182fe38627b6ea42b45f5eb718
BLAKE2b-256 d1dac5d132fd3ddc5f46266972639e33f22a34a4e43603fb9bf22bfa21d275a5

See more details on using hashes here.

File details

Details for the file fastcons-0.1.3-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for fastcons-0.1.3-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 91c814cda95ab873c8553afdea2b24c6634edbcd90a1ece65aaf0aff697a0410
MD5 3a6f8ba13c10cb7713116663351d0c91
BLAKE2b-256 985ed4f529cc21f6bb8b2770f0839b5b49d8a0a34f691e0789743c5570cd3671

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page