Skip to content

Commit 8a58144

Browse files
committed
add predefined variables
Inspired by `sympy.abc`
1 parent 9b067e5 commit 8a58144

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

docs/api/terms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Package terms
44
.. toctree::
55
:maxdepth: 2
66

7+
terms/abc
78
terms/logic
89
terms/arithmetic
910
terms/pairs

docs/api/terms/abc.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Module abc
2+
==========
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
.. automodule:: lambda_calculus.terms.abc
8+
:members:

src/lambda_calculus/terms/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"Variable",
1818
"Abstraction",
1919
"Application",
20+
"abc",
2021
"arithmetic",
2122
"logic",
2223
"pairs",

src/lambda_calculus/terms/abc.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python3
2+
3+
"""Predefined Variables for all ASCII letters"""
4+
5+
from string import ascii_letters
6+
from . import Variable
7+
8+
__all__ = tuple(ascii_letters)
9+
10+
# better IDE autocompletion
11+
a, b, c, d, e, f, g, h, i, j = map(Variable, "abcdefghij")
12+
k, l, m, n, o, p, q, r, s, t = map(Variable, "klmnopqrst")
13+
u, v, w, x, y, z = map(Variable, "uvwxyz")
14+
15+
A, B, C, D, E, F, G, H, I, J = map(Variable, "ABCDEFGHIJ")
16+
K, L, M, N, O, P, Q, R, S, T = map(Variable, "KLMNOPQRST")
17+
U, V, W, X, Y, Z = map(Variable, "UVWXYZ")

tests/terms/test_abc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python3
2+
3+
"""Tests for the predefined variables"""
4+
5+
from unittest import TestCase
6+
from string import ascii_letters
7+
from lambda_calculus.terms import Variable, abc
8+
9+
10+
class PredefinedVariablesTest(TestCase):
11+
"""Tests for the predefined variables"""
12+
13+
def test_complete(self) -> None:
14+
"""Check whether all letters exist"""
15+
self.assertEqual(tuple(ascii_letters), abc.__all__)
16+
for letter in ascii_letters:
17+
self.assertTrue(hasattr(abc, letter))
18+
19+
def test_variables(self) -> None:
20+
"""Test the predefined variables"""
21+
for letter in ascii_letters:
22+
variable = getattr(abc, letter)
23+
self.assertIsInstance(variable, Variable)
24+
self.assertEqual(variable.name, letter)

0 commit comments

Comments
 (0)