Skip to content

Commit 064625a

Browse files
committed
Updated changelog and documentation main page, and updates tests accordingly.
1 parent 8bd369a commit 064625a

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 1.1.0 - Compatibility with standard functions
2+
3+
* It is now possible to use any function in a lambda expression, through use of the `make_lambda_friendly` method (see documentation)
4+
* All methods from the `math.py` module are provided in a lambda-friendly way by the package for convenience
5+
* Updated documentation accordingly, and made main page clearer
6+
* Renamed class _InputEvaluator into _LambdaExpression
7+
18
### 1.0.0 - First public version
29

310
* Initial fork from [valid8](https://github.com/smarie/python-valid8) sources.

docs/index.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,56 @@ print(say_hello_function) # "'Hello, ' + s + ' !'"
4747
Most of python syntax can be used in an expression:
4848

4949
```python
50-
from mini_lambda import x, s, _
50+
from mini_lambda import x, s, _, Log2
5151

5252
# various lambda functions
5353
is_lowercase = _( s.islower() )
5454
get_prefix_upper_shebang = _( s[0:4].upper() + ' !' )
5555
numeric_test_1 = _( -x > x ** 2 )
5656
numeric_test_2 = _( ((1 - 2 * x) <= -x) | (-x > x ** 2) )
57+
complex_identity = _( Log2(2 ** x) )
5758

5859
# use the functions
5960
is_lowercase('Hello') # returns False
6061
get_prefix_upper_shebang('hello') # returns 'HELL !'
6162
numeric_test_1(0.5) # returns False
6263
numeric_test_2(1) # returns True
64+
complex_identity(10) # returns 10
6365

6466
# string representation
6567
print(is_lowercase) # s.islower()
6668
print(get_prefix_upper_shebang) # s[0:4].upper() + ' !'
6769
print(numeric_test_1) # -x > x ** 2
6870
print(numeric_test_2) # (1 - 2 * x <= -x) | (-x > x ** 2)
71+
print(complex_identity) # log2(2 ** x)
6972
```
7073

71-
If you know python you should feel at home here, except for the fact that `or` and `and` should be replaced with their bitwise equivalents `|` and `&`.
74+
If you know python you should feel at home here, except for two things:
7275

73-
Note that the printed version provides the minimal equivalent representation taking into account the operator precedence. Hence `numeric_test_2` got rid of my useless parenthesis. This is **not** a mathematical simplification like in SymPy, i.e. `x - x` will not be simplified to `0`.
76+
* `or` and `and` should be replaced with their bitwise equivalents `|` and `&`
77+
* standard unbound (=package-level) methods need to be made lambda-friendly before use. For convenience all of the methods from the `math.py` module are provided in a lambda-friendly way by this package, hence the `from mini_lambda import Log2` above.
7478

75-
There are of course a few limitations to `mini_lambda` as compared to full-flavoured python `lambda` functions, the main one being that you can't mix more than one variable in the same expression for now. Check the [Usage](./usage/) page for more details.
79+
Note that the printed version provides the minimal equivalent representation taking into account the operator precedence. Hence `numeric_test_2` got rid of my useless parenthesis. This is **not** a mathematical simplification like in [SymPy](http://www.sympy.org/fr/), i.e. `x - x` will **not** be simplified to `0`.
80+
81+
There are of course a few limitations to `mini_lambda` as compared to full-flavoured python `lambda` functions, the main ones being that
82+
83+
* you can't mix more than one variable in the same expression for now.
84+
* `list`/`tuple`/`set`/`dict` comprehensions are not supported
85+
* `... if ... else ...` ternary conditional expressions are not supported either
86+
87+
Check the [Usage](./usage/) page for more details.
7688

7789

7890
## Main features
7991

8092
* More compact lambda expressions for single-variable functions
8193
* Overriding all operators that can be overriden as of today in python 3.6: the remaining limits come from the language itself, for example chained comparisons are not supported as python casts the partial results to boolean.
82-
* printability: expressions can be turned to string representation in order to (hopefully) get interpretable messages more easily, for example when the expression is used in a validation context (see [valid8](https://github.com/smarie/python-valid8))
94+
* printability: expressions can be turned to string representation in order to (hopefully) get interpretable messages more easily, for example when the expression is used in a validation context (that is what I try to do with [valid8](https://github.com/smarie/python-valid8))
8395

8496

8597
## See Also
8698

87-
The much-broader debate in the python community about alernate lambda syntaxes is interesting, see [here](https://wiki.python.org/moin/AlternateLambdaSyntax)
99+
The much-broader debate in the python community about alternate lambda syntaxes is interesting, see [here](https://wiki.python.org/moin/AlternateLambdaSyntax)
88100

89101
### Equivalent (python-first)
90102

@@ -107,6 +119,7 @@ A bit far from the topic but related:
107119
These libraries create functions from string expressions. Therefore you cannot rely on your favourite IDE to check your expressions, but it might not be a problem for some users/use cases.
108120

109121
* [simpleeval](https://github.com/danthedeckie/simpleeval)
122+
* ...
110123

111124

112125
### Others

mini_lambda/tests/test_readme.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,34 @@ def test_doc_index_1():
2424
def test_doc_index_2():
2525
""" Tests that the second example in the documentation main page works """
2626

27-
from mini_lambda import s, x, _
27+
from mini_lambda import s, x, _, Log2
2828

2929
# various lambda functions
3030
is_lowercase = _(s.islower())
3131
get_prefix_upper_shebang = _(s[0:4].upper() + ' !')
3232
numeric_test_1 = _(-x > x ** 2)
3333
numeric_test_2 = _(((1 - 2 * x) <= -x) | (-x > x ** 2))
34+
complex_identity = _(Log2(2 ** x))
3435

3536
# use the functions
3637
assert is_lowercase('Hello') is False
3738
assert get_prefix_upper_shebang('hello') == 'HELL !'
3839
assert numeric_test_1(0.5) is False
3940
assert numeric_test_2(1) is True
41+
assert complex_identity(10) == 10
4042

4143
# string representation
4244
print(is_lowercase) # s.islower()
4345
print(get_prefix_upper_shebang) # s[0:4].upper() + ' !'
4446
print(numeric_test_1) # -x > x ** 2
4547
print(numeric_test_2) # (1 - 2 * x <= -x) | (-x > x ** 2)
48+
print(complex_identity) # log2(2 ** x)
4649

4750
assert str(is_lowercase) == 's.islower()'
4851
assert str(get_prefix_upper_shebang) == "s[0:4].upper() + ' !'"
4952
assert str(numeric_test_1) == '-x > x ** 2'
5053
assert str(numeric_test_2) == '(1 - 2 * x <= -x) | (-x > x ** 2)'
54+
assert str(complex_identity) == 'log2(2 ** x)'
5155

5256

5357
# def test_readme_1():

0 commit comments

Comments
 (0)