Pure

From Esolang
Jump to navigation Jump to search

Pure is a standardized version of Procedure created by User:A. Pure is case-insensitive and is expected to be much terser than Procedure programs.

Port instruction and related

Currently the only supported ports are STDIN and STDOUT.

  • connect to x: Set the current port to x. It only works if no ports are currently connected.
  • disconnect from x: Remove the current port, x is a comment. It fails if there are already no ports connected.
  • port x: Output/Input according to the current port. If the current operand is a variable, you are allowed to quote the variable with single quotes.
  • write x: An alias for port, intended for writing instructions.
  • set x: Another alias for port, intended for reading instructions.

The rules of the connection include:

  • If a port is already connected, any attempt to connect another port will fail.
  • If there aren't ports connected already, the port instruction will fail to execute.
  • If the current connected port is STDIN, the port command will read from STDIN, evaluate it, and set the variable to that value.
  • If the current connected port is STDOUT, the port command will evaluate its argument, and output the evaluated thing to STDOUT.
  • Variables in Pure are weakly typed. That means you can change its type whenever you want by changing the type of the value it stores.
  • The to and from in connect and disconnect are optional respectively.

Comments and NOP instructions

  • Lines are expected to end with the period ., although it's still possible to do without that.
  • to introduces a one-line comment that runs up to the period . or a newline. It isn't expected to work if the previous string is connect.
  • from is an alias for to. However, it works differently: It isn't expected to work if the previous string is disconnect.
  • the comments out the next word in the program, intended for backwards-compatibility with Procedure.

Datatypes

This section is merely for documenting Pure's type system.

Integers

Integers are a sequence of digits of [0-9] that doesn't start with 0.

A line of Pure

A line of Pure is expected to look like this:

N: Line of Code.

N stands for the line number. It can either be an integer larger than 1 or repeat (an anonymous line that isn't expected to be indexed). The trailing space after the colon is optional.

What does line of code stand for?

line of code is expected to be one of the Pure instructions. Here's a reference of all instructions:

  • connect to x: Set the current port to x. It only works if no ports are currently connected.
  • disconnect from x: Remove the current port, x is a comment. It fails if there are already no ports connected.
  • port x: Output/Input according to the current port.
  • write x: An alias for port, intended for writing instructions.
  • set x: Another alias for port, intended for reading instructions.
  • if condition, then go to step placeHolderStep; otherwise, go to step placeHolderStep. A control flow instruction.
  • Go to step placeHolderStep.: Switch the control flow the the intended step.

Restrictions

  • You can not go to a repeat step; instead, the steps have to be a non-negative integer.
  • The go to step is optional in the conditional statement.
  • The step part in the control flow switching instruction is optional.

Hello, World!

1: Connect STDOUT.
2: Port "Hello, World!".
3: Disconnect STDOUT.

Infinite cat

1: Connect STDIN.
2: Port input.
3: Disconnect STDIN.
4: Connect STDOUT.
5: Port input.
6: Disconnect STDOUT.
7: Go to 1.

Truth-machine

1: Connect STDIN.
2: Port num.
3: Disconnect STDIN.
4: Connect STDOUT.
5: If num is equal to 1, then 6; otherwise, 8.
6: Port 1.
7: Go to 6.
8: Port 0.
9: Disconnect STDOUT.

See also