# Serializing Functions / Methods / Closures

**URL:** https://discourse.julialang.org/t/serializing-functions-methods-closures/57061
**Category:** Internals & Design
**Tags:** question, closure
**Created:** [March 13, 2021, 7:43am UTC](https://discourse.julialang.org/t/serializing-functions-methods-closures/57061 "2021-03-13T07:43:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)
#### Post date: [March 13, 2021, 7:43am UTC](https://discourse.julialang.org/t/serializing-functions-methods-closures/57061/1 "2021-03-13T07:43:53Z")

</div>

Hi all,

over the last months I’ve spent quite some time to bring JLD2 back up to speed. One of the remaining pain points is that it is not possible to properly store and recover (anonymous) functions  
and closures. This has been requested way too many times.

I’m aware that this is a difficult topic and that there probably will  
be edge cases that can’t work for one reason or another. (And likely for good reasons).

Still, I’m mostly concerned with the simpler things e.g. storing simple closures and anonymous functions that commonly appear as fields in larger structures. The `struct` part of closures already gets serialized properly and only the attached method is missing.

I’ve experimented with this for myself and adapted some code from  
`BSON` ([BSON.jl/src/anonymous.jl at master · JuliaIO/BSON.jl · GitHub](https://github.com/JuliaIO/BSON.jl/blob/master/src/anonymous.jl))  
and got very basic things working but, honestly, I don’t understand what I’m doing.

So, here are my questions:  
Is there more information beyond the julialang dev-docs that I can read?  
(e.g. what do the fields mean? What is the purpose of the structure?  
When are which fields of `Method`, `TypeName`, etc. initialized ?)  
Would anyone be willing to help me work on this ?

Best,  
Jonas

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [November 18, 2021, 12:45pm UTC](https://discourse.julialang.org/t/serializing-functions-methods-closures/57061/2 "2021-11-18T12:45:40Z")

</div>

so sad that there’s been no reply in eight months to help with serializing functions. would be very convenient to be able to save them to JLD2 files. thanks so much for working on this important problem @JonasIsensee

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [November 20, 2021, 3:30pm UTC](https://discourse.julialang.org/t/serializing-functions-methods-closures/57061/3 "2021-11-20T15:30:31Z")

</div>

Kind of a vague question. I’m still not clear what it means. There’s no example of what doesn’t work and it’s not clear what the request for more detail is about.

---

<div class="post-metadata">

### Author: ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)
#### Post date: [December 1, 2021, 8:14am UTC](https://discourse.julialang.org/t/serializing-functions-methods-closures/57061/4 "2021-12-01T08:14:35Z")

</div>

It was _vague_ because I knew too little to ask precise questions.

I worked on this problem once more and got some things working on julia v1.6. (Deserializing anonymous functions and closures)  
Now v1.6 is LTS and v1.7 has significant changes to the internals so I will most likely not pursue this any further.
