From JSON to JSEN Through Virtual Languages of the Creative Commons Attribution License (
Total Page:16
File Type:pdf, Size:1020Kb
© 2021 by the authors; licensee RonPub, Lübeck, Germany. This article is an open access article distributed under the terms and conditions A.of Ceravola, the Creative F. Joublin:Commons From Attribution JSON to license JSEN through(http://c reativecommons.org/licenses/by/4Virtual Languages .0/). Open Access Open Journal of Web Technology (OJWT) Volume 8, Issue 1, 2021 www.ronpub.com/ojwt ISSN 2199-188X From JSON to JSEN through Virtual Languages Antonello Ceravola, Frank Joublin Honda Research Institute Europe GmbH, Carl Legien Str. 30, Offenbach/Main, Germany, {Antonello.Ceravola, Frank.Joublin}@honda-ri.de ABSTRACT In this paper we describe a data format suitable for storing and manipulating executable language statements that can be used for exchanging/storing programs, executing them concurrently and extending homoiconicity of the hosting language. We call it JSEN, JavaScript Executable Notation, which represents the counterpart of JSON, JavaScript Object Notation. JSON and JSEN complement each other. The former is a data format for storing and representing objects and data, while the latter has been created for exchanging/storing/executing and manipulating statements of programs. The two formats, JSON and JSEN, share some common properties, reviewed in this paper with a more extensive analysis on what the JSEN data format can provide. JSEN extends homoiconicity of the hosting language (in our case JavaScript), giving the possibility to manipulate programs in a finer grain manner than what is currently possible. This property makes definition of virtual languages (or DSL) simple and straightforward. Moreover, JSEN provides a base for implementing a type of concurrent multitasking for a single-threaded language like JavaScript. TYPE OF PAPER AND KEYWORDS Regular Research Paper: JSEN, JSON, executable data structures, homoiconic languages, metaprogramming, virtual languages, concurrency, threading 1 INTRODUCTION astronomy, and several others. However, along its wide usage, XML has been criticized for its verbosity and There is a large variety of data formats available for complexity [33][35], consequently giving space for storing or transferring information between different other data formats to emerge [34]. One of the most software systems. Some of them are focused on used alternatives is JSON [15][16]. Considered lighter, specific domains while others are general purpose and simpler, and more readable than XML [27][37]; JSON can be easily used cross-domain. In this second group, belongs to the family of general-purpose data formats, XML is one of the most well-known data formats, and continues gaining space in new domains, designed in 1996 by the XML Working Group [7] [36] particularly among Internet applications. with the target of being a general-purpose data format, We use JSON data structures for storing and easy to read and usable on Internet applications. XML transmitting data across different subsystems in one of received a lot of attention from different communities our projects, a web-based, client-server avatar system. [33] leading to its usage in domains such as It is implemented with HTML, CSS and JavaScript, government, chemistry, telecommunication, used in both client and server side [32]. For some 1 Open Journal of Web Technology (OJWT), Volume 8, Issue 1, 2021 specific functionalities we came across the requirement manage asynchronous code as well as the need to of storing and manipulating code programmatically, in easily implement concurrent processing particularly ways not possible with JavaScript. We had to important in artificial intelligence systems. On the way programmatically control function’s execution, in some to the proposed solution, we discovered that object cases we had to execute functions in a concurrent way, oriented and functional programming provided by as well as injecting or removing code statements on JavaScript was not sufficient for the problem we were them. This type of code manipulation is supported by tackling and therefore we needed language extensions homoiconic languages: “In a homoiconic language, the which were not easily possible in JavaScript. For primary representation of programs is also a data example, our applications had the needs to model event structure in a primitive type of the language itself” based concurrent programs which, through JSEN [4][25]. became easily implementable. JavaScript provides a degree of homoiconicity [6] In the next paragraph we are going to describe the allowing introspection of classes, prototypes, and structure of this paper, touching the different concepts members. It allows dynamic changes like adding/ that will be elaborated in the different sections. removing or redefining members in classes/objects. JavaScript gives access to functions, by allowing 1.2 OVERVIEW access to their names, parameters, or their full source code (as a single string by applying the method In this paper we start the introduction of JSEN, in the “.toString()” to a function identifier). However, paragraph 2, by first looking at JSON. The two data JavaScript homoiconicity do not go beyond this; for formats are similar and complementary. This is an instance, it is not possible to have access to function’s important relation that facilitate the introduction of this individual statements or parts of them. A greater level work. In the paragraph 2.2, by describing JSEN, we of introspection/manipulation, instead, can be found in introduce its core principles on which it is based: homoiconic languages like Lisp [31], SmallTalk [11] or closure and heterogenous multi-dimensional arrays. At Tcl [28] and in the JavaScript macro language of that stage we explain the syntax, we describe how Majaho [14], as well as EsLisp [19]. In particular, the JSEN extends JavaScript homoiconicity, we introduce latter implements a Lisp based e-expression syntax for the concept of JSEN virtual machine and virtual JavaScript, where programs are natively stored in data languages. In the paragraph 2.3 we show how to go structures fully accessible in a programmatic way by from the definition of a JSEN data structure to its programs themselves. execution. Looking at JSEN as a storage format, in the In this paper, we describe a data structure that paragraph 2.4 we show how, similarly as JSON, JSEN allows a finer degree of access to function statements. can be used to transfer programs across systems. We called this format JSEN, JavaScript Executable We then describe, in the paragraph 3, the Notation (name inspired by the symmetric relations architecture of JSEN, to understand how JSEN can be between JSEN and JSON). Where JSON is a data used in applications. The paragraph 3.1, goes deeper format for storing and manipulating objects (data), into virtual languages, introducing how JSEN data JSEN is a format for storing and manipulating structures can be executed. In the paragraph 3.2 we executable code. Furthermore, with JSEN we can then investigate more details on the memory easily handle asynchronous functions without falling representation of JSEN by stepping into the stages of into the callback-hell pattern. In this paper, we describe JSEN definition, compilation, and execution. Existing the JSEN format, giving a glimpse on some of the concurrent/asynchronous methods available in interesting features we could derive from that. JSEN is JavaScript are then compared with JSEN in the available as Open-Source Software in GitHub at paragraph 3.3. The paragraph 3.4 describes in more https://github.com/HRI-EU/JSEN. All necessary details how a JSEN virtual machine works and how it libraries are present, with examples and all source can execute JSEN data structures in a concurrent way. snippet mentioned in this paper. We will now draw the We complete our analysis in the paragraph 4 by reasons that led us to introduce JSEN before we give an showing the main properties of JSEN like extended overview of the structure of the paper. homoiconicity for the hosting language, introduction of code serialization, execution performance of JSEN vs 1.1 MOTIVATION native code, virtual language support/extension and execution of concurrent code. We close the paper with Our experience with JavaScript has put in light several the paragraph 5 by shortly describing what has been limitations that JSEN is trying to overcome. The intentionally left out from this paper, which will then starting point for us has been the needs to be addressed in follow up papers, and we give a programmatically control function’s execution, to 2 A. Ceravola, F. Joublin: From JSON to JSEN through Virtual Languages summary and conclusions in the paragraph 6. Let us exchange/storing format. Elements of JSEN can be start now with the origin of the name. anonymous functions, pure JSEN statements, strings, arrays and objects. In Listing 2 we show an example of 2 FROM JSON TO JSEN a JSEN data structure for a program that implements the computation of prime numbers. For a more gradual introduction we show here how The choice of using arrays as supporting structure JSEN can be easily understood by looking at its for JSEN, comes from the needs of representing relations with JSON. sequences of statements of a program: arrays elements are ordered and can represent a sequence. Programs are 2.1 JSON also constituted of blocks and sub-blocks; similarly, arrays in JavaScript can be nested. In this way, it is JSON is a human readable data format based on the possible, in JSEN, to express any algorithm with JavaScript language, shaped around the syntax of arbitrary nesting and complexity. JavaScript object literals [18]. It has been defined with Let us look at JSEN from a closer perspective. The the purpose of encapsulating data that could be used or example (1) in Listing 3 shows an empty JSEN data manipulated in a program as well as used as data structure (empty array): empty program. The example exchange/storage format. The elements of a JSON data (2) in Listing 3 shows how to specify a comment.