This is yet another case of Confused by behaviour of nested functions , which is definitely an unfortunate gotcha of the language. As discussed in that thread, it’s usually better to conditionally return a different anonymous function rather than conditionally adding or redefining methods like that.
rdeits
2
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Finding the number of arguments of an anonymous function | 31 | 3508 | May 20, 2019 | |
| Extended function not being seen (Is explicity imported) | 5 | 492 | December 3, 2020 | |
| Overwriting functions | 7 | 10329 | November 22, 2016 | |
| Confusing dispatch problem | 9 | 487 | February 6, 2023 | |
| Cool idea: define a function conditionally. Even more powerful than traits | 30 | 1266 | March 8, 2020 |