Use anonymous functions for f (f = x -> x and f = x -> -x), see e.g. Defining a function inside if...else..end NOT as expected?. There is also an issue about this that I can’t find now.
Use anonymous functions for f (f = x -> x and f = x -> -x), see e.g. Defining a function inside if...else..end NOT as expected?. There is also an issue about this that I can’t find now.