100 Languages Speedrun: Episode 02: Emojicode
Tomasz Wegrzanowski
Posted on November 22, 2021
Most programming languages are created to address some genuine need, but some are just an art statement. One such art statement is the Emojicode language - self-described as a "full-blown programming language consisting of emojis."
Hello World
Let's start by writing hello.๐
:
๐ญ๐๐ธ๐
๐ ๐
๐ ๐ค๐ท๐ด๐ป๐ป๐พ, ๐
๐พ๐
๐ป๐ณ๐คโ๏ธ
๐
As you can see, usual keywords have been replaced by emoji:
- ๐ญ are comment lines
- ๐ ๐ ... ๐ is the main function
- ๐ค is like quotes
- ๐...โ๏ธ is like print
- in general, โ๏ธ ends argument list
The contents of the strings and comments don't have to be emoji, but I used my app for fancy text to spice them up as well.
Variables
We can put thing in variables by using โก๏ธ. Variables go on the right, which is fairly unconventional choice, but not completely unheard of. ๐งฒ does string interpolation:
๐ ๐
๐คโโฅโโกโจโโโ๐คโก๏ธwho
๐ ๐ค๐ท๐ด๐ป๐ป๐พ, ๐งฒwho๐งฒ๐คโ๏ธ
๐
Lists and for loops
Lists are created by ๐ฟ...๐
. I get the first emoji, not so sure about the second one.
You can loop with ๐ iterator list ๐ body ๐
, which is a decent loop emoji:
๐ ๐
๐ฟ
๐คPython๐ค
๐คJavaScript๐ค
๐คRuby๐ค
๐คEmojicode๐ค
๐คPHP๐ค
๐โก๏ธlanguages
๐ ๐คMost important languages to learn๐คโ๏ธ
๐ language languages ๐
๐ languageโ๏ธ
๐
๐
FizzBuzz
We need a few more things here.
-
๐ variable ๐โฉ start afterend step
is afor i in range(start, afterend, step)
loop. -
i ๐ฎ 15 ๐ 0
isi % 15 == 0
- โช๏ธ, ๐
โโช๏ธ, and ๐
are
if
,else if
, andelse
And with that we can write a FizzBuzz, using fancy fonts for output as well:
๐ ๐
๐ i ๐โฉ 1 101 1 โ ๐
โช๏ธ i ๐ฎ 15 ๐ 0 ๐
๐ ๐ค๐ฝ๐๐ซ๐ซ๐น๐ฆ๐ซ๐ซ๐ค โ
๐
๐
โช๏ธ i ๐ฎ 3 ๐ 0 ๐
๐ ๐ค๐ฝ๐๐ซ๐ซ๐ค โ
๐
๐
โช๏ธ i ๐ฎ 5 ๐ 0 ๐
๐ ๐ค๐น๐ฆ๐ซ๐ซ๐ค โ
๐๐
๐
๐ ๐ค๐งฒi๐งฒ๐ค โ
๐
๐
๐
Doubling things
We need one more thing - functions.
Well, we're a bit lost. Documentation doesn't say anything about functions. It has closures so we'd think that this might work:
๐ ๐
๐ i ๐ขโก๏ธ๐ข
โฉ๏ธ iโi
๐ โก๏ธ double
๐ ๐ค๐งฒโ๏ธ double 21โ๐งฒ๐คโ
๐
We need to declare types. ๐ขโก๏ธ๐ข means takes an integer, and returns an integer. โฉ๏ธ is return. โ๏ธ...โ is function call. Not too bad.
Y Combinator fail
Unfortunately these cannot be recursive, so this doesn't work at all!
๐ ๐
๐ n ๐ขโก๏ธ๐ข
โช๏ธ n โ๏ธ 3 ๐
โฉ๏ธ 1
๐๐
๐
๐ญ Does not work
โฉ๏ธ โ๏ธ fib nโ1โโโ๏ธ fib nโ2โ
๐
๐ โก๏ธ fib
๐ ๐ค๐งฒโ๏ธ fib 5โ๐งฒ๐คโ
๐
Well, I thought about doing the old Lisp trick, and pass fib closure as argument to fib, so it can call itself, but that only works if there are no stupid types getting in the way. It's possible for type system to support Y combinator if it supports recursive types, but I don't think Emojicode does.
Classes
The documentation doesn't say anything about functions, but it has classes. So let's define class ๐ค with method ๐ that does fib:
๐ ๐ค ๐
๐๐
๐
โ๏ธ ๐ n ๐ขโก๏ธ๐ข ๐
โช๏ธ n โ๏ธ 3 ๐
โฉ๏ธ 1
๐๐
๐
โฉ๏ธ ๐๐ nโ1โโ๐๐ nโ2โ
๐
๐
๐
๐ ๐
๐๐คโ๏ธ โก๏ธ fib
๐ i ๐โฉ 1 31 1 โ ๐
๐fib iโ๏ธ โก๏ธ x
๐ ๐ค๐งฒx๐งฒ๐คโ
๐
๐
If you've been following along, this code shouldn't be too difficult to understand.
-
๐๐คโ๏ธ โก๏ธ fib
- creates a new ๐ค and assigns it tofib
variable -
๐fib iโ๏ธ โก๏ธ x
- calls ๐ onfib
instance, calling our only method with argumenti
-
๐ ๐ค ๐ ... ๐
- definition of a class with name ๐ค (class names must be emoji) -
๐๐๐
- empty constructor, we need some constructor for every class, even if it doesn't do anything -
โ๏ธ ๐ n ๐ขโก๏ธ๐ข ๐...๐
- defining method ๐...โ๏ธ that taken one integer argumentn
and returns an integer -
โฉ๏ธ ๐๐ nโ1โโ๐๐ nโ2โ
- recursive call, ๐๐ nโ1โ isthis.๐(n-1)
in more usual language
Unicode
This language was of course created as an art statement (or as a joke if you prefer to put it that way), but it asks an important question. Throughout the history of programming, nearly every language (APL and Raku being the most notable exception, and don't worry - we'll surely cover both in this series) limited itself to just plain text with ASCII characters.
Even though ASCII symbols were clearly not enough, so symbols get reused to mean ten different things (try to list all syntactic meanings of {}
characters in JavaScript or actually in just about any language), and long strings of characters like !==
, **=
and such get used as fake extra characters.
So the question is - should programming languages keep limiting themselves to just ASCII, or is it finally time to embrace the whole Unicode? An interesting middle ground are ligature fonts like Fira Code - the source code would still say !==
, but in the editor you'd see โข
.
Code
All code examples for the series will be in this repository.
Posted on November 22, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.