# Struct Encapsulation Question for Optimization Test Set

**URL:** <https://discourse.julialang.org/t/struct-encapsulation-question-for-optimization-test-set/66645>\
**Category:** New to Julia\
**Created:** [August 19, 2021, 12:07am UTC](https://discourse.julialang.org/t/struct-encapsulation-question-for-optimization-test-set/66645 "2021-08-19T00:07:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)\
**Post date:** [August 19, 2021, 1:40am UTC](https://discourse.julialang.org/t/struct-encapsulation-question-for-optimization-test-set/66645/4 "2021-08-19T01:40:18Z")

</div>

> [@danphenderson](#):
>
> In response to looping over the files, thank you for the warning. I honestly didn’t put much thought into it because it worked. My approach to loop over the files was to avoid having writing 44 include statements. Hopefully, more problems will be added in time to make the matters worse. How would you do it?

I don’t know enough about your problem to give a strong suggestion. Often I’d tend to explicitly write out an array of functions, but that assumes each file’s content is fairly short. If not, using include might be the right approach.

> [@danphenderson](#):
>
> As for the anonymous function suggestion, that is a great idea apart from one issue! Ssome specifications are really long and it would be very illegible. So I need to be able to define it by some reference then put it into my struct, which implies the function is no longer anonymous.

I’m not sure I follow. In Julia, there is a distinction between a named function and an anonymous function bound to a name.

```julia
julia> f = x -> begin
     y = x + 1
     z = y * 2
     return z^2
end
#1 (generic function with 1 method)

julia> function g(x)
    y = x + 1
    z = y * 2
    return z^2
end
g (generic function with 1 method)

julia> f(1)
16

julia> g(1)
16

```

Does that address your concern?

---

_[View the full topic](https://discourse.julialang.org/t/struct-encapsulation-question-for-optimization-test-set/66645)._
