# Suggestion: Explicit anonymous functors?

**URL:** <https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692>\
**Category:** Internals & Design\
**Created:** [February 4, 2024, 8:33am UTC](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692 "2024-02-04T08:33:19Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [February 4, 2024, 9:17pm UTC](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692/21 "2024-02-04T21:17:31Z")

</div>

> [@sgaure](#):
>
> would scream about `c`

If `c` is hidden, why not `+`? I don’t think I’d go for this, because there isn’t any ambiguity or confusion about what `+ c` means in that context. I like the issues I linked because they resolve common ambiguities and mistakes.

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [February 4, 2024, 9:23pm UTC](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692/22 "2024-02-04T21:23:01Z")

</div>

> [@jar1](#):
>
> If `c` is hidden, why not `+`?

Because `+` is a global, or module level, identifier. I said “outer local scopes”. If you have defined something like ⊕ in a local scope, or have your own local `+` it would not be visible.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 4, 2024, 9:49pm UTC](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692/23 "2024-02-04T21:49:43Z")

</div>

The actually important characteristic there is `+` is `const`. Variables that can’t get reassigned are safe to share, no reason to stop that. On the other hand, if you have a non-`const` global variable, you get the same problem when you make an edit without thinking it through. However, a variable assignment in a local scope defaults to not borrowing from a global scope because a global scope can be scattered across multiple files, which is too annoying to be aware of all at once.

With this in mind, your `c` example is actually a significantly different proposal from the `tmp` example. `c` is not reassigned, so in normal Julia nothing stops the scope from automatically borrowing `c`. `tmp` is assigned, so it only automatically borrows outer local `tmp`. Again, I’ve mulled over these before with many very patient commenters, and no tweaks make anything generally easier. You really should know what variables are inside the entire function when you’re making edits. If your function is too big to do that, split it.

---

<div class="post-metadata">

**Author:** ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)\
**Post date:** [February 4, 2024, 10:12pm UTC](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692/24 "2024-02-04T22:12:37Z")

</div>

> [@Benny](#):
>
> no tweaks make anything generally easier. You really should know what variables are inside the entire function when you’re making edits. If your function is too big to do that, split it.

I agree to that. My idea was just to suggest an extension which e.g. could be part of coding style guidelines in particular projects to minimize such risks. In some contexts certain variable names end up being all over the place, reused for almost the same purpose. I can see that there is a certain amount of work implementing this extension, which I’m capable of doing myself, but I can’t see any particular downsides. It could be it’s not of much use for the occasional user, or the typical scientist, or the newcomer to julia. But for larger projects stretching over time with different developers, such mechanisms for avoiding mess might be useful. Or, maybe not.

[Previous page](https://discourse.julialang.org/t/suggestion-explicit-anonymous-functors/109692.md?page=1)
