Comparison with C++
The Emojicode compiler is written in C++, and the ideas behind the language are close to C++ and Swift in places. For people who know C++, here is how commonly used features correspond. Searching for the C++ name on the left (such as std::map) or a common term such as “associative array” also brings you here.
Program structure
| C++ | Emojicode | Chapter |
|---|---|---|
int main() { … } |
🏁 🍇 … 🍉 |
Hello World |
std::cout << x << std::endl; |
😀 x❗️ |
Hello World |
std::cout << x; (no newline) |
👄 x❗️ |
Hello World |
// comment |
💭 comment |
Hello World |
/* … */ |
💭🔜 … 🔚💭 |
Hello World |
std::getline(std::cin, line); |
🆕🔡▶️👂🏼❗️ ➡️ line |
Standard Input |
#include / import |
📦 name 🏠 |
|
return x; |
↩️ x |
Classes |
Types and variables
| C++ | Emojicode | Chapter |
|---|---|---|
int64_t / long long |
🔢 |
Values and Variables |
double |
💯 |
Values and Variables |
bool, true, false |
👌, 👍, 👎 |
Values and Variables |
std::string |
🔡 |
Strings |
const auto x = 42; |
42 ➡️ x |
Values and Variables |
auto x = 0; |
0 ➡️ 🖍🆕 x |
Values and Variables |
x = 5; |
5 ➡️ 🖍x |
Values and Variables |
x += 5; |
x ⬅️➕ 5 |
Values and Variables |
std::string s; (declaration only) |
🖍🆕 s 🔡 |
Values and Variables |
static_cast<double>(n) |
💯 n❗️ |
Values and Variables |
Operators
| C++ | Emojicode | Chapter |
|---|---|---|
+ - * / |
➕ ➖ ✖️ ➗ |
Values and Variables |
% |
🚮 |
Values and Variables |
( … ) |
🤜 … 🤛 |
Values and Variables |
== |
🙌 |
Conditionals |
< > <= >= |
◀️ ▶️ ◀️🙌 ▶️🙌 |
Conditionals |
&& || |
🤝 👐 |
Conditionals |
!x |
❎ x❗️ |
Conditionals |
Strings
| C++ | Emojicode | Chapter |
|---|---|---|
std::to_string(n) |
🔡 n❗️ |
Strings |
std::stoll(s) |
🔢 s 10❗️ (the result is 🍬🔢) |
Strings |
"a" + s + "b" |
🔤a🧲s🧲b🔤 |
Strings |
"\n" "\t" |
❌n ❌t |
Strings |
s.substr(pos, len) |
🔪 s pos len❗️ |
Strings |
s.find(t) |
🔍 s t❗️ |
Strings |
toupper |
📫 s❗️ |
Strings |
s.size() |
📐 s❗️ (number of bytes) |
Strings |
Control flow
| C++ | Emojicode | Chapter |
|---|---|---|
if (c) { … } |
↪️ c 🍇 … 🍉 |
Conditionals |
else if (c) { … } |
🙅↪️ c 🍇 … 🍉 |
Conditionals |
else { … } |
🙅 🍇 … 🍉 |
Conditionals |
for (int i = 0; i < 10; i++) |
🔂 i 🆕⏩ 0 10❗️ 🍇 … 🍉 |
Loops |
for (auto x : v) |
🔂 x v 🍇 … 🍉 |
Loops |
while (c) |
🔁 c 🍇 … 🍉 |
Loops |
break / continue |
None | Loops |
Containers
| C++ | Emojicode | Chapter |
|---|---|---|
std::vector<int64_t> |
🍨🐚🔢🍆 (list) |
Lists and Dictionaries |
std::vector<int64_t> v{1, 2, 3}; |
🍿 1 2 3 🍆 ➡️ v |
Lists and Dictionaries |
v[i] |
🐽 v i❗️ |
Lists and Dictionaries |
v.size() |
📏 v❓ |
Lists and Dictionaries |
std::map<std::string, int64_t> / std::unordered_map |
🍯🐚🔢🍆 (dictionary; keys are 🔡) |
Lists and Dictionaries |
std::map<…> m{{"a", 1}}; |
🍿 🔤a🔤 ➡️ 1 🍆 ➡️ m |
Lists and Dictionaries |
m.find(key) |
🐽 m key❗️ (the result is 🍬) |
Lists and Dictionaries |
std::optional<T> |
🍬T |
Optionals |
std::nullopt |
🤷♀️ |
Optionals |
v.push_back(x) |
🐻 v x❗️ |
Lists and Dictionaries |
std::sort |
🦁 v compare❗️ |
Lists and Dictionaries |
Classes and types
| C++ | Emojicode | Chapter |
|---|---|---|
class |
🐇 |
Classes |
struct (a type treated as a value) |
🕊 (value type) |
Value Types and Enumerations |
enum class |
🔘 |
Value Types and Enumerations |
| Constructor | 🆕 |
Classes |
| Member function | ❗️ name 🍇 … 🍉 |
Classes |
static member function |
🐇❗️ name 🍇 … 🍉 |
Classes |
override |
✒️ |
Inheritance |
Base::method() (calling the superclass) |
⤴️method❗️ |
Inheritance |
private |
🔒 |
Classes |
| Interface / pure virtual class | 🐊 (protocol) |
Protocols |
template <typename T> |
🐚T⚪️🍆 |
Generics |
this |
👇 |
Classes |
Error handling
| C++ | Emojicode | Chapter |
|---|---|---|
throw |
🚨🆕🚧 message❗️ |
Error Handling |
try { … } catch (e) { … } |
🆗 name call 🍇 … 🍉 🙅 e 🍇 … 🍉 |
Error Handling |
e.what() |
💬 e❗️ |
Error Handling |
Functions and lambdas
| C++ | Emojicode | Chapter |
|---|---|---|
[](int64_t x) { return x * 2; } |
🍇 x 🔢 ➡️ 🔢 ↩️ x ✖️ 2 🍉 |
Closures |
std::function<int64_t(int64_t)> |
🍇🔢➡️🔢🍉 |
Closures |
f(21) |
⁉️ f 21❗️ |
Closures |