User:Alextretyak/11l
| Designed by | Alexander Tretyak | 
|---|---|
| First appeared | 2018 | 
| Typing discipline | Static, strong, inferred | 
| License | MIT License | 
| Filename extensions | .11l | 
| Website | https://11l-lang.org | 
| Influenced by | |
| Python, C++ | |
11l (elevenel) is an imperative, statically typed, compiled, general-purpose programming language with a design oriented towards combining readable and expressive code (as in Python) with the performance of C++.
In contrast to other programming languages, keywords in 11l are structured hierarchically. At the top of the hierarchy are 11 base or root keywords. This feature underlies the language's name, in which the ‘l’ may be read as standing for Latin ‘litterae’, Greek ‘logos’ (meaning ‘word’), or English ‘letters’ (because each root keyword in 11l can be abbreviated to a single letter).
Although the language is still at an early stage of development, the core language and the standard library contain sufficient functionality to solve most tasks on Rosetta Code[1]. (11l is currently in 25th place by number of tasks solved on Rosetta Code.)
Operators[edit source]
Most 11l operators are chosen on a rational basis[2]. For example, the ‘bitwise exclusive or’ operation uses the three characters ( (opening parenthesis), + (plus), and ) (closing parenthesis), since they resemble the ⊕ character used to denote exclusive or in Boolean algebra. Although ⊕ is more commonly used for one-digit values, it is also found on Wikipedia used for pointers (see XOR linked list) and for arrays of bytes (see HMAC).
For the exponentiation operation the character ^ (caret) was chosen, since it is often used when writing formulas and mathematical expressions not only in programming languages and computer systems, but also in ordinary text. [The use of ^ for the ‘bitwise exclusive or’ operation (as in C and most other programming languages) may be regarded as an unfortunate idea, since it confuses newcomers to programming [3].]
For the ‘integer division’ operation, the letter I and the character / (slash) were chosen. The I is short for Integer.
Array concatenation is expressed with the three characters [ (opening square bracket), + (plus) and ] (closing square bracket), since arrays in 11l (as in JavaScript, Python, Ruby, Swift and many other languages) are written using square brackets (for example, [1, 2, 3]). And since this operation is quite expensive, a separate operator is allocated to it.
Lexical analysis[edit source]
According[4] to the developer of the language, 11l implements the most advanced lexical analyzer among all the existing programming languages. This lexical analyzer, in particular, makes it possible to almost completely get rid of all visual noise such as mandatory semicolons at the end of statements, curly braces (or begin and end keywords) to indicate code blocks, parentheses around conditions or expressions (for statements such as if, while, etc.), as well as colon (:) and backslash (\) characters at the end of lines. Here is an example of code in C and the corresponding 11l code (this is a translation of this Python code, rather than being a synthetic example):
| C/C++/C# | 11l | 
|---|---|
while (true) {
    switch (instr[i]) {
    case '[':
        nesting_level++;
        break;
    case ']':
        if (--nesting_level == 0)
            goto break_;
        break;
    }
    i++;
    ...
}
break_:
 | 
loop
   switch instr[i]
      "["
         nesting_level++
      "]"
         if --nesting_level == 0
            loop.break
   i++ | 
It is proposed to use dashed lines (less distracting than characters or keywords) to indicate blocks of code at the integrated development environment level, rather than language resources:
Standard library[edit source]
The 11l standard library is based on the Python library, but many functions have been revised and certain shortcomings or deficiencies have been fixed. For example[5]:
- The 
random.randrange(a, b)function, which returns a random numbernin the rangea <= n < b, and therandom.randint(a, b)function, which returns a number in the rangea <= n <= b, have been combined into a single function which takes one argument of type "range" (in 11l the range fora <= n <= bis written asa..b, while the range fora <= n < bis written asa.<b). - The 
match()regular expression object method has been replaced byfullmatch()(in other words,fullmatch()in Python corresponds tomatch()in 11l). - The 
re.splitandre.subfunctions have been moved from theremodule into the overloaded string methodssplitandreplacerespectively. - The 
gettempdir()function from thetempfilemodule and some functions from theosmodule (listdir,walk,mkdir,makedirs,remove,rename, etc.) have been moved to a separatefsmodule; the functions from theos.pathhave been moved tofs:path. - 11l has two modules instead of the 
heapqmodule:minheap(equivalent toheapq) andmaxheap, which has no direct equivalent in Python. - The 
binandhexfunctions return a string without the0bor0xprefix, because the unprefixed string is more often what is wanted.[6][7][8][9][10][11][12][13][14] "\n".join(arr)in Python corresponds toarr.join("\n")in 11l (and in 11l the elements ofarrcan be not just strings, as in Python, but any objects for which conversion into a string is defined).map(lambda x: x * 2, filter(lambda x: x % 2 == 0, [1, 2, 3, 4]))in Python corresponds to[1, 2, 3, 4].filter(x -> x % 2 == 0).map(x -> x * 2)in 11l.
Design principles[edit source]
11l is designed so that files generated on different systems using the same source code will always be binary identical. For example, in Python, the default encoding when a text file is opened depends on the platform. 11l, by contrast, uses UTF-8 by default. The line ending character or characters when writing text files in Python are also platform-dependent, whereas 11l uses Unix-style line endings (i.e. the single character LF) when writing text files (the CR character is simply ignored in reading text files).
11l's minimalistic design makes it relatively easy to learn the entire language (including the standard library).
Implementation notes[edit source]
The reference implementation of 11l takes the form of a Python → 11l → C++ transpiler, and thus can be used not only to compile 11l code but also to compile Python code [which results in significantly faster execution (often by more than an order of magnitude)]. It should be noted that this transpiler generates human-readable 11l code (which can help those who already know Python in learning 11l) and human-readable C++ code (which makes it easier to debug a program).
References[edit source]
- ^ 11l - Rosetta Code
 - ^ 11l Operators
 - ^ what is ^ used for in ruby? (Stack Overflow)
 - ^ Article ‘Lexical Analysis in 11l’
 - ^ Standard Library. Differences from Python. Main differences
 - ^ Gray code - Rosetta Code
 - ^ Geohash - Rosetta Code
 - ^ Decimal floating point number to binary - Rosetta Code
 - ^ Python-projects/n5110_BMP_converter.py · GitHub
 - ^ URL encoding - Rosetta Code
 - ^ UTF-8 encode and decode - Rosetta Code
 - ^ Solve triangle solitare puzzle - Rosetta Code
 - ^ Variable-length quantity - Rosetta Code
 - ^ Numbers with same digit set in base 10 and base 16 - Rosetta Code