From b1e10a05e88e23086b7eb337bbbeb7c9910a1f62 Mon Sep 17 00:00:00 2001 From: Eric Wolf Date: Thu, 22 Sep 2022 04:53:12 +0200 Subject: [PATCH] correct README statement about recursive terms BetaNormalisingVisitor can not produce cycles because it does not modify terms, preventing them from referencing terms available after their construction. --- README.md | 8 ++------ lambda_calculus/__init__.py | 2 +- pyproject.toml | 2 +- tests/visitors/test_normalisation.py | 11 +++++++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 50a24f6..0dc48a0 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,9 @@ use predefined ones from the `terms` subpackage. This package is intended to be used for educational purposes and is not optimized for speed. -Furthermore, it expects all terms to be finite, which means the absense of cycles. +Furthermore, it expects all terms to be finite, which means the absence of cycles. -This results in the Visitor for term normalisation included in this package (`BetaNormalisingVisitor`) -having problems when handling terms which are passed a reference to themselves during evaluation, -which is the case for all recursive functions. - -`RecursionError` may be raised if the visitors get passed an infinite term. +`RecursionError` may be raised if the visitors get passed an infinite term or the evaluation is too complex. ## Requirements diff --git a/lambda_calculus/__init__.py b/lambda_calculus/__init__.py index dc7a5b3..c356822 100644 --- a/lambda_calculus/__init__.py +++ b/lambda_calculus/__init__.py @@ -4,7 +4,7 @@ from .terms import Variable, Abstraction, Application -__version__ = "2.2.0" +__version__ = "2.2.1" __author__ = "Eric Niklas Wolf" __email__ = "eric_niklas.wolf@mailbox.tu-dresden.de" __all__ = ( diff --git a/pyproject.toml b/pyproject.toml index 1332a87..d0ee5e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "lambda_calculus" -version = "2.2.0" +version = "2.2.1" description = "Implementation of the Lambda calculus" requires-python = ">=3.10" keywords = [] diff --git a/tests/visitors/test_normalisation.py b/tests/visitors/test_normalisation.py index 087c600..63bd06c 100644 --- a/tests/visitors/test_normalisation.py +++ b/tests/visitors/test_normalisation.py @@ -145,3 +145,14 @@ def test_skip_intermediate(self) -> None: ), Variable("z") ) + + def test_self_argument(self) -> None: + """test behavior when applying a term to itself""" + term = Variable("a").apply_to(Variable("b")).abstract("a") + term_copy = Variable("a").apply_to(Variable("b")).abstract("a") + self.assertEqual( + self.visitor.skip_intermediate(term.apply_to(term)), + Variable("b").apply_to(Variable("b")) + ) + # prevent original for being modified + self.assertEqual(term, term_copy)