lispython 0.4.1__tar.gz → 0.4.2__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.
- {lispython-0.4.1 → lispython-0.4.2}/PKG-INFO +1 -4
- {lispython-0.4.1 → lispython-0.4.2}/README.md +0 -3
- {lispython-0.4.1 → lispython-0.4.2}/docs/macros.md +19 -0
- {lispython-0.4.1 → lispython-0.4.2}/pyproject.toml +1 -1
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/macros/sugar.lpy +10 -0
- lispython-0.4.2/tests/test_as_thread.py +36 -0
- {lispython-0.4.1 → lispython-0.4.2}/uv.lock +1 -1
- {lispython-0.4.1 → lispython-0.4.2}/.claude/settings.local.json +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/.gitignore +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/.pre-commit-config.yaml +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/.vscode/settings.json +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/LICENSE.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/index.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/syntax/expressions.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/syntax/overview.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/syntax/statements.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/usage/cli.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/usage/getting-started.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/version_macro.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/docs/why-lispy.md +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/mkdocs.yml +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/__init__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/builtins.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/compiler/__init__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/compiler/expr.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/compiler/literal.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/compiler/stmt.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/compiler/utils.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/importer.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/macro.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/meta_functions.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/nodes.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/parser.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core/utils.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/core_meta_functions.lpy +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/lsp/__init__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/lsp/__main__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/lsp/server.lpy +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/macros/__init__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/macros/init.lpy +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/src/lispy/tools.lpy +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/__init__.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_expr.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_gensym.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_include_meta.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_literal.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_meta_functions.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_parser.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/test_stmt.py +0 -0
- {lispython-0.4.1 → lispython-0.4.2}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lispython
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.2
|
|
4
4
|
Summary: Lisp-like Syntax for Python with Lisp-like Macros
|
|
5
5
|
Project-URL: Homepage, https://jetack.github.io/lispython
|
|
6
6
|
Project-URL: Repository, https://github.com/jetack/lispython
|
|
@@ -103,9 +103,6 @@ Use [`lpy-mode`](https://github.com/jetack/lpy-mode) for syntax highlighting and
|
|
|
103
103
|
- [ ] REPL should track history and arrow key navigation
|
|
104
104
|
- [ ] REPL multi-line input support
|
|
105
105
|
- [ ] Better compilation error messages
|
|
106
|
-
### Macro System
|
|
107
|
-
- [ ] `as->` macro for syntactic sugar
|
|
108
|
-
- [ ] `gensym` for avoiding name collision
|
|
109
106
|
### Python AST
|
|
110
107
|
- [ ] `type_comment` never considered. Later, it should be covered
|
|
111
108
|
- [ ] Any missing AST nodes in the version 3.12+
|
|
@@ -81,9 +81,6 @@ Use [`lpy-mode`](https://github.com/jetack/lpy-mode) for syntax highlighting and
|
|
|
81
81
|
- [ ] REPL should track history and arrow key navigation
|
|
82
82
|
- [ ] REPL multi-line input support
|
|
83
83
|
- [ ] Better compilation error messages
|
|
84
|
-
### Macro System
|
|
85
|
-
- [ ] `as->` macro for syntactic sugar
|
|
86
|
-
- [ ] `gensym` for avoiding name collision
|
|
87
84
|
### Python AST
|
|
88
85
|
- [ ] `type_comment` never considered. Later, it should be covered
|
|
89
86
|
- [ ] Any missing AST nodes in the version 3.12+
|
|
@@ -56,6 +56,25 @@ Just change `def` in function definition to `defmacro`. And macros usually retur
|
|
|
56
56
|
```
|
|
57
57
|
You can find more in `src/lispython/macros/sugar.lpy`.
|
|
58
58
|
|
|
59
|
+
### `as->`
|
|
60
|
+
Unlike `->` (thread first) and `->>` (thread last), `as->` lets you name the threaded value and place it anywhere in each form:
|
|
61
|
+
```python
|
|
62
|
+
(as-> 0 x
|
|
63
|
+
(+ x 10) ;; x = 10
|
|
64
|
+
(* 2 x) ;; x = 20
|
|
65
|
+
(str x)) ;; x = "20"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
This expands to:
|
|
69
|
+
```python
|
|
70
|
+
x = 0
|
|
71
|
+
x = x + 10
|
|
72
|
+
x = 2 * x
|
|
73
|
+
x = str(x)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Useful when the threaded value doesn't always go in the first or last position.
|
|
77
|
+
|
|
59
78
|
## gensym
|
|
60
79
|
`gensym` generates unique symbols to avoid variable name collisions in macros. It is automatically available inside `defmacro` bodies.
|
|
61
80
|
|
|
@@ -28,6 +28,16 @@
|
|
|
28
28
|
(return `(->> ~f ~@rest)))
|
|
29
29
|
(return `(-> (~f ~x) ~@rest))))
|
|
30
30
|
|
|
31
|
+
(defmacro as-> [expr name *forms]
|
|
32
|
+
(if (== 0 (len forms))
|
|
33
|
+
(return expr))
|
|
34
|
+
(= stmts [])
|
|
35
|
+
(stmts.append `(= ~name ~expr))
|
|
36
|
+
(for f in forms
|
|
37
|
+
(stmts.append `(= ~name ~f)))
|
|
38
|
+
(stmts.append name)
|
|
39
|
+
(return `(do ~@stmts)))
|
|
40
|
+
|
|
31
41
|
(defmacro fn [*body]
|
|
32
42
|
(return `(lambda ~@body)))
|
|
33
43
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from lispy.tools import src_to_python_org
|
|
2
|
+
|
|
3
|
+
PREAMBLE = "(require lispy.macros *)\n"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestAsThread:
|
|
7
|
+
def test_no_forms(self):
|
|
8
|
+
assert src_to_python_org(PREAMBLE + "(as-> 42 x)") == "42"
|
|
9
|
+
|
|
10
|
+
def test_single_form(self):
|
|
11
|
+
result = src_to_python_org(PREAMBLE + "(as-> 0 x (+ x 1))")
|
|
12
|
+
assert "x = 0" in result
|
|
13
|
+
assert "x = x + 1" in result
|
|
14
|
+
|
|
15
|
+
def test_multiple_forms(self):
|
|
16
|
+
result = src_to_python_org(
|
|
17
|
+
PREAMBLE + "(as-> 0 x (+ x 10) (* 2 x) (str x))"
|
|
18
|
+
)
|
|
19
|
+
assert "x = 0" in result
|
|
20
|
+
assert "x = x + 10" in result
|
|
21
|
+
assert "x = 2 * x" in result
|
|
22
|
+
assert "x = str(x)" in result
|
|
23
|
+
|
|
24
|
+
def test_method_call(self):
|
|
25
|
+
result = src_to_python_org(
|
|
26
|
+
PREAMBLE + '(as-> "hello" s (.upper s))'
|
|
27
|
+
)
|
|
28
|
+
assert "s = 'hello'" in result
|
|
29
|
+
assert "s = s.upper()" in result
|
|
30
|
+
|
|
31
|
+
def test_flexible_placement(self):
|
|
32
|
+
result = src_to_python_org(
|
|
33
|
+
PREAMBLE + "(as-> 1 x (+ 10 x) (- x 5))"
|
|
34
|
+
)
|
|
35
|
+
assert "x = 10 + x" in result
|
|
36
|
+
assert "x = x - 5" in result
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|