# Is there a way to write a function into JLD or other h5 file?

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-write-a-function-into-jld-or-other-h5-file/77718>\
**Category:** General Usage\
**Tags:** jld2\
**Created:** [March 10, 2022, 8:48pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-function-into-jld-or-other-h5-file/77718 "2022-03-10T20:48:03Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [March 10, 2022, 11:36pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-write-a-function-into-jld-or-other-h5-file/77718/2 "2022-03-10T23:36:01Z")

</div>

I know BSON works if you make your function an anonymous function:

```julia
using BSON
f = x -> x^2
@save "f.bson" f
# in new session
BSON.@load "f.bson" f
f(3) # 9

```

although it [can’t have](https://github.com/JuliaIO/BSON.jl/issues/39) keyword arguments. I don’t think JLD2 works with any unfortunately, but maybe its [in the works](https://github.com/JuliaIO/JLD2.jl/pull/316).

---

_[View the full topic](https://discourse.julialang.org/t/is-there-a-way-to-write-a-function-into-jld-or-other-h5-file/77718)._
