#esolang 2 hashtags

Todd Sundsted

A while back, I posted about creating a Forth-inspired programming language that uses emoji as words (functions) and said that I would post the source code. I keep my wordโ€”this weekend I cleaned up the code and published it.

I've built a tool that transpiles emoji source code into either Crystal or Python, and then builds and runs the transpiled source.

Here's the solution to Project Euler Problem 1, with comments so that you can more easily follow the flow:

๐Ÿ’ญ Project Euler Problem 1:
๐Ÿ’ญ Find the sum of all the multiples of 3 or 5 below 1000 => 233168

๐Ÿ’ญ Define a word to check if a number is divisible by 3 or 5
๐Ÿ“–โ“                    ๐Ÿ’ญ Stack: ( n -- bool )
  ๐Ÿ“š                    ๐Ÿ’ญ Duplicate n for two tests
  ๐Ÿ”ข3 ๐Ÿ”€ ๐Ÿ”ข0 ๐ŸŸฐ          ๐Ÿ’ญ (n%3==0)
  ๐Ÿ”„
  ๐Ÿ”ข5 ๐Ÿ”€ ๐Ÿ”ข0 ๐ŸŸฐ          ๐Ÿ’ญ (n%5==0)
  โšก                    ๐Ÿ’ญ (n%3==0 OR n%5==0)
๐Ÿ“•

๐Ÿ’ญ Declare variables
๐Ÿ“ฆ ๐Ÿ’ฏ                   ๐Ÿ’ญ sum variable
๐Ÿ“ฆ ๐Ÿงฎ                   ๐Ÿ’ญ counter variable

๐Ÿ’ญ Initialize variables
๐Ÿ”ข0 ๐Ÿ’พ ๐Ÿ’ฏ               ๐Ÿ’ญ sum = 0
๐Ÿ”ข1 ๐Ÿ’พ ๐Ÿงฎ               ๐Ÿ’ญ counter = 1

๐Ÿ’ญ Loop from 1 to 999 (inclusive)
๐Ÿ”
  ๐Ÿ’ญ Get counter and check if divisible by 3 or 5
  ๐Ÿ“ค ๐Ÿงฎ                 ๐Ÿ’ญ counter
  ๐Ÿ“š โ“                 ๐Ÿ’ญ counter bool

  ๐Ÿ‘
    ๐Ÿ’ญ If divisible, add counter to sum
    ๐Ÿ“ค ๐Ÿ’ฏ โž• ๐Ÿ’พ ๐Ÿ’ฏ       ๐Ÿ’ญ sum = sum + counter
  ๐Ÿ”š

  ๐Ÿ’ญ Increment counter
  ๐Ÿ“ค ๐Ÿงฎ ๐Ÿ”ข1 โž• ๐Ÿ’พ ๐Ÿงฎ     ๐Ÿ’ญ counter = counter + 1

  ๐Ÿ’ญ Test exit condition: counter > 999
  ๐Ÿ“ค ๐Ÿงฎ ๐Ÿ”ข999 โฌ†๏ธ
๐Ÿ”š

๐Ÿ’ญ Print the result
๐Ÿ“ค ๐Ÿ’ฏ ๐Ÿ˜€

Forth is fun because it is so easy to create a simple implementation of the language. It's also very very terse, which makes the emoji-nature of a project like this shine through. Here's the program above with emoji digits, fewer alphanumerics, and less whitespace:

๐Ÿ’ญ Project Euler Problem 1

๐Ÿ“–โ“ ๐Ÿ“š 3๏ธโƒฃ๐Ÿ”€0๏ธโƒฃ๐ŸŸฐ๐Ÿ”„5๏ธโƒฃ๐Ÿ”€0๏ธโƒฃ๐ŸŸฐโšก ๐Ÿ“•

๐Ÿ“ฆ๐Ÿ’ฏ
๐Ÿ“ฆ๐Ÿงฎ

0๏ธโƒฃ ๐Ÿ’พ๐Ÿ’ฏ
1๏ธโƒฃ ๐Ÿ’พ๐Ÿงฎ
๐Ÿ”
  ๐Ÿ“ค๐Ÿงฎ๐Ÿ“š
  โ“๐Ÿ‘๐Ÿ“ค๐Ÿ’ฏโž•๐Ÿ’พ๐Ÿ’ฏ๐Ÿ”š
  ๐Ÿ“ค๐Ÿงฎ1๏ธโƒฃโž•๐Ÿ’พ๐Ÿงฎ
  ๐Ÿ“ค๐Ÿงฎ๐Ÿ”ข999โฌ†๏ธ
๐Ÿ”š

๐Ÿ“ค๐Ÿ’ฏ ๐Ÿ˜€

The project README has more detail on the language features if you're interested.

#emoji #forth #esolang

Todd Sundsted

My post on using emoji in Crystal Language identifiers got some ๐ŸŽ‰ attention. The obvious question was, how much further could I take a Crystal based solution? I played around with macros for a while to see how much syntax I could replace, but that path didn't go very far. Too much of the language, like block delimiters, showed through.

It turns out there is at least one programming language designed almost entirely around emojiโ€”Emojicode. Emojicode is pretty cool and impressively complete, but because Emojicode is, at its core, a fairly traditional imperative language, it is difficult to keep the ASCII out. ๐Ÿค”

I thought I could do better by modeling an emoji-based programming language on a stack-based language like Forth. ๐Ÿ’ก Heavy use of recursion and the stack makes it easy to avoid naming things, which means โœจ less ASCII and more emoji โœจ.

This ugly duckling defines a word (a function) that computes a factorial. The factorial word is the character โ— (the syntax ๐Ÿ“–โ— ... ๐Ÿ“• defines it as a new word). You can see that โ— calls itself recursively, right?

๐Ÿ’ญ Factorial

๐Ÿ“–โ—๐Ÿ“š2๏ธโƒฃโฌ‡๏ธโ“๐Ÿ‘๐Ÿ—‘๏ธ1๏ธโƒฃ๐Ÿ‘Ž๐Ÿ“š1๏ธโƒฃโž–โ—โœ–๏ธ๐Ÿ”š๐Ÿ“•

๐Ÿ”ข5โ—๐Ÿ˜€   ๐Ÿ’ญ 120
๐Ÿ”ข10โ—๐Ÿ˜€  ๐Ÿ’ญ 3628800

You can use spaces and line breaks to make things more readable, but a lot of Forth code kind of looks like this to me so ๐Ÿคท.

There's already a small number of primitive words and a standard library of additional words. I'll probably play around with the core a bit more and then publish it.

Tower of Hanoi ๐Ÿฏ works, too!

#emoji #forth #esolang