esolang

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

Expected: 42

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.

WordDoes
woD latlh tam chImmoHDrop, dup, swap, clear
boq boqHa' boq'egh boqHa''egh chuvAdd, 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 joqAnd, or
HIja'chugh ghobe'chughRun the block if the value under it is true / false
vangqa'Run a block n times
chervalue name: store a value
pongname block: define a word
~ or lI'moHPush the next word as a name
cha' 'IjPrint the top and a newline; read a line
tlheghrarJoin 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, repeat and pong.

Try this

  1. Print the numbers 1 to 5 with vangqa' and a variable.
  2. Define a word with pong that squares the top of the stack.
  3. Run the wiki's 99 bottles program and change it to count down from 5.

Further

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 varaq

Source

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