The Definite Language Reference & Guide

  1. The Basics
  2. Optionals and Nothingness
  3. The s package
  4. Control Flow
  5. Classes & Value Types
  6. Extensions
  7. Protocols
  8. Enums
  9. Types and Namespaces
  10. Generics
  11. Callables
  12. Threads
  13. Metatypes
  14. Packages
  15. Memory Management
  16. Emojicode Engine & Compilation Specification
  17. Appendix I: The Emojicode Compiler

The Basics

Emojicode is a language that aims to provide the most modern and powerful features to make it easy, fast and fun to write programs. These powerful features include classes, optionals, which can handle the absence of a value, generics, closures and much more.

Emojicode is a strongly typed language, which means that the compiler will verify that all of your operations are correct. This for instance prevents you from treating a number as a list of texts.

Although Emojicode only uses Emojis to express the programโ€™s structure, it is similar to programming languages you might know, like C.

Emojicode was designed to allow the development of platform independent applications by running them inside a virtual machine. Your code is first compiled to bytecode by a compiler and can then be executed. The reference implemention of such a virtual machine is called Emojicode Real-Time and can, as the name suggests, execute your code rather fast.

Hint

If you need guidance on how to use the compiler and the Real-Time Engine see โ€œCompile and Run Your First Programโ€, which is a short tutorial on writing applications in Emojicode.

Comments

You can include non-executable text in your code by marking it as a comment. Comments begin with ๐Ÿ‘ด and end at the line break.

Example:

๐Ÿ‘ด This comment ends at the end of the line. Exactly here

Multiline comments starts with ๐Ÿ‘ต and ends with ๐Ÿ‘ต and can contain line breaks.

Example:

๐Ÿ‘ต This is a multiline comment. You can even make
line breaks. ๐Ÿ‘ต

The ๐Ÿ block

Emojicode needs to know what your program should do when it starts, therefore it requires you to provide a ๐Ÿ block. Hereโ€™s an example of a ๐Ÿ block.

๐Ÿ ๐Ÿ‡
  ๐Ÿ‘ด Get things up and running here...
๐Ÿ‰

The ๐Ÿ block can also return an integer which is then used as the exit code:

๐Ÿ โžก๏ธ ๐Ÿš‚ ๐Ÿ‡
  ๐Ÿ‘ด Get things up and running here...

  ๐ŸŽ 0 ๐Ÿ‘ด Return a code here.
๐Ÿ‰

It occours at the document level of a document.

When to use Emojis?

Thereโ€™s sometimes confusion when emojis are used. Basically itโ€™s very simple:

All type, method, class method and initializer names are Emojis. On the other hand variables cannot include emojis but must be any combination of characters that cannot be confused with numbers.

Variables

Variables pair a name, the variable name, with a value. The variable name can consist of any sequence of characters but may not contain spaces or emojis and may not begin with a number.

There are two types of variables: normal variables and frozen variables. Frozen variables differ from normal ones in that they cannot be changed after they were initially set.

๐Ÿฆ Declaring a Frozen Variable

The easiest way to declare and set a frozen variable at once is to use ๐Ÿฆ.

๐Ÿฆ daysInDecember 31
๐Ÿฆ approximationOf๐œ‹ 3.14159265359

The above code sets the variable daysInDecember to 31 and approximationOf๐œ‹ to 3.14159265359. These variables were declared as frozen variables as they never change.

The compiler infers the type of the variables from the values given.

๐Ÿฎ Setting and Declaring a Variable

To declare or change are normal, changeable variable you should use ๐Ÿฎ. If the variable you want to set is already declared its value will be changed, given that it is not frozen; in that particular case an error message would be emitted. Otherwise the variable is declared in the current scope.

๐Ÿฎ moneyLeft 20
๐Ÿฎ numberOfTimesโ€œSmokeOnTheWaterโ€WasPlayed 20348292837483929

These variables were justifiably declared as changeable variables because they obviously change often. You should however always prefer frozen variables if you donโ€™t intend to modify the variable.

๐Ÿฐ Declaring Variables

You can declare a variable yourself regardless if a variable with the same name was declared in the parent scope but you may not declare a variable more than one time.

๐Ÿฐ variableName variableType

variableName must be a valid variable name. variableValue may be an expression of any type.

After you declared the variable in the local scope you can use ๐Ÿฎ to set it to a value. The compiler will throw an error if you try to access an uninitialized variable. Optionals are automatically initialized to Nothingness.

Caution

Beware of that ๐Ÿฐ can shadow variables from parent scopes and can for instance make instance variables inaccessible.

Scoping

Variables are only accessible from the scope in which they were declared. Every code block (everything between a ๐Ÿ‡ and ๐Ÿ‰) defines an own scope which disappears once the block was executed:

๐Ÿ ๐Ÿ‡
  ๐Ÿฆ work ๐Ÿ”คWork It Harder Make It Better๐Ÿ”ค
  ๐ŸŠ ๐Ÿ‘ ๐Ÿ‡
    ๐Ÿ˜€ work  ๐Ÿ‘ด work is accessible here
    ๐Ÿฆ doIt ๐Ÿ”คDo It Faster, Makes Us stronger๐Ÿ”ค
  ๐Ÿ‰
  ๐Ÿ˜€ work  ๐Ÿ‘ด work still works, of course
  ๐Ÿ˜€ doIt  ๐Ÿ‘ด doIt is no longer accessible here
๐Ÿ‰

You cannot access scopes beyond the method, class method or intializer from your code. Nevertheless, you can access the object scope in instance methods and intializers. Closures are also considered an exception from this rule. Youโ€™ll learn more about these two kinds for special scoping in Classes & Value Types and Callables.

๐Ÿซ & ๐Ÿณ Incrementing and Decrementing Variables

Variables containing numbers can be incremented by using ๐Ÿซ and decremented by using ๐Ÿณ.

๐Ÿซ numberOfCats
๐Ÿณ watermelons

The above example will increment numberOfCats and decrement watermelons.

Numeric Literals

Integer literals can be written in

You can use _ within integer literals to improve readability:

344_000_000_000

The . can be used as decimal separator to create a ๐Ÿš€.

Number Types

There are only two numeric types in Emojicode:

Booleans

Emojicode has a type to represent Boolean values: ๐Ÿ‘Œ. A boolean value can either be true or false. A true value is created using ๐Ÿ‘ and a false value is created using ๐Ÿ‘Ž.

In the example below two variables are set to a boolean value.

๐Ÿฆ emojicodeIsTheFunniestLanguage ๐Ÿ‘
๐Ÿฆ phpIsAsCool ๐Ÿ‘Ž

Symbol literals

A Symbol is a single Unicode character represented by the symbol type ๐Ÿ”ฃ. The symbol type can represent any character defined in Unicode.

You can include the symbol in the source code file by prepending ๐Ÿ”Ÿ before the desired symbol. This is called a Symbol literal.

Example:

๐Ÿฆ percent ๐Ÿ”Ÿ%

Context Based Parsing

Emojicode heavily uses context based parsing. This means that something can have a completely different meaning based on the context.

All statments introduced above except for ๐Ÿ are only valid inside a method or initializer body. If you however used ๐Ÿฆ when a type name was expected, ๐Ÿฆ would be interpreted as a type called ๐Ÿฆ.

The statment introduced below is, on the contrary, only valid at document level โ€“ you canโ€™t use it inside a method or class.

Including Other Source Code Files

An Emojicode program is always compiled from a single file. Nevertheless, you can include other source code files. Basically, this just inserts the code from the file at the point where you included it.

Syntax:

๐Ÿ“œ string

string must be a string whose value is a path to another Emojicode source file. The path is relative to the directory which included the document with the ๐Ÿ“œ statement.

Hint

Do not use this method to share code accross projects. If you have written really fancy code, create a package, which you can easily make available to other people.

Next โ†’