Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift - Rios, Luiz Romário Santana; Ierusalimschy, Roberto (Anais do Simpósio Brasileiro de Linguagens de Programação (SBLP), 2025)
When using lambdas in managed languages, the programmer does not need to concern themselves with the disposal of the closure; in contrast, unmanaged languages that implement lambdas need mechanisms to make the closures be disposed safely at the right time. Through examples, we explore and compare the following languages: C++, Rust, and Swift. For each language, we implement examples of the usage of lambdas in increasing complexity, analyzing how they work while showcasing the implementations. After presenting the implementations, we contrast the languages regarding memory safety and typing. Finally, from those experiments, we assess some properties of lambdas in the languages and summarize them in a table, namely: safety features, safe by default, safety guarantees, verbosity, type flexibility, and memory overhead.