Emoji lisp

    It all started with what I read at Stanislav Lem in the novel “Peace on Earth” (1985), that in the future communication in the language will be replaced by communication with the help of pictograms. It seemed to me rather prophetic in connection with the growing interest in various emoticons and other types of larger pictures, and I thought: what if we program using emoji? Searching the network, I was convinced that such a thought had already entered people's heads and was embodied in the project https://github.com/wheresaddie/Emojinal
    but this project did not impress me, firstly, the language does not have completeness and in general the author’s approach as an attempt to replace some of the operators using emoji seemed not very interesting.

    I thought that Lisp would be much better off laying on emoji, because closing-opening brackets are like emoticons, plus the language itself is very simple, the compiler can be written pretty quickly and it doesn't take a lot of implementation to make everything work different designs.

    Since I wanted to give users the opportunity to easily try this new language, it was decided to make it embedded in the browser. As the compiler language, you could choose any language that compiles in JavaScript, but I just chose JavaScript and decided to write so that it could be compiled both in the environment of node.js and in the browser. The second point that I would like to achieve is the variability of the emoji set, from the first operations I began to doubt that the choice of the emoji representation is really unambiguous and decided to do everything so that another developer could just replace this character set and see what new ones turn out emoji programs. For this reason, all test cases are written as templates into which the current set is substituted.

    I chose PEG as the language for describing the grammar, the only problem with it was that it was not possible to make unicode characters by enumeration in the conditions (I had to iterate over the first and second characters separately, because for it it was several characters). Plus, there was a difficulty associated with recompiling the PEG parser, because I would have to change the definition of identifiers each time (biting the brackets) and rebuild the parser using PEG.js, which seemed slow enough on the browser side. A rather simple decision was made - before submitting the program for lexical analysis, replace the current characters of the brackets from the set with ordinary brackets, and then parse with ordinary brackets. It turned out such a PEG:
      = s:sexpr* {return {type:"Program", body:s}}
      = "("
      = ")"
      = [\uD83D][\uDC36-\uDE4F]
      / [\uD83D][\uDE80-\uDEC5]
      / [\uFE0F]
      / [\u2702-\u27B0]
      / [\u24C2]
      / [\uD83C][\uDC04-\uDFE2]
      / [\u20E3-\u3299]
      = [0-9]+
    _ "whitespace"
      = [\t\v\f \n\u00A0\uFEFF]*
      = a:atom { return a; }
      / list
      = leftBracket _ head:sexpr
        tail:(_ sexpr)* _ rightBracket _ {
          var result = [head];
          for (var i = 0; i < tail.length; i++) {
          return {type: 'List', contents:result};
      = d:number _ { return {type: 'Literal', value: parseInt(d.join(""), 10)}}
      / '"' d:(!'"' [a-z])* '"' _ { return {type: 'Literal', value: d }}
      / s:identifier _ { return {type: 'Identifier', name: s.join?s.join(""):s}}

    Further, it’s simpler: I chose a set of functions that were included in a simple standard library, this:

    and in order to demonstrate their work I wrote the calculation of Fibonacci numbers, the calculation of myself and a few simple programs,
    in addition, exported pictures and codes from the gemoji project for more visual demonstration.

    This is how a program that calculates itself looks like:

    here months are brackets, animals are identifiers, the rest of the constructions are above.

    This is what the program for Fibonacci numbers looks like:

    this is a recursive function whose name is a dog. Emoji characters can be written in a row, but numbers in a row must be separated by spaces if they refer to different numbers.

    In the first version, instead of months, sad-funny emoticons were used, but because of their similarity, the code was much more difficult to structure, for this reason it switched to months. True, it is not entirely clear to me why there are months in the standard set of emoji looking in different directions.

    In the process, I found out that emoji are not so well supported, for example, sublime allows you to copy only some of them, if you try to copy the text of a program calculating itself, it will be empty in the clipboard. Of desktop browsers, Safari is more or less normal emoji. The compiler supports emoji in the form of unicode characters, and there are even repl, but writing a terminal doesn’t support such characters too well, they attack each other, but I hope that the situation will improve in the future and we will be able to easily write calls to emo utilities right on the command line.

    All sources are available at https://github.com/parsifal-47/emojilisp, there you can expand the standard library or write a request for it, in addition, you can try your hand at programming on this simple set of functions at emojilisp.com . And as I wrote at the very beginning, I wanted to be able to redefine the set of emoji corresponding to the functions without much difficulty. This can be done by changing the files in the conf folder of the project on github or by clicking the "create your own set" button on the site, after which the set, like any program, can be shared. Here, for example, is a variant with a more interesting symbol for the list operation .

    In addition, a difficultly verified idea came up that such a language would probably be easier for children to understand, and perhaps some kind of programming would be for the future.

    Also popular now: