And

From Esolang
Jump to: navigation, search
This article is a stub, which means that it is not detailed enough and needs to be expanded. Please help us by adding some more information.

The And programming language is a very peculiar esoteric language by User:Rdococ.

Structure

And takes advantage of lazy evaluation so that you can do this:

((x < 3 || y > 2 || z[3] = 1) && input = 'a') && (x := y + 1 && y := 0 && print "Hello guys!")

In that snippet of And code, if x < 3 or y > 2 or the fourth entry of z = 1, and your input is the letter a, then x will become y + 1 and y will become 0, and then the user will see the words, "Hello guys!", and then the instruction pointer will return to the top, asking for another input. The reason this stuff happens is because of lazy evaluation - which allows a chain of and operators like that to work like a conditional.

And code is essentially lines upon lines of chained && and || operations that are repeatedly evaluated over and over again, asking the user for input every time. Who needs conditionals?!

Oh and a few more things. The exit statement - when evaluated - will end the program. The print statement - when evaluated - will print a message. And stuff like assignment and printing always return true.

Computational Class

At least that of a push down automaton.

Proof

This code halts when the number of {'s inputted equals the number of }'s inputted - that is, the brackets are nested properly.

(input = '{' && (x := x + 1 && (x = y && exit))) ||
(input = '}' && (y := y + 1 && (x = y && exit) && return))

Reduction to brainfuck

ugh... I know it is possible... but...

Examples

Hello World

print "Hello World!" && exit

Cat program

This is a bit restricted because the user can only input one character at a time.
print input

99 bottles of beer

This version adds a new line every time it is evaluated. It goes from 99 to 0 and then repeats, and it handles grammar correctly.

s = 0 && (n := 99 && s := 1) || (
(n = 0 && (print "No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall." && n := 99)) ||
(n = 1 && (print "One bottle of beer on the wall. One bottle of beer. Take one down and pass it around, no more bottles of beer on the wall." && n := n - 1)) ||
(n = 2 && (print "Two bottles of beer on the wall. Two bottles of beer. Take one down and pass it around, one bottle of beer on the wall." && n := n - 1)) ||
(n > 2 && (print n + " bottles of beer on the wall. " + n + " bottles of beer. Take one down and pass it around, " + (n - 1) + " bottles of beer on the wall." && n := n - 1)))