Skip to content

Commit 222f41c

Browse files
committed
fix BetaNormalisingVisitor
The Visitor was missing __slots__ and a return after visiting a reduced application
1 parent ff09d8a commit 222f41c

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

lambda_calculus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .terms import Variable, Abstraction, Application
66

7-
__version__ = "1.6.0"
7+
__version__ = "1.6.1"
88
__author__ = "Eric Niklas Wolf"
99
__email__ = "[email protected]"
1010
__all__ = (

lambda_calculus/visitors/normalisation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
class BetaNormalisingVisitor(Visitor[Iterator[terms.Term[str]], str]):
2020
"""
2121
Visitor which transforms a term into its beta normal form,
22-
yielding intermediate results
22+
yielding intermediate results until it is reached
2323
"""
2424

25+
__slots__ = ()
26+
2527
def visit_variable(self, variable: terms.Variable[str]) -> Iterator[terms.Variable[str]]:
2628
"""visit a Variable term"""
2729
return iter(())
@@ -51,6 +53,7 @@ def visit_application(self, application: terms.Application[str]) -> Iterator[ter
5153
)
5254
yield reduced
5355
yield from reduced.accept(self)
56+
return
5457
case _:
5558
abstraction = transformation
5659
# no redex, continue with argument

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "lambda_calculus"
3-
version = "1.6.0"
3+
version = "1.6.1"
44
description = "Implementation of the Lambda calculus"
55
requires-python = ">=3.10"
66
keywords = []

tests/visitors/test_normalisation.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ def test_order(self) -> None:
6363
self.assertEqual(
6464
list(
6565
Application(
66-
Abstraction("x", Variable("z")),
66+
Application(
67+
Abstraction("a", Variable("a")),
68+
Abstraction("x", Variable("z"))
69+
),
6770
Application(
6871
triple,
6972
triple
7073
)
7174
).accept(self.visitor)
7275
),
7376
[
77+
Application(
78+
Abstraction("x", Variable("z")),
79+
Application(
80+
triple,
81+
triple
82+
)
83+
),
7484
Variable("z")
7585
]
7686
)

0 commit comments

Comments
 (0)