kachayev / fn.py

Functional programming in Python: implementation of missing features to enjoy FP
Other
3.35k stars 204 forks source link

how to use _ in a function #64

Closed laocan closed 10 years ago

laocan commented 10 years ago

I've try : print math.sin(_) it turn out to be wrong, but it works for: lambda x: math.sin(x)

Does _ always be same as lambda caluse? any limitation? thx ~~

kachayev commented 10 years ago

@laocan There is no way in Python to work with expressions like math.sin(_) cause of evaluation order. And, btw, there is no necessity for doing this in you example. math.sin(_) most probably means lambda x: math.sin(x) which is equivalent to math.sin.

microamp commented 10 years ago

I would also like to suggest having a look at the tests. It does cover most of operators (e.g. operator.add). It also handles method calls as well as some neat stuff like slices!

kachayev commented 10 years ago

BTW, If you need to express math.ldexp(10, _) use partial(math.ldexp, 10). If you need math.ldexp(_, 10) use partial(flip(math.ldexp), 10).

Is there something else that I can help you with?

laocan commented 10 years ago

I got it. thx~