BrainTangle

From Esolang
Jump to navigation Jump to search

BrainTangle is an Esolang invented by PSTF and his 文心一言(because he don't use ChatGPT now).

Syntax Overview

Data Types

BrainTangle only has one data type: a single-character string (a "tangle"). Operations on tangles are performed by manipulating them in various ways.

Programs

Programs in BrainTangle consist of a series of commands, each occupying a single line. Each command is either a basic operation or a control flow statement.

Basic Operations

Tangle Manipulation

  1. ++ Append the current tangle to itself.
  2. -- Remove the last character from the current tangle.
  3. >> Rotate the current tangle to the right (move the first character to the end).
  4. << Rotate the current tangle to the left (move the last character to the beginning).
  5. !! Reverse the order of characters in the current tangle.

Tangle Comparison and Branching

  1. == Check if the current tangle is equal to a specified tangle. If true, execute the next line; otherwise, skip the next line.
  2. != Similar to ==, but executes the next line if the tangles are not equal.

Input/Output

  1. ? Read a single character from input and set it as the current tangle.
  2. ! Output the current tangle to the console.

Control Flow

Loops
  1. loop ... endloop Create a loop that repeats the enclosed block until a specific condition is met (this condition must be manually checked within the loop using comparison operations).
Conditional Statements

BrainTangle doesn't have explicit conditional statements like if/else. However, you can simulate conditional behavior using the == and != operations to skip lines based on the current tangle's value.

Example Program

Here's a simple BrainTangle program that reads a character from input, checks if it's an 'a', and outputs a message accordingly:

?  ; Read input into current tangle  
==a  ; Compare current tangle to 'a'  
    !a found!  ; If equal, output 'a found!'  
    !not a  ; This line is skipped if the tangles are equal  
endloop  ; (Note: This example doesn't actually need a loop, but loops are part of the language)

Note: The syntax and behavior of BrainTangles are highly simplified for this example. In a real implementation, additional details such as how to properly structure loops and handle edge cases would need to be defined.

Turing Completeness

BrainTangle is Turing-complete because it has the ability to manipulate and compare data (tangles), read input, and write output. With these capabilities, it can simulate the behavior of a Turing machine, including its infinite tape and ability to move the tape head and modify the tape's contents. The use of loops and conditional logic allows for more complex computations and decision-making processes.

Categories