spork-runtime 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spork_runtime-0.1.0/LICENSE +21 -0
- spork_runtime-0.1.0/PKG-INFO +85 -0
- spork_runtime-0.1.0/README.md +51 -0
- spork_runtime-0.1.0/pyproject.toml +66 -0
- spork_runtime-0.1.0/setup.cfg +4 -0
- spork_runtime-0.1.0/spork/runtime/__init__.py +400 -0
- spork_runtime-0.1.0/spork/runtime/core.py +1621 -0
- spork_runtime-0.1.0/spork/runtime/json.py +344 -0
- spork_runtime-0.1.0/spork/runtime/ns.py +607 -0
- spork_runtime-0.1.0/spork/runtime/testing.py +50 -0
- spork_runtime-0.1.0/spork/runtime/types.py +357 -0
- spork_runtime-0.1.0/spork/runtime/utils.py +601 -0
- spork_runtime-0.1.0/spork/std/__init__.py +10 -0
- spork_runtime-0.1.0/spork/std/json.py +85 -0
- spork_runtime-0.1.0/spork/std/map.py +219 -0
- spork_runtime-0.1.0/spork/std/prelude.py +519 -0
- spork_runtime-0.1.0/spork/std/string.py +182 -0
- spork_runtime-0.1.0/spork_runtime.egg-info/PKG-INFO +85 -0
- spork_runtime-0.1.0/spork_runtime.egg-info/SOURCES.txt +25 -0
- spork_runtime-0.1.0/spork_runtime.egg-info/dependency_links.txt +1 -0
- spork_runtime-0.1.0/spork_runtime.egg-info/requires.txt +7 -0
- spork_runtime-0.1.0/spork_runtime.egg-info/top_level.txt +1 -0
- spork_runtime-0.1.0/tests/test_prelude.py +165 -0
- spork_runtime-0.1.0/tests/test_runtime.py +85 -0
- spork_runtime-0.1.0/tests/test_std_json.py +37 -0
- spork_runtime-0.1.0/tests/test_std_map.py +85 -0
- spork_runtime-0.1.0/tests/test_std_string.py +52 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Grant Wade
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: spork-runtime
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Compiler-free runtime and Python standard library for Spork
|
|
5
|
+
Author-email: Grant Wade <grant@spork.sh>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/spork-it/spork-runtime
|
|
8
|
+
Project-URL: Documentation, https://github.com/spork-it/spork-runtime#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/spork-it/spork-runtime
|
|
10
|
+
Project-URL: Issues, https://github.com/spork-it/spork-runtime/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/spork-it/spork-runtime/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: lisp,clojure,runtime,standard-library,persistent-data-structures
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: spork-pds<0.2.0,>=0.1.3
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build>=1; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy>=1.11; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
32
|
+
Requires-Dist: twine; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# spork-runtime
|
|
36
|
+
|
|
37
|
+
`spork-runtime` is the runtime distribution for Spork programs. It contains:
|
|
38
|
+
|
|
39
|
+
- the runtime types and helpers emitted Python code depends on;
|
|
40
|
+
- persistent collection integration backed by [`spork-pds`](https://github.com/spork-it/spork-pds);
|
|
41
|
+
- namespace and protocol support;
|
|
42
|
+
- JSON support and declared-test descriptors; and
|
|
43
|
+
- the Spork standard library implemented as ordinary Python modules.
|
|
44
|
+
|
|
45
|
+
It intentionally contains no reader, compiler, import hook, or `.spork` source files. A compiled Spork application can therefore depend on `spork-runtime` without installing `spork-lang` or compiling the standard library during installation.
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install spork-runtime
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Python API
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from spork.runtime import Keyword, assoc, get, hash_map, vec
|
|
57
|
+
from spork.std import map as maps
|
|
58
|
+
from spork.std import string
|
|
59
|
+
|
|
60
|
+
users = hash_map(Keyword("count"), 1)
|
|
61
|
+
users = maps.update(users, Keyword("count"), lambda value: value + 1)
|
|
62
|
+
assert get(users, Keyword("count")) == 2
|
|
63
|
+
assert string.join(", ", vec("Spork", "Python")) == "Spork, Python"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Python standard-library modules mirror the Spork namespaces:
|
|
67
|
+
|
|
68
|
+
| Spork namespace | Python module |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| `std.string` | `spork.std.string` |
|
|
71
|
+
| `std.map` | `spork.std.map` |
|
|
72
|
+
| `std.json` | `spork.std.json` |
|
|
73
|
+
|
|
74
|
+
`spork.std.prelude.MACROS` exposes the built-in macro implementations as Python callables for the compiler to install into its macro environment.
|
|
75
|
+
|
|
76
|
+
## Development
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
python -m venv .venv
|
|
80
|
+
.venv/bin/python -m pip install -e '.[dev]'
|
|
81
|
+
.venv/bin/python -m pytest
|
|
82
|
+
.venv/bin/python -m build
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The `spork` directory is an implicit namespace package. This allows `spork-runtime`, `spork-pds`, and `spork-lang` to provide separate portions of the same Python namespace.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# spork-runtime
|
|
2
|
+
|
|
3
|
+
`spork-runtime` is the runtime distribution for Spork programs. It contains:
|
|
4
|
+
|
|
5
|
+
- the runtime types and helpers emitted Python code depends on;
|
|
6
|
+
- persistent collection integration backed by [`spork-pds`](https://github.com/spork-it/spork-pds);
|
|
7
|
+
- namespace and protocol support;
|
|
8
|
+
- JSON support and declared-test descriptors; and
|
|
9
|
+
- the Spork standard library implemented as ordinary Python modules.
|
|
10
|
+
|
|
11
|
+
It intentionally contains no reader, compiler, import hook, or `.spork` source files. A compiled Spork application can therefore depend on `spork-runtime` without installing `spork-lang` or compiling the standard library during installation.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install spork-runtime
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Python API
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from spork.runtime import Keyword, assoc, get, hash_map, vec
|
|
23
|
+
from spork.std import map as maps
|
|
24
|
+
from spork.std import string
|
|
25
|
+
|
|
26
|
+
users = hash_map(Keyword("count"), 1)
|
|
27
|
+
users = maps.update(users, Keyword("count"), lambda value: value + 1)
|
|
28
|
+
assert get(users, Keyword("count")) == 2
|
|
29
|
+
assert string.join(", ", vec("Spork", "Python")) == "Spork, Python"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Python standard-library modules mirror the Spork namespaces:
|
|
33
|
+
|
|
34
|
+
| Spork namespace | Python module |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `std.string` | `spork.std.string` |
|
|
37
|
+
| `std.map` | `spork.std.map` |
|
|
38
|
+
| `std.json` | `spork.std.json` |
|
|
39
|
+
|
|
40
|
+
`spork.std.prelude.MACROS` exposes the built-in macro implementations as Python callables for the compiler to install into its macro environment.
|
|
41
|
+
|
|
42
|
+
## Development
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m venv .venv
|
|
46
|
+
.venv/bin/python -m pip install -e '.[dev]'
|
|
47
|
+
.venv/bin/python -m pytest
|
|
48
|
+
.venv/bin/python -m build
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The `spork` directory is an implicit namespace package. This allows `spork-runtime`, `spork-pds`, and `spork-lang` to provide separate portions of the same Python namespace.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "spork-runtime"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Compiler-free runtime and Python standard library for Spork"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Grant Wade", email = "grant@spork.sh"}
|
|
14
|
+
]
|
|
15
|
+
keywords = [
|
|
16
|
+
"lisp",
|
|
17
|
+
"clojure",
|
|
18
|
+
"runtime",
|
|
19
|
+
"standard-library",
|
|
20
|
+
"persistent-data-structures",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 3 - Alpha",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.10",
|
|
28
|
+
"Programming Language :: Python :: 3.11",
|
|
29
|
+
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Programming Language :: Python :: 3.14",
|
|
32
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
33
|
+
"Topic :: Software Development :: Libraries",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
dependencies = [
|
|
37
|
+
"spork-pds>=0.1.3,<0.2.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.optional-dependencies]
|
|
41
|
+
dev = [
|
|
42
|
+
"build>=1",
|
|
43
|
+
"mypy>=1.11",
|
|
44
|
+
"pytest>=8",
|
|
45
|
+
"twine",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/spork-it/spork-runtime"
|
|
50
|
+
Documentation = "https://github.com/spork-it/spork-runtime#readme"
|
|
51
|
+
Repository = "https://github.com/spork-it/spork-runtime"
|
|
52
|
+
Issues = "https://github.com/spork-it/spork-runtime/issues"
|
|
53
|
+
Changelog = "https://github.com/spork-it/spork-runtime/blob/main/CHANGELOG.md"
|
|
54
|
+
|
|
55
|
+
[tool.setuptools.packages.find]
|
|
56
|
+
where = ["."]
|
|
57
|
+
include = ["spork.runtime*", "spork.std*"]
|
|
58
|
+
namespaces = true
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
addopts = "-ra"
|
|
62
|
+
testpaths = ["tests"]
|
|
63
|
+
|
|
64
|
+
[tool.mypy]
|
|
65
|
+
explicit_package_bases = true
|
|
66
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"""
|
|
2
|
+
spork.runtime - The Spork Runtime Library
|
|
3
|
+
|
|
4
|
+
This package contains everything needed to run compiled Spork programs.
|
|
5
|
+
It is designed to be lightweight and independent of the compiler.
|
|
6
|
+
|
|
7
|
+
Submodules:
|
|
8
|
+
- types: Core type definitions (Symbol, Keyword, VectorLiteral, etc.)
|
|
9
|
+
- persistent data structures: provided by the spork-pds dependency
|
|
10
|
+
- core: Standard library functions (first, rest, map, filter, etc.)
|
|
11
|
+
- utils: Runtime utilities (spork_try, setup_runtime_env, etc.)
|
|
12
|
+
- testing: Module-local descriptors for declared tests
|
|
13
|
+
- ns: Namespace management (loading, registering, finding namespaces)
|
|
14
|
+
|
|
15
|
+
The runtime is what gets installed into user project environments.
|
|
16
|
+
The compiler (spork.compiler) depends on runtime.types for AST nodes,
|
|
17
|
+
but the runtime has no dependencies on the compiler.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from typing import Any, TypeVar, Union
|
|
21
|
+
|
|
22
|
+
# Re-export core functions
|
|
23
|
+
from spork.runtime.core import (
|
|
24
|
+
_PROTOCOL_IMPLS,
|
|
25
|
+
_PROTOCOLS,
|
|
26
|
+
LazySeq,
|
|
27
|
+
add,
|
|
28
|
+
assoc,
|
|
29
|
+
assoc_bang,
|
|
30
|
+
bit_and,
|
|
31
|
+
bit_and_not,
|
|
32
|
+
bit_not,
|
|
33
|
+
bit_or,
|
|
34
|
+
bit_shift_left,
|
|
35
|
+
bit_shift_right,
|
|
36
|
+
bit_xor,
|
|
37
|
+
concat,
|
|
38
|
+
conj,
|
|
39
|
+
conj_bang,
|
|
40
|
+
contains_q,
|
|
41
|
+
count,
|
|
42
|
+
cycle,
|
|
43
|
+
dec,
|
|
44
|
+
dedupe,
|
|
45
|
+
disj,
|
|
46
|
+
disj_bang,
|
|
47
|
+
dissoc,
|
|
48
|
+
dissoc_bang,
|
|
49
|
+
distinct,
|
|
50
|
+
div,
|
|
51
|
+
doall,
|
|
52
|
+
dorun,
|
|
53
|
+
drop,
|
|
54
|
+
drop_while,
|
|
55
|
+
empty,
|
|
56
|
+
even_q,
|
|
57
|
+
every,
|
|
58
|
+
first,
|
|
59
|
+
flatten,
|
|
60
|
+
frequencies,
|
|
61
|
+
get,
|
|
62
|
+
get_protocol_abc,
|
|
63
|
+
group_by,
|
|
64
|
+
inc,
|
|
65
|
+
interleave,
|
|
66
|
+
interpose,
|
|
67
|
+
into,
|
|
68
|
+
iterate,
|
|
69
|
+
keep,
|
|
70
|
+
keep_indexed,
|
|
71
|
+
lazy_seq,
|
|
72
|
+
map_indexed,
|
|
73
|
+
mapcat,
|
|
74
|
+
mod,
|
|
75
|
+
mul,
|
|
76
|
+
neg_q,
|
|
77
|
+
not_any,
|
|
78
|
+
not_every,
|
|
79
|
+
nth,
|
|
80
|
+
odd_q,
|
|
81
|
+
partition,
|
|
82
|
+
partition_all,
|
|
83
|
+
persistent_bang,
|
|
84
|
+
pop_bang,
|
|
85
|
+
pos_q,
|
|
86
|
+
protocol_dispatch,
|
|
87
|
+
protocol_register_virtual_subclass,
|
|
88
|
+
quot,
|
|
89
|
+
realized_q,
|
|
90
|
+
reduce,
|
|
91
|
+
reductions,
|
|
92
|
+
register_protocol_impl,
|
|
93
|
+
rest,
|
|
94
|
+
reverse,
|
|
95
|
+
runtime_register_protocol,
|
|
96
|
+
satisfies_protocol,
|
|
97
|
+
seq,
|
|
98
|
+
some,
|
|
99
|
+
sort,
|
|
100
|
+
sort_by,
|
|
101
|
+
split_at,
|
|
102
|
+
split_with,
|
|
103
|
+
spork_abs,
|
|
104
|
+
spork_filter,
|
|
105
|
+
spork_map,
|
|
106
|
+
spork_max,
|
|
107
|
+
spork_min,
|
|
108
|
+
spork_range,
|
|
109
|
+
spork_repeat,
|
|
110
|
+
sub,
|
|
111
|
+
take,
|
|
112
|
+
take_while,
|
|
113
|
+
transient,
|
|
114
|
+
zero_q,
|
|
115
|
+
zipmap,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Re-export JSON utilities
|
|
119
|
+
from spork.runtime.json import (
|
|
120
|
+
SporkJSONEncoder,
|
|
121
|
+
)
|
|
122
|
+
from spork.runtime.json import (
|
|
123
|
+
dump as json_dump,
|
|
124
|
+
)
|
|
125
|
+
from spork.runtime.json import (
|
|
126
|
+
dumps as json_dumps,
|
|
127
|
+
)
|
|
128
|
+
from spork.runtime.json import (
|
|
129
|
+
load as json_load,
|
|
130
|
+
)
|
|
131
|
+
from spork.runtime.json import (
|
|
132
|
+
load_spork as json_load_spork,
|
|
133
|
+
)
|
|
134
|
+
from spork.runtime.json import (
|
|
135
|
+
loads as json_loads,
|
|
136
|
+
)
|
|
137
|
+
from spork.runtime.json import (
|
|
138
|
+
loads_spork as json_loads_spork,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# Re-export PDS (persistent data structures)
|
|
142
|
+
from spork.pds import (
|
|
143
|
+
EMPTY_DOUBLE_VECTOR,
|
|
144
|
+
EMPTY_LONG_VECTOR,
|
|
145
|
+
EMPTY_MAP,
|
|
146
|
+
EMPTY_SET,
|
|
147
|
+
EMPTY_SORTED_VECTOR,
|
|
148
|
+
EMPTY_VECTOR,
|
|
149
|
+
Cons,
|
|
150
|
+
DoubleVector,
|
|
151
|
+
IntVector,
|
|
152
|
+
Map,
|
|
153
|
+
Set,
|
|
154
|
+
SortedVector,
|
|
155
|
+
TransientDoubleVector,
|
|
156
|
+
TransientIntVector,
|
|
157
|
+
TransientMap,
|
|
158
|
+
TransientSet,
|
|
159
|
+
TransientSortedVector,
|
|
160
|
+
TransientVector,
|
|
161
|
+
Vector,
|
|
162
|
+
cons,
|
|
163
|
+
hash_map,
|
|
164
|
+
hash_set,
|
|
165
|
+
sorted_vec,
|
|
166
|
+
vec,
|
|
167
|
+
vec_f64,
|
|
168
|
+
vec_i64,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Re-export types
|
|
172
|
+
from spork.runtime.testing import SporkTest, register_spork_test
|
|
173
|
+
from spork.runtime.types import (
|
|
174
|
+
_MISSING,
|
|
175
|
+
Decorated,
|
|
176
|
+
Keyword,
|
|
177
|
+
KwargsLiteral,
|
|
178
|
+
MapLiteral,
|
|
179
|
+
MatchError,
|
|
180
|
+
SetLiteral,
|
|
181
|
+
Symbol,
|
|
182
|
+
VectorLiteral,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Re-export utils
|
|
186
|
+
from spork.runtime.utils import (
|
|
187
|
+
__spork_ns_env__,
|
|
188
|
+
__spork_ns_get__,
|
|
189
|
+
__spork_refer_all__,
|
|
190
|
+
__spork_require__,
|
|
191
|
+
setup_runtime_env,
|
|
192
|
+
spork_kwargs_dict,
|
|
193
|
+
spork_kwargs_map,
|
|
194
|
+
spork_raise,
|
|
195
|
+
spork_setattr,
|
|
196
|
+
spork_try,
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
# Type variables for generic types
|
|
200
|
+
T = TypeVar("T")
|
|
201
|
+
K = TypeVar("K")
|
|
202
|
+
V = TypeVar("V")
|
|
203
|
+
T_co = TypeVar("T_co", covariant=True)
|
|
204
|
+
V_co = TypeVar("V_co", covariant=True)
|
|
205
|
+
|
|
206
|
+
# Type aliases for common patterns
|
|
207
|
+
List = Vector
|
|
208
|
+
Vec = Vector
|
|
209
|
+
Dict = Map
|
|
210
|
+
ConsCell = Cons
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def is_typed_collection(obj: Any) -> bool:
|
|
214
|
+
"""Check if an object is one of Spork's typed persistent collections."""
|
|
215
|
+
return isinstance(obj, (Vector, Map, Cons))
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def get_collection_type(obj: Any) -> Union[type, None]:
|
|
219
|
+
"""Get the collection type of a Spork persistent data structure."""
|
|
220
|
+
if isinstance(obj, Vector):
|
|
221
|
+
return Vector
|
|
222
|
+
elif isinstance(obj, Map):
|
|
223
|
+
return Map
|
|
224
|
+
elif isinstance(obj, Cons):
|
|
225
|
+
return Cons
|
|
226
|
+
return None
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
__all__ = [
|
|
230
|
+
# Types
|
|
231
|
+
"Symbol",
|
|
232
|
+
"Keyword",
|
|
233
|
+
"VectorLiteral",
|
|
234
|
+
"MapLiteral",
|
|
235
|
+
"SetLiteral",
|
|
236
|
+
"KwargsLiteral",
|
|
237
|
+
"Decorated",
|
|
238
|
+
"MatchError",
|
|
239
|
+
"SporkTest",
|
|
240
|
+
"register_spork_test",
|
|
241
|
+
"_MISSING",
|
|
242
|
+
# Persistent data structures
|
|
243
|
+
"Vector",
|
|
244
|
+
"Map",
|
|
245
|
+
"Set",
|
|
246
|
+
"Cons",
|
|
247
|
+
"DoubleVector",
|
|
248
|
+
"IntVector",
|
|
249
|
+
"TransientVector",
|
|
250
|
+
"TransientDoubleVector",
|
|
251
|
+
"TransientIntVector",
|
|
252
|
+
"TransientMap",
|
|
253
|
+
"TransientSet",
|
|
254
|
+
"EMPTY_VECTOR",
|
|
255
|
+
"EMPTY_DOUBLE_VECTOR",
|
|
256
|
+
"EMPTY_LONG_VECTOR",
|
|
257
|
+
"EMPTY_MAP",
|
|
258
|
+
"EMPTY_SET",
|
|
259
|
+
"EMPTY_SORTED_VECTOR",
|
|
260
|
+
"vec",
|
|
261
|
+
"vec_f64",
|
|
262
|
+
"vec_i64",
|
|
263
|
+
"hash_map",
|
|
264
|
+
"hash_set",
|
|
265
|
+
"sorted_vec",
|
|
266
|
+
"cons",
|
|
267
|
+
"SortedVector",
|
|
268
|
+
"TransientSortedVector",
|
|
269
|
+
# JSON
|
|
270
|
+
"SporkJSONEncoder",
|
|
271
|
+
"json_dump",
|
|
272
|
+
"json_dumps",
|
|
273
|
+
"json_load",
|
|
274
|
+
"json_loads",
|
|
275
|
+
"json_load_spork",
|
|
276
|
+
"json_loads_spork",
|
|
277
|
+
# Protocol system
|
|
278
|
+
"_PROTOCOLS",
|
|
279
|
+
"_PROTOCOL_IMPLS",
|
|
280
|
+
"runtime_register_protocol",
|
|
281
|
+
"get_protocol_abc",
|
|
282
|
+
"register_protocol_impl",
|
|
283
|
+
"protocol_register_virtual_subclass",
|
|
284
|
+
"protocol_dispatch",
|
|
285
|
+
"satisfies_protocol",
|
|
286
|
+
# Sequence operations
|
|
287
|
+
"first",
|
|
288
|
+
"rest",
|
|
289
|
+
"seq",
|
|
290
|
+
"nth",
|
|
291
|
+
"conj",
|
|
292
|
+
"assoc",
|
|
293
|
+
"dissoc",
|
|
294
|
+
"disj",
|
|
295
|
+
"get",
|
|
296
|
+
"count",
|
|
297
|
+
"contains_q",
|
|
298
|
+
"empty",
|
|
299
|
+
"into",
|
|
300
|
+
# Transients
|
|
301
|
+
"transient",
|
|
302
|
+
"persistent_bang",
|
|
303
|
+
"conj_bang",
|
|
304
|
+
"assoc_bang",
|
|
305
|
+
"dissoc_bang",
|
|
306
|
+
"disj_bang",
|
|
307
|
+
"pop_bang",
|
|
308
|
+
# Lazy sequences
|
|
309
|
+
"spork_map",
|
|
310
|
+
"spork_filter",
|
|
311
|
+
"take",
|
|
312
|
+
"take_while",
|
|
313
|
+
"drop",
|
|
314
|
+
"drop_while",
|
|
315
|
+
"concat",
|
|
316
|
+
"spork_repeat",
|
|
317
|
+
"cycle",
|
|
318
|
+
"iterate",
|
|
319
|
+
"spork_range",
|
|
320
|
+
"interleave",
|
|
321
|
+
"interpose",
|
|
322
|
+
"partition",
|
|
323
|
+
"partition_all",
|
|
324
|
+
"keep",
|
|
325
|
+
"keep_indexed",
|
|
326
|
+
"map_indexed",
|
|
327
|
+
"dedupe",
|
|
328
|
+
"distinct",
|
|
329
|
+
"flatten",
|
|
330
|
+
"mapcat",
|
|
331
|
+
# Predicates and reducers
|
|
332
|
+
"some",
|
|
333
|
+
"every",
|
|
334
|
+
"not_every",
|
|
335
|
+
"not_any",
|
|
336
|
+
"reduce",
|
|
337
|
+
"reductions",
|
|
338
|
+
# Collection utilities
|
|
339
|
+
"zipmap",
|
|
340
|
+
"group_by",
|
|
341
|
+
"frequencies",
|
|
342
|
+
"reverse",
|
|
343
|
+
"sort",
|
|
344
|
+
"sort_by",
|
|
345
|
+
"split_at",
|
|
346
|
+
"split_with",
|
|
347
|
+
"doall",
|
|
348
|
+
"dorun",
|
|
349
|
+
"realized_q",
|
|
350
|
+
# Math
|
|
351
|
+
"inc",
|
|
352
|
+
"dec",
|
|
353
|
+
"even_q",
|
|
354
|
+
"odd_q",
|
|
355
|
+
"pos_q",
|
|
356
|
+
"neg_q",
|
|
357
|
+
"zero_q",
|
|
358
|
+
"add",
|
|
359
|
+
"sub",
|
|
360
|
+
"mul",
|
|
361
|
+
"div",
|
|
362
|
+
"mod",
|
|
363
|
+
"quot",
|
|
364
|
+
"spork_max",
|
|
365
|
+
"spork_min",
|
|
366
|
+
"spork_abs",
|
|
367
|
+
# Bitwise
|
|
368
|
+
"bit_or",
|
|
369
|
+
"bit_and",
|
|
370
|
+
"bit_and_not",
|
|
371
|
+
"bit_xor",
|
|
372
|
+
"bit_not",
|
|
373
|
+
"bit_shift_left",
|
|
374
|
+
"bit_shift_right",
|
|
375
|
+
# Utils
|
|
376
|
+
"spork_try",
|
|
377
|
+
"spork_raise",
|
|
378
|
+
"spork_setattr",
|
|
379
|
+
"spork_kwargs_dict",
|
|
380
|
+
"spork_kwargs_map",
|
|
381
|
+
"setup_runtime_env",
|
|
382
|
+
"__spork_require__",
|
|
383
|
+
"__spork_ns_env__",
|
|
384
|
+
"__spork_ns_get__",
|
|
385
|
+
"__spork_refer_all__",
|
|
386
|
+
# Type variables
|
|
387
|
+
"T",
|
|
388
|
+
"T_co",
|
|
389
|
+
"K",
|
|
390
|
+
"V",
|
|
391
|
+
"V_co",
|
|
392
|
+
# Type aliases
|
|
393
|
+
"List",
|
|
394
|
+
"Vec",
|
|
395
|
+
"Dict",
|
|
396
|
+
"ConsCell",
|
|
397
|
+
# Utilities
|
|
398
|
+
"is_typed_collection",
|
|
399
|
+
"get_collection_type",
|
|
400
|
+
]
|