I need to define a pure function that takes two arguments and returns their quotient. If the divisor is 0
then I want to return 0
.
If I had a named function then I would do
div[_, 0] := 0
div[x_, y_] := x / y
how to do the same sort of pattern matching on arguments in a pure function #1 / #2 &
?
Try something like
If[#2 == 0, 0, #1/#2] &
for your pure function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With