Pinocchio

From Esolang
Jump to: navigation, search

Pinocchio is a language by that_dude. The language's variable types are noses.

In the Pinocchio programming language, you must create different Pinocchios (similar to functions in real languages, but with differences). For example:

Pinocchio main{
	#code...
}

Each Pinocchio has a nose, the only variable in a Pinocchio. The noses of other Pinocchios can be accessed, but not changed. Invoking/running a Pinocchio is done by talking to it from another Pinocchio. The "main" Pinocchio is run automatically. To increase the length of a Pinocchio's nose, that Pinocchio must tell a lie. To decrease it, it must tell the truth. For example:

Pinocchio main{
	dancer.talk();
}
Pinocchio dancer{
	yes(false); # the Yes function causes the Pinocchio to assert that the contents are true. If they aren't, its nose increases; if they are, it increases.
	yes(false);
	yes(true); # The value of this Pinocchio's nose is now 1 more than its start, 0.
}

"if" statements are as you would expect, but loops are different. Only the entirety of a Pinocchio can be looped. The value of the Pinocchio's nose is kept. To loop, a Pinocchio must talk to Geppetto.

Pinocchio main{
	liar.talk();
	if (liar.nose < 17) {
		Geppetto.talk(); # Geppetto is a reserved name and cannot be used as the name of a Pinocchio.
	} # There is no else statement. There are several ways of getting around this, but I won't explain them.
}
Pinocchio liar{
	yes(false);
}

To print the value of a nose, you use print([name of Pinocchio]); This will print the ASCII value of the nose. For instance:

Pinocchio main{
	liar.talk();
	if (liar.nose != 65) {
		Geppetto.talk();
	}
	if (liar.nose == 65) {
		truthseeker.talk();
	}
}
Pinocchio liar{
	yes(liar.nose == 65); #If it is 65 before liar is run, it will decrease. In other words, failsafe.
}
Pinocchio truthseeker{
	print(liar);
}

The above code will print A.

Additional notes

As should be obvious, once a Pinocchio has finished running, it will return to the Pinocchio that talked to it.

"me" can be used as an abbreviation for the current Pinocchio. However, all Pinocchios are sane, so me.talk() is invalid. To loop, the Pinocchio MUST talk to Geppetto.

LF (12) will (well, should, as there's no official interpreter yet) automatically be output as CR (15) LF (12) on Windows, so line endings only need LF.

Examples

Hello World

Pinocchio main{
	writeH.talk();
	writee.talk();
	writel.talk();
	writel.talk();
	writeo.talk();
	writeW.talk();
	writeo.talk();
	writer.talk();
	writel.talk();
	writed.talk();
	writeLF.talk();
}
Pinocchio value{
	yes(direction.nose == 1);
}
Pinocchio direction{
	yes(me.nose == 1);
}
Pinocchio display{
	print(value);
}
Pinocchio.writeH{
	value.talk();
	if(value.nose < 72) {
		Geppetto.talk();
	}
	display.talk();
}
Pinocchio.writee{
	value.talk();
	if(value.nose < 101) {
		Geppetto.talk();
	}
	display.talk();
}
Pinocchio.writel{
	if(value.nose < 108) {
		if (direction.nose == 1) {
			direction.talk();
		}
		value.talk();
		Geppetto.talk();
	}
	if(value.nose > 108) {
		if (direction.nose == 0) {
			direction.talk();
		}
		value.talk();
		Geppetto.talk();
	}
	if(value.nose == 108) {
		display.talk();
	}
}
Pinocchio.writeo{
	if(value.nose < 111) {
		if (direction.nose == 1) {
			direction.talk();
		}
		value.talk();
		Geppetto.talk();
	}
	if(value.nose > 111) {
		if (direction.nose == 0) {
			direction.talk();
		}
		value.talk();
		Geppetto.talk();
	}
	if(value.nose == 111) {
		display.talk();
	}
}
Pinocchio.writeW{
	if(direction.nose == 0) {
		direction.talk();
	}
	value.talk();
	if(value.nose > 87) {
		Geppetto.talk();
	}
	display.talk();
}
Pinocchio.writer{
	if(direction.nose == 1) {
		direction.talk();
	}
	value.talk();
	if(value.nose < 114) {
		Geppetto.talk();
	}
	display.talk();
}
Pinocchio.writed{
	if(direction.nose == 0) {
		direction.talk();
	}
	value.talk();
	if(value.nose > 100) {
		Geppetto.talk();
	}
	display.talk();
}
Pinocchio.writeLF{
	value.talk();
	if(value.nose > 12) {
		Geppetto.talk();
	}
	display.talk();
}