`foo = () -> 3` vs. `foo() = 3`

Just for completeness, another small difference is how they’re serialized. For the anonymous version, the function definition is actually serialized, where as the non-anonymous one just the name is serialized. The niche place where this might come up is when using Distributed’s auto-global shipping, so e.g. this works,

foo = () -> 3
@fetch foo() # foo definition shipped to worker, run there, answer returned

whereas the non-anonymous version you need to have foo actually defined on all workers (since only its name is serialized), which ammounts to an @everywhere

foo() = 3
@fetch foo() # error

@everywhere foo() = 3
@fetch foo() # works
2 Likes