📜 ⬆️ ⬇️

Elvish programming language

As you know, if you are a serious programmer, you do not need syntactic sugar, this is self-indulgence. A few years ago, Python was considered a rattle because of this. What you braces interfere? Childishness came up with some kind: replace braces with tab indents. Said a solid uncle. Malichiki agrees according, looking guiltily at the ceiling. A year later, everyone worked in groups where Python is the main language.

What is the correct development of languages? But what. A programming pattern is taken, which is used in the current language, and an attempt is made to introduce this pattern at the level of the language itself in an already new language. That is, there was a function without a name, you called it lambda, maybe even the name was, but you did not need it, just the compiler required, well, they called it “f1”, and in the new language it immediately - lambda! Or there was an array, you somehow limited its length and composition, and as a result called it a tuple, and now, voila, you have it at once - a tuple and more convenient to use. You used deferred calculations, difficultly discerning in C ++, and now - bams! and you have the same thing right at the language level, called lazy eval, only with the monads more careful, Luke. What are monads, Master Yoda? Oh, everything!

It is understood that if you use such a new language, then you must already KNOW these patterns and be able to apply them. The reputation and market advantage is increasing already because the name of the language containing the new semantics associated with the best achievements of the community is written in the SE. On the other hand, who fumbles, for example, in closures, the one who uses them in the modern language with lambdas or the one who used them for many years on Xi? The question is rhetorical.

So syntactic sugar or semantic meat is an open question.
')
Another trend in new languages ​​is changes under the hood. Hooray! In our language, now a new garbage collector, which can be paused, which means soft multitasking is achievable! And now we have an integer code that is optimized an order of magnitude better, only we need to put one "zyuzuk" at the beginning of the function and not to divide it fractionally!

It's all wonderful, as they say, "all sorts of mothers are important." But I remember the basics of linguistics, if you have syntactic sugar, semantic meat and ground meat pods, then where are the other parts of any language asked: grammar, vocabulary? Accordingly, the idea of ​​"lexical cream" or "grammatical jam."

Today I want to introduce you to an experimental programming language, Elfu. The name is rather sudden, just one friend of mine, a mad scientist from the Novosibirsk Academgorodok who invented the system of automatic proof of theorems, saw an example of code exclaimed: “what is it, elvish !?”.

It began with the fact that I somehow in the morning, for a long time tried to understand the code in which there was a lot of this and function. According to my estimates, on the floor of the source code screen, the function keyword was repeated in each line, and this more than twice per line.

Just for example, a picture of abstract art:

this.a = this.compare ((this.b + this.c) && this.d, this.x + this.y / this.z,

(function () {var closure = 'val'; return function () {alert (closure);};}) ())

And so on the floor of the screen! I really wanted to, just to understand what was happening to erase all references to this, like this:

a = compare ((b + c) && d, x + y / z

And suddenly, all that was on the screen became clear. I managed to take a look at the whole battlefield and figure out what was happening.

Then I decided to make an experimental language, where to replace this with function, with ➮.

a = compare ((b + c) && d, x + y / z,
(() {Var closure = 'val'; return () {alert (closure);};}) ())

I already had the experience of transpilers with the dotcall project, and in general I liked the transpilation system in JavaScript in coffeeScript. The matter immediately went. Having made a small traspiler in JavaScript, I began to actively use my brainchild to see how convenient it is in practice. Entering unusual characters immediately bothered me, because the keyboard is only 32 characters. But using the taboo replacement solved this problem, it turned out to be very convenient and easy to recruit in practice.

Because every day I have to type constructions like this many times:

for (var i = 0; i <data.length; i ++) {

and had long dreamed of having its shortened analog, I even got accustomed in C ++ macro each (i, array), I decided to immediately do this:

i ⬌ data {

Well, it went, how many wonderful characters in Unicode, I thought, and since childhood I was surprised why of all the possible characters in the universe, only 32 are used in programming, and they are not used in any language at once.

How can you persevere, the entire planet, develop a syntactic space, semantic, but leave completely ignored the lexical, symbolic, grammatical? However, this is understandable, for example, phonetics, the smallest linguistic space, but we cannot change it at all, how many letters there are and so many. Even this unfortunate TH of English in Russian will never take root. But maybe with symbols easier?

Since I do not use the debugger, but I use the console output and debug codification, that is, I actually type console.log () dozens and hundreds of times during my work session, I immediately wanted to simplify this set, and instead:

console.log ('hello world', '!')

to recruit

ロ 'hello world', '!'

Actually the previous line is hello.yy, that is, “hello world in elfu programming language”!

Then, in functional programming, there are often simplified functions like this:

this.data = this.data.map (function (item) {if (item> 20) return item})

after replacing the function with ➮, it was decided to try to go on, walk so to walk:

data = data ⧉ (➮ item {⌥ (item> 20) $ item})

as you can see: ⌥ this is if, ⧉ this is map, $ is return.

Now I remembered that I constantly had to think up how to call this item argument every time, and he often doesn’t need a name, such as, for example, in this case, a would be fine. Then I decided that if the function declared through ➮ has no parameters, then by default three parameters are declared a, b, c. And if you want the function to actually have no parameters, then you must specify explicitly ().

data = data ⧉ (➮ {⌥ (a> 20) $ a})

As one author wrote in one article on Habré, sorry I forgot to copy the link then, “it’s convenient when you don’t need to parse the extra keywords and identifiers with your eyes”. Hello to you, oh forgotten name.

I emphasize that my language is experimental, it replaces nothing, cancels nothing, and claims only the title of experiment in a given direction.

Here are some more interesting experimental features for Elf:

A ⬊ 1 // A.push (1)

A ⬋ 22 // A.unshift (22)

n⁰ = nˣ + mⁱ // n [0] = n [x] + m [i]

⌥ (⬤ a ≟ '∅')
// ⌥ (typeof a == 'undefined')

⌥ (name ≠ ⦿ && id ≠ ⦾) ⏀ name
// if (name! = true && id! = false) delete this.name

ロ ⍽ (⚂ * 100)
// console.log (Math.floor (Math.random () * 100))

That is, it is a game cube that is easily associated with a random number sensor. ∅ crossed out circle, i.e. uncertainty. But is cutting in half, that is, the destruction of the object. Finally, it is possible again, like in a school on mathematics, to produce m "um and everything". True, this is a superscript, there is no subscript in Unicode, or rather it is, but very incomplete, in Elf it is not used yet.

Many characters are so short and understandable that it became obvious that the brackets to the arguments after them look cumbersome. The idea came to make brackets optional, in some cases. For example, str ≀ 'a' is similar to str.indexOf ('a'). F'fs' is similar to require ('fs').

For more than six months, every day I use Elf. It works in node.js (and in the browser with some tricks similar to those used in other transpilers, like coffeeScript). I took the .yy file extension. You can simply do:

npm i -g elfu
require ('elfu')
require ('library.yy')

All characters used in the Elf are simply Unicode characters. Nothing has been invented, in most of them they are from the Unicode page of the Math and other symbols specification, but there are also ranges from different languages. To avoid problems, I made the font elfu.ttf in which I connected all the currently used characters. But on modern Linux, Windows, MacOS, iOS, Android, everything out of the box is displayed as it should, although some characters come from different fonts and may not look very nice and be slightly different in size.

The .yy file extension is a reference to the Elvish alphabet, let us imagine that this is a kind of elvish sign, rune. In fact, in the Elvish language, one must say "Khosti Lammen", which means "The Language of Numbers". However, you probably need the .elfu extension to also require (). By the way, the npm elfu package installs three command line utilities: yy, yyj, jyy. yy can be used instead of node: “yy hello.yy”, yyj compiles the elfu file to Javascript with output to STDOUT, jyy compiles back from Javascript to Elfu.

On average, the code for an elf is smaller by about 25%, but the point is not in bytes, but in a completely different work of the eye, the code becomes more visual. I dare to suggest that the use of something like an elf is necessary on the way to what millions of modern programmers dream about, namely programming from a tablet without a keyboard.

The features described in this article are only a small part of the already implemented.
You can read more in the links provided, though in English, but there are still mostly code samples.

exebook.imtqy.com/elfu/article.html
github.com/exebook/elfu
www.npmjs.com/package/elfu

What I would like from a respectable public is participation, at least for fun. If you are interested in the topic, throw your suggestions here or on the githab, what else can you add or change. A lot more Unicode characters and all sorts of features! Even if the Elf remains just an experiment of a mad philosopher, many of the characters may be useful in other languages ​​and developments. By the way, for example, in Elf, the sequences for entering characters according to tab-completion are standardized. For example, io | TAB turns into ≀ and means .indexOf (). There are ready-made configs for Sublime Text and Geany.

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


All Articles