Skip to content

Commit f0af663

Browse files
committed
add BetaNormalisingVisitor.skip_intermediate
1 parent 222f41c commit f0af663

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
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.1"
7+
__version__ = "1.7.0"
88
__author__ = "Eric Niklas Wolf"
99
__email__ = "[email protected]"
1010
__all__ = (

lambda_calculus/visitors/normalisation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class BetaNormalisingVisitor(Visitor[Iterator[terms.Term[str]], str]):
2424

2525
__slots__ = ()
2626

27+
def skip_intermediate(self, term: terms.Term[str]) -> terms.Term[str]:
28+
"""return the beta normal form directly"""
29+
result = term
30+
for intermediate in term.accept(self):
31+
result = intermediate
32+
return result
33+
2734
def visit_variable(self, variable: terms.Variable[str]) -> Iterator[terms.Variable[str]]:
2835
"""visit a Variable term"""
2936
return iter(())

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.1"
3+
version = "1.7.0"
44
description = "Implementation of the Lambda calculus"
55
requires-python = ">=3.10"
66
keywords = []

tests/visitors/test_normalisation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,16 @@ def test_no_normal_form(self) -> None:
119119
if iteration > 10:
120120
break
121121
self.assertEqual(transformation, term)
122+
123+
def test_skip_intermediate(self) -> None:
124+
"""test skipping of intermediate results"""
125+
self.assertEqual(
126+
self.visitor.skip_intermediate(Abstraction("a", Variable("z"))),
127+
Abstraction("a", Variable("z"))
128+
)
129+
self.assertEqual(
130+
self.visitor.skip_intermediate(
131+
Application(Abstraction("a", Variable("a")), Variable("z"))
132+
),
133+
Variable("z")
134+
)

0 commit comments

Comments
 (0)