Aheui
A Befunge written in Korean. Each Hangul syllable is one command, and its vowel decides where the cursor goes next.
Puzzlet Chung, 2005 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Puzzlet Chung designed Aheui (아희) in 2005, the first esolang for Hangul, the Korean alphabet. It borrows its grid and moving cursor from Befunge. The new part is how a command is spelled.
Read the story
A Hangul syllable is built from up to three letters: a first consonant, a vowel and a final consonant. Unicode stores all 11,172 syllables in that order, so the three parts fall out of the code point by simple arithmetic. Aheui gives each part a job. The first consonant is the instruction. The vowel is the direction. The final consonant is the argument, such as which storage to use. 밤 is ㅂ+ㅏ+ㅁ: push 4 (the strokes in ㅁ), then move right.
Instead of one stack there are 26 stacks and a queue. There is no command to change the code, so the grid is pure program.
The machine
A grid of syllables; anything that is not a full syllable is a comment. The cursor starts at the top left moving down, and wraps at the edges. Each step, the vowel sets the momentum, the consonant acts, and the cursor moves.
| Vowel | Momentum |
|---|---|
| ㅏ ㅓ ㅗ ㅜ | Right, left, up, down, one cell |
| ㅑ ㅕ ㅛ ㅠ | The same, two cells |
| ㅡ ㅣ ㅢ | Reflect vertical, horizontal, both |
| First consonant | Does |
|---|---|
| ㅇ | Nothing |
| ㅎ | End |
| ㄷ ㄸ ㅌ ㄴ ㄹ | Add, multiply, subtract, divide, modulo (second by top) |
| ㅁ | Pop; with final ㅇ print it as a number, with ㅎ as a character |
| ㅂ | Push: with final ㅇ an input number, with ㅎ an input character, else the final's stroke count |
| ㅃ ㅍ | Duplicate, swap |
| ㅅ | Select the storage named by the final |
| ㅆ | Move the top value to the storage named by the final |
| ㅈ | Push 1 if second ≥ top, else 0 |
| ㅊ | Pop; if it is 0, reverse |
The final ㅇ names the queue; the others name stacks. A command that finds too few values reverses the cursor instead.
Example
An A+B program.
An A+B program. The cursor starts on the top left but every vowel is ㅏ, so it moves right. 방 (ㅂ with final ㅇ) reads a number, twice. 다 adds them. 망 (ㅁ with final ㅇ) prints the sum, and 희 ends.
Patterns it teaches
- Two-dimensional control flow: direction lives in every command, and speed-two vowels jump over cells.
- Stack machines: 26 stacks and a queue, picked by name.
- Encoding tricks: one character carries an instruction, a direction and an argument.
Try this
- Print the number 8 by pushing
밤(4) twice and adding. - Read a number and print it twice.
- Hard: print the numbers 1 to 5 with a loop that uses ㅊ to leave.
Further
See also
CJK
Queue-based
Write your own in Run Convert a program from Aheui
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: aheui.
Command line
shib run aheui -e '방방다망희' --input '3 4'shib manual aheuiSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/aheui.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org