Piquant
Piquant is an esoteric programming language, in which all code blocks are treated as conditionally selectable states.
Overview
Piquant has a one-dimensional array of memory cells, each of which can hold one number. Text is largely unsupported (with the exception of the q command; see below). Memory is referenced using the letter A
; the first memory cell is called A0
, the second A1
, etc. Ranges of cells can be referenced with a colon (e.g. A0:5
). Indirect references are also possible using multiple A
s; for example, AA0
references the cell whose index is the number stored in A0
.
All Piquant programs begin by initialising the memory, by means of a list of numbers in square brackets. For example, [1, 2]
would set A0
to 1 and A1
to 2. Any cells not initialised are automatically set to 0. These values are set once, at the very start of the program.
Everything following this is written in this format:
{condition1; action1a; action1b…} {condition2; action2a; action2b…}
The entire program essentially acts as a large, repeating switch-case statement; whichever code block has a true condition will be executed. If multiple conditions are true, all except the first will be ignored. This process loops until no conditions are true, at which point the program halts. All conditions and actions use standard arithmetic and logic operators, that is:
Operator | Effect |
---|---|
Arithmetics | |
+ |
Addition |
- |
Subtract |
* |
Multiplication |
/ |
Division |
% |
Remainder of division |
= |
Assignment |
Relationships | |
== |
Equal to |
!= |
Not equal to |
> |
Greater than |
≥ |
Greater than or equal to |
< |
Less than |
≤ |
Less than or equal to |
Logic | |
&& |
Logical AND combination |
|| |
Logical OR combination |
There are three additional commands:
Command | Function |
---|---|
i |
Prompts user for input, and stores result in specified cell (e.g. iA0 )
|
p |
Prints specified number (e.g. p1 ), or contents of specified cell (e.g. pA0 )
|
q |
Prints ASCII character with specified value (e.g. q65 or qA0 )
|
No other letters are allowed in programs. Comments can be added with #
.
Example programs
Cat program
[] {A0 == 0; iA0; pA0; A0 = 1}
Hello world
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100] {A0 == 72; qA0:10; A0 = 0}
The following program utilizes indirect referencing in order to print the message “Hello world”. The first eleven cells, A0
through A10
, comprehend the text's ASCII codes, whereas the next eleven cells, A11
through A21
, list these indices in their correct order. The program requests the values of the cells A11:A21
, that is, A0:A10
, and employs these as the actual cell indices for the character printing operation.
[72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] {A0 == 72; qAA11:21; A0 = 0}
Truth machine
[] {A0 == 0; iA0; pA0} {A0 == 1; pA0}
Fibonacci series
[1] {A0 >= A1; pA0; A1 = A0 + A1} {A0 < A1; pA1; A0 = A0 + A1}
Factorial
[] {A0 == 0; A0 = 1; iA1} {A1 > 1; A0 = A0 * A1; A1 = A1 - 1} {A1 == 1; pA0; A1 = 0}
FizzBuzz
[1, 70, 105, 122, 122, 66, 117, 122, 122] {A0 > 100; A0 = -1} {A0 % 3 == 0 && A0 % 5 == 0; qA1:8; A0 = A0 + 1} {A0 % 3 == 0; qA1:4; A0 = A0 + 1} {A0 % 5 == 0; qA5:8; A0 = A0 + 1} {A0 != -1; pA0; A0 = A0 + 1}
Notes
The name “Piquant” was chosen as it is one of the few English words containing the letters A, I, P and Q, the four letters permitted within programs.
Interpreter
- Common Lisp implementation of the Piquant programming language.