Procedure

From Esolang
Jump to navigation Jump to search

Procedure is an esolang by User:PythonshellDebugwindow. It is case-sensitive, whitespace-sensitive, and newlines are all \r\n.

Memory model

Procedure uses named variables to store data. To set one:

N: Set the variable 'VNAME' to VALUE.

Procedure variables can have any characters in their names, except for the newline, backslash, and single quote/apostrophe characters, and they are weakly typed, so the following:

1: Set the variable 'my variable' to the integer 123.
2: Set the variable 'my variable' to the string "Hello".

is legal. To access its value (here to set another variable):

1: Set the variable 'my variable' to the string "Value".
2: Set the variable 'my other variable' to the variable 'my variable'.

Implicitly cast an integer to a string:

1: Set the variable 'casting example' to the string 123.

File I/O

To connect to (open) the file msg.txt:

N: Connect to the file "msg.txt".

To disconnect from (close) the file msg.txt:

N: Disconnect from the file "msg.txt".

To read a line (up to ASCII 10) from the currently opened file as a string:

text received from the connection

To write "Hello, World!" to the currently opened file:

N: Write the string "Hello, World!" to the connection.

Up to one file can be open at a time. File constants are STDIN, STDOUT, and STDERR; these can be referenced without using the file.

Datatypes

Datatype Example
Integer the integer 123
String the string "Hello, World!"
Decimal the decimal number 3.14159
Character the character `A`
Bit the bit 1

Bits are like Booleans.

Numeric constants (non-literals)

Syntax Value/approx.
-1
the number zero 0
the number one 1
the number E 2.71828...
the number PI 3.14159...

Define/Call Function

To FNAME:
1. CODE
2. CODE
3. CODE

Add 3 numbers:

To addthree a b and c:
1. Return the sum of a and the sum of b and c.

To call:

1. Set the variable 'result' to the addthree of the number 1 the number 2 and the number 3.

Looping

Unconditional GOTOs can be made using Repeat as the line number:

Repeat: Go to step N.

where N is the step to jump to (must be an integer literal) bounded by the current scope (global or function).

Conditional GOTOs

Conditional GOTOs can be made using the If-then instruction:

N: If condition, then go to step N.

where the second N is the step to jump to (must be an integer literal) bounded by the current scope (global or function). If-then-otherwise GOTOs are like this (with the same restrictions for the second and third N):

N: If condition, then go to step N; otherwise, go to step N.

Operators

Operator Syntax
Equality A is equal to B
Inequality A is not equal to B
Greater than A is greater than B
Less than A is less than B
Greater than or equal to A is greater than or equal to B
Less than or equal to A is less than or equal to B

Examples

Hello, World!

1: Connect to STDOUT.
2: Write "Hello, World!" to the connection.
3: Disconnect from STDOUT.

Infinite cat

1: Connect to STDIN.
2: Set the variable 'input' to text received from the connection.
3: Disconnect from STDIN.
4: Connect to STDOUT.
5: Write the variable 'input' to the connection.
6: Disconnect from STDOUT.
Repeat: Go to step 1.

Truth-machine

1: Connect to STDIN.
2: Set the variable 'num' to an integer received from the connection.
3: Disconnect from STDIN.
4: Connect to STDOUT.
5: If the variable 'num' is equal to the number one, then go to step 6; otherwise, go to step 7.
6: Write the number one to the connection.
Repeat: Go to step 6.
7: Write the number zero to the connection.
8: Disconnect from STDOUT.

See also

  • Pure, a version of Procedure