Skip to content

neilk/HeartForth

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

HeartForth

❀ πŸ’ž πŸ’• πŸ’˜ πŸ’• πŸ’˜ ❀ πŸ’ž

An Emoji stack language

Synopsis

Instead of standard Forth...

: factorial 0 swap begin dup 1 - dup 1 = until begin * over 0 = until swap drop ;

5 factorial .

>> 120 

In HeartForth, factorial would be...

πŸ˜€πŸ’₯0πŸ’žπŸ‘‰πŸ’•1βž–πŸ’•1πŸ™πŸ‘πŸ‘‰βœ–πŸ’‘0πŸ™πŸ‘πŸ’žπŸ’”πŸ˜‰

5πŸ’₯😘

>> 120

And Fibonacci...

πŸ˜€πŸŒΏ0 1πŸ’˜0βœ‹πŸ’‘βž•πŸ’žπŸ’•πŸ˜˜πŸ‘ŒπŸ’”πŸ˜‰

10🌿

>> 0 1 1 2 3 5 8 13 21 34

Discussion

HeartForth is a dialect of Forth, a stack-oriented language. Where other programming languages use many data structures, Forth has a wealth of operators to manipulate the stack. Emoji has a large number of symbols which incorporate hearts. So....

HeartForth Standard Forth meaning
πŸ’• dup ( a -> a a )
πŸ’” drop ( a -> )
πŸ’‘ over ( a b -> a b a )
πŸ’˜ rot ( a b c -> b c a )
πŸ’ž swap ( a b -> b a )
😘 . show last item on stack
❀ dump show entire stack

Advantages

  • Extremely compact.
  • Clean visual separation between program and data.
  • Whitespace agnostic.
  • Fully internationalized; no bias for English speakers.

Disadvantages

  • None.

Motivation

My friend Ian Baker wondered whether anyone had yet made an all-Emoji programming language. My first thought was to do a Lisp, but I was disappointed in how much the parentheses 🌘 πŸŒ’ dominated the visual look. What we needed was a language which was more stream-of-consciousness, like the way people use Emoji already.

A long time ago I had used another stack-based language, PostScript. They have this curious property of being streams of keywords with some data mixed in. Just like a block of Emoji. Once I realized I could match hearts to stack operators I knew I was onto something. The "revolving hearts" πŸ’ž symbol almost begs to be swap, and hearts have something to do with holding something close or remembering it.

I originally tried implementing a new stack language in pure JavaScript, which was surprisingly easy to get started but surprisingly hard to do things like recursion well. So I decided to simply source-translate to an existing Forth implementation instead.

Complete glossary (so far)

HeartForth Standard Forth meaning
πŸ’• dup ( a -> a a )
πŸ’” drop ( a -> )
πŸ’‘ over ( a b -> a b a )
πŸ’˜ rot ( a b c -> b c a )
πŸ’ž swap ( a b -> b a )
😘 . show last item on stack
❀ dump show entire stack
βž• + add
βž– - subtract
βœ– * multiply
βž— / divide
πŸ™ = equals
πŸ“’ > greater than
πŸ“‘ < less than
πŸ˜€ : begin function definition
πŸ˜‰ ; end function definition
βœ‹ ?do do block if > 0
πŸ‘Œ loop loop
πŸ‘‰ begin start block
πŸ‘ until end loop condition
πŸ‘ if if
πŸ‘ then then

Thanks to

Aadit M. Shah posted this answer on Stack Exchange, which helped me get started.

The repl.it project and ForthFreak for bringing Forth to JavaScript.

Mirrored

On my blog at neilk.net.

Dedication

For my lovely girlfriend Melanie. I heart you 100 factorial .

About

<3 <3 An Emoji stack language <3 <3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published