Bacatá: a generic notebook generator for DSLs Mauricio Verano Merino TUe The Netherlands m.verano.merino@tue.nl Jurgen J. Vinju CWI / TUe The Netherlands Jurgen.Vinju@cwi.nl Tijs van der Storm CWI / University of Groningen The Netherlands storm@cwi.nl Abstract Interactive notebooks, such as provided by the Jupyter plat- form [2], are gaining traction in scientific computing, data science, and machine learning. Developing a Jupyter kernel machinery for a new language, however, requires consider- able effort. In this extended abstract, we present Bacatá, a language-parametric bridge between Jupyter and the Rascal language workbench [3]. Reusing existing language compo- nents, such as a parsers, interpreters, Read-Eval-Print Loop (REPLs) and autocomplete, Bacatá generates a Jupyter kernel machinery so that the DSL can be used in notebook form. We sketch the architecture of Bacatá and demonstrate it in action using a DSL for image processing, called Amalga. 1 Introduction Notebooks are gaining traction in scientific computing, data science, and machine learning, due to the capabilities they provide in terms of development, documentation, execution and results visualization. Notebooks support live code, re- sults computation, and narrative text, all in the same rich media document. Consequently, they are often used for com- putational storytelling: explaining languages, libraries, algo- rithms, etc. in an interactive way. Jupyter [2] is the most popular platform for constructing notebook applications. Jupyter notebooks platform can be divided into two main parts: the web server and the note- book document. The web server contains different kernels (interpreters), which runs and introspect user’s code. Those kernels enable the communication between the platform and the language. Constructing a Jupyter kernel for a new language is a time-consuming and error-prone task. It requires under- standing and handling messages through the implementa- tion of the Jupyter’s wire protocol and connecting it to a language-specific read-eval-print-loop (REPL) which com- putes results, displays errors, and produces rich media rep- resentations. In this extended abstract, we present Bacatá, a language-parametric framework for creating Jupyter note- books with minimal effort. Bacatá acts as a bridge between Jupyter and languages developed within the Rascal language workbench [3]. As a result, language components that are DSLDI’2017, October 2017, Vancouver, Canada 2017. ACM ISBN 978-x-xxxx-xxxx-x/YY/MM. . . $15.00 hps://doi.org/10.1145/nnnnnnn.nnnnnnn DSL Notebook Kernel Generator Bacatá.jar kernel.json Figure 1. High-level overview of Bacatá already developed within Rascal can be reused to drive the generated Jupyter kernel. We illustrate Bacatá in the context of a DSL for image processing algorithms (i.e. Amalga). We expect Bacatá to be a first step towards extending the editor services provided by language workbenches [1] to include interactive notebooks. 2 Bacatá Bacatá provides a bridge between the Jupyter notebook plat- form and Rascal [3]. Rascal is a functional meta-programming language for source code analysis and transformation, and language workbench for DSL development. It has been suc- cessfully used for developing DSLs in the domains of finance, digital forensics, and game economies. Bacatá extends Ras- cal’s current set of IDE services with support for interactive notebooks. Figure 1 summarizes Bacatá’s architecture. A DSL imple- mentation is the input to a Jupyter kernel generator, which implements how the generic Bacatá executable should pro- cess requests and responses from and to the Jupyter notebook server. To create a notebook interface using Bacatá, the language developer needs to perform the following high-level steps: 1. Define a Rascal module M containing a function which returns a REPL value (see below). 2. Call the function genKernel, with the name and location of module M, and other configuration parameters. This generates a JSON file (i.e. kernel.json) containing the proper invocation to Bacatá when it is loaded into the Jupyter platform. 3. Call the function startNotebookServer to start the Jupyter Web server to load the kernel given as parameter (e.g. M); Bacatá will start Rascal with M, and from then on relay communication from Jupyter to the proper handlers defined by the obtained REPL value.