Rule

From Esolang
Jump to navigation Jump to search

Rule is a slide-rule-oriented esoteric programming language by User:Rdococ.

Semantics

Rule programs operate on a slide rule, consisting of an unbounded array of slideable sections.

The only statement is section1:x::section2:y. It slides section1 such that the number x on section1 aligns with the number y on section2. section1 and section2 must name a section, while x and y can either be a number or the other instruction. If both sections are linear, this is equivalent to the assignment section1 = section2 + x - y.

An expression (the x or y above) can either be a numerical constant or section1:x::section2, which represents the number on section2 that aligns with x on section1. With two linear sections this is equivalent to section2 - section1 + x.

Attempting to slide a fixed segment will break the slide rule, causing all future assignments to fail and future expressions to return completely random numbers. While segments are unbounded and expressions can return infinity (e.g. LogFixed:0::LinFixed), if a segment is slid off to infinity, it will fly off the slide rule and can no longer be used. If this happens to the instruction pointer, the program halts immediately.

Sections

The slide rule is split into several sections which may or may not be slid by the program.

Slide Slideable? Description
LogFixed No A fixed, base-e logarithmic scale.
LinFixed No A fixed linear scale.
AbsFixed No A fixed absolute value scale.
Log Yes A slideable, base-e logarithmic scale.
Output Yes An output scale. When slid, the value at LinFixed:0::Output modulo 256 is rounded to the nearest ASCII code and printed.
IP Yes Slides left to the next integer after the execution of each instruction. LinFixed:0::IP is the index of the current statement.

Referencing a non-existent slide names creates a new linear slide rule.

Computational class

The language describes a machine with unbounded memory, but limited to absolute addressing. The program can freely add, subtract, multiply, divide and get absolute values, as well as perform a computed GOTO by sliding the IP rule. This can be used to emulate a Minsky machine, which is sufficient for Turing completeness.

You can perform a conditional jump with the following steps:

  1. Stick to odd integers for all your register values to avoid breaking the slide rule. Represent 0 with -1 and all higher values with odd positives like 1, 3, 5, etc.
  2. Select a number and divide it by its absolute value. This returns -1 if the register is at "zero" and 1 otherwise. Add 1 and divide by 2 to get 0 or 1 depending on the register's value.
  3. Multiply the condition by one destination IP and multiply 1 minus the condition with the other destination. Finally, add them together and slide the IP to complete the conditional jump.