by amelius · 6y ago · 0 comments
>>> f = lambda x: (
... (
... print('a') or
... print('b')
... ) if x % 2
... else (
... print('c') or
... print('d')
... )
... )
>>> f(42)
c
d
>>> f(43)
a
bThat is strikingly hideous. After such knowledge, what forgiveness?
The walrus operator moves Python closer to the expressions-camp.
In practice, the bigger problem with a more functional Python is that the ubiquitous dicts don't have nice and concise operators for persistent operations. Eg you can concatenate two lists via +, but dicts are more cumbersome.
Though that improved a bit, {dictA, dictB} mostly solves that problem. But more operators would be useful.
And, of course, lack of tail call elimination puts a damper on things. You can mostly work around that problem, but eg implementing state machines as mutually recursive functions is going to be a pain.
Which looks a bit better.