Not A Programming Language

From Esolang
Jump to navigation Jump to search
This is still a work in progress. It may be changed in the future.

Not A Programming Language, or NAP for short is a programming language that is not a programming language, created by User:PkmnQ. It is made for use in The Town of Not A Town (abbreviated to NAT Town), a town notable for violating many laws of physics and mathematics, as other programming languages were not contradictory enough to be useful for NAT Town purposes.

Example Code

Hello World

"Hello, World!"

99 bottles of beer

c I 99 1 {"{1:[I] bottles of beer} on the wall,\n{1}.\nTake one down, pass it around,"; s; "{1}"}

Recursive Factorial

f Fact N {i (e N 0) {r 1}; i (g N 0) {r [N*Fact [N-1]]}}

Iterative Factorial

f Fact N {e 1; c I 1 N {d J; e [J*I]}; d J; r J}

Syntax

Printing

Printing constant strings is easy:

"String goes here"

Escaping is simple.

"I can escape quotes (\") using backslashes (\\)"

To add newlines, do this:

"One line\nAnother line"

You can add expressions like so:

"Variable I has the value [I]"

If there are repeated substrings, you can do this:

"James, while John {1:had} {1} \"{1}\", {1} {1} \"{1} {1}\". \"Had {1}\" {1} {1} a better effect on the teacher."

You can even nest substrings inside other substrings.

"James, while John {2:{1:had} {1}} \"{1}\", {2} \"{2}\". \"Had {1}\" {2} a better effect on the teacher."

Commands

Commands are separated by semicolons.

Opcode Arguments Description
a var, expr Increments the variable by expr.
c var, exprStart, exprEnd A count loop. Sets var to exprStart and either increments or decrements to exprEnd. Basically, a simple form of a for loop.
d var Dequeues a value from the queue and sets the variable to it.
e expr Enqueues an expression to the queue.
f name, args, block Defines a new function. The name is required to start with an uppercase letter, like variables.
i cond, block If the condition is true, the block gets run.
r expr Returns the value for a function.
s Advances the count loop.
u cond, block Until the condition is true, the block gets run.
w cond, block While the condition is true, the block gets run.
x block Comment (do nothing)

Conditions

Conditions have a similar syntax to commands, but they're surrounded with parentheses.

(h fact 1)
Opcode Arguments Description
a cond1, cond2 Reports if both conditions are true.
e expr1, expr2 Reports if the result of the 2 expressions are equal.
f Always reports false.
g expr1, expr2 Reports if the result of expr1 is greater than the result of expr2.
h func, args Reports if func halts for the args.
l expr1, expr2 Reports if the result of expr1 is less than the result of expr2.
n cond Negates the condition.
o cond1, cond2 Reports if at least one condition is true.
t Always reports true.

Expressions

This section is incomplete.

Expressions are made up of one or more values or other expressions. They are enclosed in brackets, unless inside other expressions or consist of only one value:

[N+1]

Operators

Unary Operators

This section is incomplete.

Binary Operators

This section is incomplete.

Custom Functions

This section is incomplete.

Values

Values are either numbers or variables.

Variables

This section is incomplete.

Variables need to start with a capital letter.

I

To set a variable, you can use the queue.

e 1; d I; x {"set to number"}
e C; d I; x {"set to variable"}

Alternatively, with the -d flag (autodeclare), all variables are automatically declared with 0, and you can use the a command instead.

a I 1; x {"set to number"}
a I C; x {"set to variable"}

Blocks

This section is incomplete.

Blocks are codes encased in curly brackets. They're usually used for flow control.

{"This is a block"}