📜 ⬆️ ⬇️

Emoji lisp

(Friday)
It all started with what I read in Stanislav Lem’s novel Peace on Earth (1985), that in the future, communication in the language will be replaced by communication using 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 I program with emoji? Searching the net, I became 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, at first, the language is not complete, and in general the author’s approach as an attempt to replace part of the operators with the help of emoji did not seem very interesting.

I thought Lisp would be much better placed on emoji, because the closing-opening brackets are like emoticons, plus everything, the language itself is very simple, the compiler can be written quite quickly and you don’t need a lot of implementation 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 a compiler language, it was possible to choose any language that is compiled into JavaScript, but I simply chose JavaScript and decided to write it so that it could be compiled both in the node.js environment and in the browser. The second point that I would like to achieve is the variability of the emoji set, from the very first operations I began to doubt that the choice of emoji presentation was really unequivocal and decided to do everything so that another developer could just replace this character set and see what new emoji programs For this reason, all test cases are written as templates, in which the current set is substituted.

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

')
Further, easier: I chose a set of functions that are included in a simple standard library, this is:

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

This is a program that calculates itself:

here months are brackets, animals are identifiers, the rest are higher.

This is the program for Fibonacci numbers:

This is a recursive function whose name is doggy. Emodi characters can be written in a row, but the numbers going in a row need to be separated by spaces if they belong 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 moved for months. True, I do not quite understand why in the standard set of emoji there are months looking in different directions.

In the process I found out that emoji is not so well supported, for example, sublime allows you to copy only some of them, if you try to copy the text of the program that calculates itself, the clipboard will be empty. From desktop browsers, emoji is more or less normally supported by Safari. The compiler supports emoji in the form of unicode characters and there is even a repl but writing the terminal doesn’t support such characters too well, they step on each other, but I hope that the situation will improve in the future and we will be able to calmly write calls to the utilities directly 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 feature set 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 you can share a set, just like any program. Here, for example, a variant with a more interesting symbol for the list operation .

In addition, there was a difficult testable idea that such a language might be easier understood by children and perhaps some such would be the programming of the future.

Source: https://habr.com/ru/post/237297/


All Articles