Re:Toolz: A functional standard library for Python
by raymondh on Friday January 22, 2021 @05:53PM
(#25877303)
Actually there is a let and let* equivalent as well:
(let* ((v1 e1) (v2 e2)) e3) ⟶ ((v1:=e1), (v2:=e2), e3)[-1]
Dr. Racket example: > (let* ((x (+ 3 4)) (y (* x x))) (+ y (- x) 8))
50
Python equivalent: >>> ((x:=3+4), (y:=x**2), y-x+8)[-1]
50
Re:Toolz: A functional standard library for Python
by Iwan-Zotow on Monday January 25, 2021 @01:29PM
(#25906781)
Yes, with walrus expression, lambda gains a lot of flexibility
Re:Toolz: A functional standard library for Python
by c-cube on Saturday January 23, 2021 @11:12AM
(#25883284)
Except :
- python scoping is not really lexical (and it captures variables, not the values they contain) - python is statement based, so lambdas are less powerful than in scheme.
So not really the same thing.
Python's lambda does pretty much what you would expect from Scheme. It creates a callable the binds arguments to parameters in a lexically scoped namespace and then evaluates the body of the lambda in that namespace. And with an open parenthesis, you can write multiline lambdas and indent it however you want.
All the usual wizardry is possible:
Also, Python has rough equivalents to some special forms in Scheme: Some statements do have a functional form but aren't well known: You have map(), filter(), partial(), and reduce(). The operator module provides function equivalents for most operators. Also, the itertools were directly based on their equivalents in functional languages or array manipulation languages.That said, Python does lack some essential tooling that you would really miss: