You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-7Lines changed: 14 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,12 +19,11 @@ The `cons` package attempts to emulate the semantics of Lisp/Scheme's `cons` as
19
19
20
20
>>> cons(1, [2, 3])
21
21
[1, 2, 3]
22
-
23
-
>>> cons(1, "a string")
24
-
ConsPair(1'a string')
25
22
```
26
23
27
-
According to `cons`, `None` corresponds to the empty built-in `list`:
24
+
In general, `cons` is designed to work with `collections.abc.Sequence` types.
25
+
26
+
According to the `cons` package, `None` corresponds to the empty built-in `list`, as `nil` does in some Lisps:
28
27
```python
29
28
>>> cons(1, None)
30
29
[1]
@@ -44,17 +43,26 @@ ConsError: Not a cons pair
44
43
45
44
```
46
45
46
+
By default, `str` types are not considered cons-pairs, although they are sequences:
47
+
```python
48
+
>>> cons("a", "string")
49
+
ConsPair('a''a string')
50
+
```
51
+
52
+
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`.
53
+
54
+
47
55
Features
48
56
===========
49
57
50
-
*Support for the standard Python ordered collection types: i.e. `list`, `tuple`, `Iterator`, `OrderedDict`.
58
+
*Built-in support for the standard Python ordered sequence types: i.e. `list`, `tuple`, `Iterator`, `OrderedDict`.
51
59
```python
52
60
>>>from collections import OrderedDict
53
61
>>> cons(('a', 1), OrderedDict())
54
62
OrderedDict([('a', 1)])
55
63
56
64
```
57
-
* Existing `cons` behavior is easy to change and new collections are straightforward to add through [`multipledispatch`][md].
65
+
* Existing `cons` behavior can be changed and support for new collections can be added through the generic functions `cons.core._car` and `cons.core._cdr`.
0 commit comments