lispython 0.4.2__tar.gz → 0.4.3__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.
Files changed (51) hide show
  1. {lispython-0.4.2 → lispython-0.4.3}/PKG-INFO +1 -1
  2. {lispython-0.4.2 → lispython-0.4.3}/pyproject.toml +1 -1
  3. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/builtins.py +11 -1
  4. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/macros/sugar.lpy +4 -3
  5. lispython-0.4.3/tests/test_as_thread.py +49 -0
  6. {lispython-0.4.2 → lispython-0.4.3}/uv.lock +1 -1
  7. lispython-0.4.2/tests/test_as_thread.py +0 -36
  8. {lispython-0.4.2 → lispython-0.4.3}/.claude/settings.local.json +0 -0
  9. {lispython-0.4.2 → lispython-0.4.3}/.gitignore +0 -0
  10. {lispython-0.4.2 → lispython-0.4.3}/.pre-commit-config.yaml +0 -0
  11. {lispython-0.4.2 → lispython-0.4.3}/.vscode/settings.json +0 -0
  12. {lispython-0.4.2 → lispython-0.4.3}/LICENSE.md +0 -0
  13. {lispython-0.4.2 → lispython-0.4.3}/README.md +0 -0
  14. {lispython-0.4.2 → lispython-0.4.3}/docs/index.md +0 -0
  15. {lispython-0.4.2 → lispython-0.4.3}/docs/macros.md +0 -0
  16. {lispython-0.4.2 → lispython-0.4.3}/docs/syntax/expressions.md +0 -0
  17. {lispython-0.4.2 → lispython-0.4.3}/docs/syntax/overview.md +0 -0
  18. {lispython-0.4.2 → lispython-0.4.3}/docs/syntax/statements.md +0 -0
  19. {lispython-0.4.2 → lispython-0.4.3}/docs/usage/cli.md +0 -0
  20. {lispython-0.4.2 → lispython-0.4.3}/docs/usage/getting-started.md +0 -0
  21. {lispython-0.4.2 → lispython-0.4.3}/docs/version_macro.py +0 -0
  22. {lispython-0.4.2 → lispython-0.4.3}/docs/why-lispy.md +0 -0
  23. {lispython-0.4.2 → lispython-0.4.3}/mkdocs.yml +0 -0
  24. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/__init__.py +0 -0
  25. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/compiler/__init__.py +0 -0
  26. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/compiler/expr.py +0 -0
  27. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/compiler/literal.py +0 -0
  28. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/compiler/stmt.py +0 -0
  29. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/compiler/utils.py +0 -0
  30. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/importer.py +0 -0
  31. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/macro.py +0 -0
  32. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/meta_functions.py +0 -0
  33. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/nodes.py +0 -0
  34. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/parser.py +0 -0
  35. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core/utils.py +0 -0
  36. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/core_meta_functions.lpy +0 -0
  37. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/lsp/__init__.py +0 -0
  38. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/lsp/__main__.py +0 -0
  39. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/lsp/server.lpy +0 -0
  40. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/macros/__init__.py +0 -0
  41. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/macros/init.lpy +0 -0
  42. {lispython-0.4.2 → lispython-0.4.3}/src/lispy/tools.lpy +0 -0
  43. {lispython-0.4.2 → lispython-0.4.3}/tests/__init__.py +0 -0
  44. {lispython-0.4.2 → lispython-0.4.3}/tests/test_expr.py +0 -0
  45. {lispython-0.4.2 → lispython-0.4.3}/tests/test_gensym.py +0 -0
  46. {lispython-0.4.2 → lispython-0.4.3}/tests/test_include_meta.py +0 -0
  47. {lispython-0.4.2 → lispython-0.4.3}/tests/test_literal.py +0 -0
  48. {lispython-0.4.2 → lispython-0.4.3}/tests/test_meta_functions.py +0 -0
  49. {lispython-0.4.2 → lispython-0.4.3}/tests/test_parser.py +0 -0
  50. {lispython-0.4.2 → lispython-0.4.3}/tests/test_stmt.py +0 -0
  51. {lispython-0.4.2 → lispython-0.4.3}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lispython
3
- Version: 0.4.2
3
+ Version: 0.4.3
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lispython"
3
- version = "0.4.2"
3
+ version = "0.4.3"
4
4
  description = "Lisp-like Syntax for Python with Lisp-like Macros"
5
5
  authors = [{ name = "Jetack", email = "jetack23@gmail.com" }]
6
6
  license = { text = "MIT" }
@@ -1,4 +1,4 @@
1
- from lispy.core.nodes import Symbol
1
+ from lispy.core.nodes import Expression, Symbol, Wrapper
2
2
 
3
3
  _gensym_counter = 0
4
4
 
@@ -17,3 +17,13 @@ def gensym(prefix="gensym"):
17
17
  def reset_gensym_counter():
18
18
  global _gensym_counter
19
19
  _gensym_counter = 0
20
+
21
+
22
+ def replace_symbol(node, old, new):
23
+ if isinstance(node, Symbol) and node.value == old.value:
24
+ return new
25
+ if isinstance(node, Expression):
26
+ node.list = [replace_symbol(child, old, new) for child in node.list]
27
+ elif isinstance(node, Wrapper):
28
+ node.value = replace_symbol(node.value, old, new)
29
+ return node
@@ -31,11 +31,12 @@
31
31
  (defmacro as-> [expr name *forms]
32
32
  (if (== 0 (len forms))
33
33
  (return expr))
34
+ (= sym (gensym (str name)))
34
35
  (= stmts [])
35
- (stmts.append `(= ~name ~expr))
36
+ (stmts.append `(= ~sym ~expr))
36
37
  (for f in forms
37
- (stmts.append `(= ~name ~f)))
38
- (stmts.append name)
38
+ (stmts.append `(= ~sym ~(replace-symbol f name sym))))
39
+ (stmts.append sym)
39
40
  (return `(do ~@stmts)))
40
41
 
41
42
  (defmacro fn [*body]
@@ -0,0 +1,49 @@
1
+ from lispy.core.builtins import reset_gensym_counter
2
+ from lispy.tools import src_to_python_org
3
+
4
+ PREAMBLE = "(require lispy.macros *)\n"
5
+
6
+
7
+ class TestAsThread:
8
+ def setup_method(self):
9
+ reset_gensym_counter()
10
+
11
+ def test_no_forms(self):
12
+ assert src_to_python_org(PREAMBLE + "(as-> 42 x)") == "42"
13
+
14
+ def test_single_form(self):
15
+ result = src_to_python_org(PREAMBLE + "(as-> 0 x (+ x 1))")
16
+ assert "__x_0 = 0" in result
17
+ assert "__x_0 = __x_0 + 1" in result
18
+
19
+ def test_multiple_forms(self):
20
+ result = src_to_python_org(
21
+ PREAMBLE + "(as-> 0 x (+ x 10) (* 2 x) (str x))"
22
+ )
23
+ assert "__x_0 = 0" in result
24
+ assert "__x_0 = __x_0 + 10" in result
25
+ assert "__x_0 = 2 * __x_0" in result
26
+ assert "__x_0 = str(__x_0)" in result
27
+
28
+ def test_method_call(self):
29
+ result = src_to_python_org(
30
+ PREAMBLE + '(as-> "hello" s (.upper s))'
31
+ )
32
+ assert "__s_0 = 'hello'" in result
33
+ assert "__s_0 = __s_0.upper()" in result
34
+
35
+ def test_flexible_placement(self):
36
+ result = src_to_python_org(
37
+ PREAMBLE + "(as-> 1 x (+ 10 x) (- x 5))"
38
+ )
39
+ assert "__x_0 = 10 + __x_0" in result
40
+ assert "__x_0 = __x_0 - 5" in result
41
+
42
+ def test_does_not_shadow_outer_variable(self):
43
+ result = src_to_python_org(
44
+ PREAMBLE + "(= x 100)\n(as-> 0 x (+ x 10))\n(print x)"
45
+ )
46
+ assert "x = 100" in result
47
+ assert "print(x)" in result
48
+ assert "__x_0 = 0" in result
49
+ assert "__x_0 = __x_0 + 10" in result
@@ -260,7 +260,7 @@ wheels = [
260
260
 
261
261
  [[package]]
262
262
  name = "lispython"
263
- version = "0.4.2"
263
+ version = "0.4.3"
264
264
  source = { editable = "." }
265
265
  dependencies = [
266
266
  { name = "pygls" },
@@ -1,36 +0,0 @@
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