Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift
Resumo
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.
Palavras-chave:
Programming paradigms and styles, Programming language design and implementation, Run-time environments
Referências
Bill, G. Odin programming language. [link]. Accessed in June 15th, 2025.
Foundation, Z. S. Zig programming language. [link]. Accessed in June 15th, 2025.
Ierusalimschy, R., and Rios, L. R. S. Approaching closures in unmanaged languages: a comparison between c++, rust, and swift (sblp 2025 short article’s artifacts). DOI: 10.17605/OSF.IO/CWKNU, 2025.
Inc., A. Automatic reference counting — the swift programming language (swift 5.4). [link]. Accessed in May 22nd, 2021.
Inc., A. Closures — the swift programming language (swift 5.4). [link]. Accessed in May 21st, 2021.
Inc., A. Expressions — the swift programming language (swift 5.4).
Inc., A. The objective-c programming language. [link], 2013. Accessed in June 15th, 2025.
Rios, L. R. S., and Ierusalimschy, R. A survey of function values in imperative programming languages. Master’s thesis, Pontifícia Universidade Católica do Rio de Janeiro, 2019.
Team, T. G. The gtk project - a free and open-source cross-platform widget toolkit. [link]. Accessed in June 15th, 2025.
Team, T. R. The rust programming language. [link], 2018. Accessed in April 18th, 2019.
Team, T. R. The rustonomicon. [link], 2021. Accessed in May 21st, 2021.
Foundation, Z. S. Zig programming language. [link]. Accessed in June 15th, 2025.
Ierusalimschy, R., and Rios, L. R. S. Approaching closures in unmanaged languages: a comparison between c++, rust, and swift (sblp 2025 short article’s artifacts). DOI: 10.17605/OSF.IO/CWKNU, 2025.
Inc., A. Automatic reference counting — the swift programming language (swift 5.4). [link]. Accessed in May 22nd, 2021.
Inc., A. Closures — the swift programming language (swift 5.4). [link]. Accessed in May 21st, 2021.
Inc., A. Expressions — the swift programming language (swift 5.4).
Inc., A. The objective-c programming language. [link], 2013. Accessed in June 15th, 2025.
Rios, L. R. S., and Ierusalimschy, R. A survey of function values in imperative programming languages. Master’s thesis, Pontifícia Universidade Católica do Rio de Janeiro, 2019.
Team, T. G. The gtk project - a free and open-source cross-platform widget toolkit. [link]. Accessed in June 15th, 2025.
Team, T. R. The rust programming language. [link], 2018. Accessed in April 18th, 2019.
Team, T. R. The rustonomicon. [link], 2021. Accessed in May 21st, 2021.
Publicado
22/09/2025
Como Citar
RIOS, Luiz Romário Santana; IERUSALIMSCHY, Roberto.
Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift. In: SIMPÓSIO BRASILEIRO DE LINGUAGENS DE PROGRAMAÇÃO (SBLP), 29. , 2025, Recife/PE.
Anais [...].
Porto Alegre: Sociedade Brasileira de Computação,
2025
.
p. 97-99.
DOI: https://doi.org/10.5753/sblp.2025.13162.
