var'aq

From Esolang
Jump to navigation Jump to search

var'aq is an esoteric programming language based on the fictional Klingon language. var'aq was created in 2000 by Brian Connors, with some help from Chris Pressey and Mark Shoulson.

There are two equivalent sets of instructions for var'aq, one with Klingon keywords and one with English keywords.

Most of the instructions in var'aq operate directly on the stack, but there is also a variable space where values and procedures can be stored by name. var'aq supports the following data types: number, function, list and string.

Using variables

To assign a value to a variable you must first push the value, then the name of the variable onto the stack. To push the name of a variable instead of its value, the spec tells you to use lI'moH operator. The cher operator can then be used to bind the value to the variable name.

1 lI'moH var cher  (* var = 1 *)

However, in the reference interpreter the lI'moH operator does not work inside a procedure. This is probably a bug, and not intended. As a workaround for this you can push the variable name as a string instead:

1 "var" cher

Alternatively you can create a pointer to the variable outside of the procedure:

lI'moH var lI'moH pvar cher (* pvar's value is var's name *)
{ 1 pvar cher }   (* pushing pvar will now be equivalent with pushing lI'moH var *)

The lI'moH operator can also be written as ~.

Examples

Hello, world!

"Hello, world!" cha'

Fibonacci sequence

This program will display the 20 first Fibonacci numbers.

0 lI'moH A cher (* store the first two numbers as A and B *)
1 lI'moH B cher  
 
A cha' B cha' (* print the first two numbers *)
 
18 {         (* repeat 18 times *)
  A B boq      (* push the sum of A and B *)
  latlh        (* duplicate the result *)
  cha'         (* print the new number *)
  B "A" cher   (* store B in A *)
  "B" cher     (* store the new number in B *)
} vangqa'    (* end repeat *)

Note that the vangqa' keyword does not work in the interpreter available on the var'aq home page, so be sure to use the updated interpreter below!

99 bottles of beer

~ bottles { 
  latlh 1 rap'a' "" tam 
    { woD "s" } ghobe'chugh 
  " bottle" tam tlheghrar tam woD 
  " of beer" tlheghrar 
} pong

~ print-verse { 
  latlh latlh bottles tlheghrar " on the wall" tlheghrar cha'
  latlh latlh bottles tlheghrar cha'
  "Take one down and pass it around" cha'
  wa'boqHa' latlh latlh  { "No" } ghobe'chugh latlh bottles tlheghrar " on the wall" tlheghrar cha' 
  "" cha' 
  latlh { print-verse } HIja'chugh
} pong

99 print-verse

Leap year

'Ij
~ DIS cher
(* if it is divisible by 4 but not by 100 *)
DIS 4 chuv
0
rap'a'
DIS 100 chuv
0
rapbe'a'
je
(* if it is divisible by 100 and by 400 *)
DIS 100 chuv
0
rap'a'
DIS 400 chuv
0
rap'a'
je
(* if any of the above *)
joq
latlh
{ "Is a leap year" cha' }
HIja'chugh
{ "Isn't a leap year" cha' }
ghobe'chugh

See also

External resources