Emojicode Documentation 0.8
Guides Language Reference Package Index

The s package

This chapter provides a very brief overview of the s package and its most important classes.

The s package can be compared to what’s called standard library in other programing languages. It provides some of the most important classes and value types to write meaningful programs.

Hint

This chapter only introduces the most important interfaces although there are many more.

You can browse the whole API of the s package here.

πŸ‘Œ πŸ”’ πŸ’―

The most basic types πŸ‘Œ (boolean), πŸ”’ (integer), πŸ’― (real number), were already introduced in The Basics. These types are, of course, defined in the s package.

πŸ”‘ Strings

Strings are textual data that is represented by the πŸ”‘ type.

String Literals

You can include strings in your code by surrounding the characters by a pair of πŸ”€:

πŸ”€This is a string.πŸ”€ ➑️ aString

Obviously, you cannot just include the πŸ”€ symbol in a string literal as it would be understood as the ending of the string. You can however escape the πŸ”€ using the ❌.

πŸ”€A string literal begins with a βŒπŸ”€ symbol.πŸ”€ ➑️ aboutStringLiterals

If you want to include the ❌ symbol in a string literal you will need to escape it as well:

πŸ”€The escape character is ❌❌ (red cross).πŸ”€ ➑️ theEscapeSymbol

The escape character can also be used to produce the following characters:

All other combinations of a ❌ and another character lead to a compiler error. The syntax is:

string-literal ⟢ πŸ”€ [string-literal-characters] πŸ”€
string-literal-characters ⟢ string-literal-character |  string-literal-character string-literal-characters
string-literal-character ⟢ string-escape-sequence | οΏ’πŸ”€ unicode
string-escape-sequence ⟢ ❌ string-escape-tail
string-escape-tail ⟢ n | t | r | e | ❌ | πŸ”€

Concatenating Strings

To add two or more strings together (concatenate) you should use the πŸͺ statement. Wrap all strings you want to concatenate between two πŸͺ. They will get concatenated in order of appearance into one string.

πŸ”€Hello πŸ”€ ➑️ string1
πŸ”€my dearπŸ”€ ➑️ string2

πŸ˜€ πŸͺ string1 string2 πŸ”€ World!πŸ”€ πŸͺ❗️

πŸͺs are the most efficient way of concatenating strings as the compiler can πŸͺoptimize the concatenation. Please note that πŸͺs are not methods but part of the language.

The syntax formally is:

concatenate-literal ⟢ πŸͺ concatenate-expressions πŸͺ
concatenate-expressions ⟢ concatenate-expression | concatenate-expression concatenate-expressions
concatenate-expression ⟢ ᅭconcatenate-literal expression

🍨 Lists

Lists are ordered mutable collections of values represented by the 🍨 type.

List Literals

You can create a list just by listing the values for the list between 🍨 and πŸ†. The example below creates a list with the values 14, 67, 2434.

🍨 14 67 2434 πŸ†

The compiler will try to infer the generic type argument for the list.

list-literal ⟢ 🍨 [expressions] πŸ†
expressions ⟢ expression | expression expressions

🍯 Dictionaries

Dictionaries can be used to assign values to keys. They are represented by the 🍯 type.

Dictionary Literals

The shortcut syntax to create a dictionary is:

dictionary-literal ⟢ 🍯 [kv-pairs] πŸ†
kv-pairs ⟢ kv-pair kv-pairs | kv-pair
kv-pair ⟢ key expression
key ⟢ expression

key must be a string. The compiler will try to infer the generic type argument for the dictionary.

Here’s an example for a dictionary that associates artists with their birthplaces:

🍯
  πŸ”€Aaron CoplandπŸ”€ πŸ”€BrooklynπŸ”€
  πŸ”€Michael JacksonπŸ”€ πŸ”€GaryπŸ”€
  πŸ”€FalcoπŸ”€ πŸ”€ViennaπŸ”€
πŸ†

⏩ Ranges

Emojicode supports a range type called ⏩. A range is an immutable sequence of numbers, or more strictly speaking of integers.

A range is always defined by three values: start, stop and step.

If step is positive, every number f(x) = start + x * step that matches the constraint start ≀ f(x) < stop is an element of the range. If step is negative the constraint stop < f(x) ≀ start applies instead.

Ranges can be very helpful in combination with πŸ”‚ if you need to repeat something for a specific number of times:

πŸ”‚ i πŸ†•β©β­ 0 10 2❗️ πŸ‡
  πŸ˜€ πŸ”‘ i 10❗️❗️  πŸ’­ Prints numbers 0 through 8 (including).
πŸ‰
πŸ”‚ i πŸ†•β©β© 0 10❗️ πŸ‡
  πŸ˜€ πŸ”‘ i 10❗️❗️  πŸ’­ Prints numbers 0 through 9 (including).
πŸ‰
πŸ”‚ i πŸ†•β©β© 10 0❗️ πŸ‡
  πŸ˜€ πŸ”‘ i 10❗️❗️  πŸ’­ Prints numbers 10 through 1 (including).
πŸ‰
πŸ”‚ i πŸ†•β©β­ 100 -10 -10❗️ πŸ‡
  πŸ˜€ πŸ”‘ i 10❗️❗️  πŸ’­ Prints numbers 100 through 0 (including).
πŸ‰
← Previous Next Up: β€œClasses & Value Types” β†’
Something not quite right? Improve this page