Var'aq
A stack language in the style of PostScript, with every keyword in Klingon.
Brian Connors, 2000 · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Brian Connors made var'aq in 2000, with help from Chris Pressey and Mark Shoulson. It is a joke about the Klingon language from Star Trek, but under the joke is a sensible language. It works like PostScript: values go on a stack, words take them off, and code blocks in braces are values too.
Read the story
So if is not syntax. You push a flag, push a block, and say HIja'chugh ("if yes"). A loop is a count, a block and vangqa' ("repeat"). A function is a name, a block and pong ("name"). The Klingon words are the hard part; the model is plain.
There is also an English keyword set. The examples on the wiki use the Klingon one.
The machine
A stack of numbers, strings and blocks, and a table of names. This implementation has the words the wiki examples use, plus a few arithmetic ones.
| Word | Does |
|---|---|
woD latlh tam chImmoH | Drop, dup, swap, clear |
boq boqHa' boq'egh boqHa''egh chuv | Add, subtract, multiply, divide, modulo |
wa'boq wa'boqHa' | Add 1, subtract 1 |
rap'a' rapbe'a' puS'a' law''a' | Equal, not equal, less, greater (1 or 0) |
je joq | And, or |
HIja'chugh ghobe'chugh | Run the block if the value under it is true / false |
vangqa' | Run a block n times |
cher | value name: store a value |
pong | name block: define a word |
~ or lI'moH | Push the next word as a name |
cha' 'Ij | Print the top and a newline; read a line |
tlheghrar | Join two values as text |
(* … *) | Comment |
Popping an empty stack gives 0. An unknown word is an error.
Example
~ double pushes the name, the block follows, and pong binds the two.
~ double pushes the name, the block follows, and pong binds the two. From then on the word double runs the block: latlh copies 21 and boq adds the copies. cha' prints 42 and a newline.
Patterns it teaches
- Stack machines: PostScript's model with different words.
- Code as data: blocks are pushed like numbers and handed to
if,repeatandpong.
Try this
- Print the numbers 1 to 5 with
vangqa'and a variable. - Define a word with
pongthat squares the top of the stack. - Run the wiki's 99 bottles program and change it to count down from 5.
Further
See also
Functional paradigm
Stack-based
Write your own in Run Convert a program from Var'aq
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: varaq.
Command line
shib run varaq -e '"Hello, world!" cha'\'''shib manual varaqSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/varaq.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org