A functional scripting interface to an object oriented C++ library (2312.13295v1)
Abstract: The object oriented programming paradigm is widely used in science and engineering. Many open and commercial libraries are written in C++ and increasingly provide bindings to Python, which is much easier to learn, but still partly encourages the use of object oriented programming. However, scientific ideas are much more directly and meaningfully expressed in the purely functional programming paradigm. Here, we take a best practice example, CERNs Python binding for its ROOT library, designed to handle the enormous amounts of data generated by the worlds largest particle accelerator, and translate a simple segment of its tutorial into Clojure, a functional language from the Lisp family. The code examples demonstrate how a purely functional language straightforwardly expresses scientific ideas. Subsequently, we develop a compiled Lisp-C++ interoperation layer to access the ROOT library exclusively via functional code. To preserve the expressivity of the Lisp code, the type hints necessary for C++ code generation are stored in a separate file. The interop system presented here is a generic framework that, when provided with a suitable file of type hints, facilitates access to methods of arbitrary C++ libraries and platforms like real-time microcontrollers.
- Root—an object oriented data analysis framework. Nuclear instruments and methods in physics research section A: accelerators, spectrometers, detectors and associated equipment, 389(1-2):81–86, 1997.
- Structure and interpretation of classical mechanics. The MIT Press, 2015.
- Functional differential geometry. The MIT Press, 2013.
- The role of programming in the formulation of ideas. AI Memo, Artificial Intelligence Laboratory, MIT, 18, 2002.
- Rich Hickey. The Clojure programming language. In Proceedings of the 2008 symposium on Dynamic languages, pages 1–1, 2008.
- Jeaye Wilkerson. The jank programming language. https://jank-lang.org. Accessed: 2023-12-09.
- CERN ROOT Manual. Passing Python callables to C++. https://root.cern/manual/python. Accessed: 2023-12-09.
- Clojure.org. State of Clojure 2023 results. https://clojure.org/news/2023/06/30/state-of-clojure-2023. Accessed: 2023-12-09.
- Efficient and accurate automatic Python bindings with cppyy & cling, 2023.
- Nurullah Akkaya. Ferret programmer’s manual. https://ferret-lang.org. Accessed: 2023-12-09.
- Markus Kloimwieder. LisRoot. https://github.com/kloimhardt/LisRoot. Accessed: 2023-12-09.
- Meta and community. React. https://react.dev/learn. Accessed: 2023-12-09.
- Cython: The best of both worlds. Computing in Science & Engineering, 13(2):31–39, 2010.
- Metosin. malli. https://github.com/metosin/malli. Accessed: 2023-12-09.
- The role of interpreters in high performance computing. Technical report, Fermi National Accelerator Lab.(FNAL), Batavia, IL (United States), 2008.
- D Liebgold. Functional mzScheme DSLs in game development. Commercial Users of Functional Programming, 2011. http://cufp.org/2011, Accessed: 2023-12-15.
- Potential of the Julia programming language for high energy physics computing. Computing and Software for Big Science, 7(1):10, 2023.
- Paul Graham. Revenge of the nerds. http://www.paulgraham.com/icad.html. Accessed: 2023-12-09.