TypeString

From Esolang
Jump to navigation Jump to search
TypeString (T~)
Designed by User:GUAqwq
Appeared in 2023
Computational class Turing complete
Major implementations Python interpreter
File extension(s) .ts_

TypeString(or T~ in short) is a Turing complete esolang based on String Concating and String Pointer. It's the 3rd esolang of TS Series by User:GUAqwq

Overview

There's 4 keywords in T~: $, =, : and \n. Other texts are split by blank, called string. The code runs line by line, and halts at the end.

\n (end of statements)

Statements are split by \n.

$ (expressions)

When $ is in front of a string, the whole expression $string gets what the string is pointing to. That's why T~ is based on String Pointer.

All strings point to undefined(which is also a string) by default, the point relations can be changed by Assign Statements.

Multi-$ are allowed. For example, if a points to b , and b points to c. Then $$a will be c.

A string with no $ is also a expression.

= (Assign and Bind)

Assign Statement:

$left = right1 right2 right3 ...

where left and right parts are expressions. When the statement is executed, left will point to right1right2right3...(the right parts will concat together).

$a = b
$b = a $a

Then $b will be ab

When there's no $ on the left, that will be a new statement: Bind Statement:

left = right1 right2 right3 ...

where left is just a string.

When the statement is executed, all left in the code will replaced with right1right2right3..., and there's no way to undo.

Do not let the string bind to it self, or the code will try to replace the string with itself, then replace itself with itself... FOREVER!.

: (Label and Jump)

When a statement includes only one expression, its a label with the value of the expression. For example:

$a = label2
label1
$a

We'll get 2 labels, label1 and label2.

Jump Statement:

: first_expr second_expr label_expr

If the first_expr and the second_expr is equal, the program jumped to the label. (If there's more than 1 label with the same value, jump to the last)

I/O

String input binds to user_input.

The program will print out what output is binding when it halts.

Note: I/O is using bind, not assign.

Turing Completement prove

Simple process controll

It is easy to find out the ways to implement IF and WHILE:

pseudo-code:

if(a==b){BLOCK0}
elif(c==d){BLOCK1}
else{BLOCK2}

while(e!=f){BLOCK3}

T~ code:

: a b __case0
: c d __case1
: __always __always __case2
__case0
BLOCK0
: __always __always __ifend0
__case1
BLOCK1
: __always __always __ifend0
__case2
BLOCK2
__ifend0

__loop0
: e f __whileend0
BLOCK3
: __always __always __loop0
__whileend0

As you see, while(e!=f) acts more like break. So there won't be the implement for break

Boolean System

Use true as true, And false as false. So that we can use if(expr == __true){BLOCK} for process controlling.

pseudo-code:

$result = $a == $b

T~ code:

$result = false
: $a $b _true
: _always _always _end
_true
$result = true
_end

pseudo-code:

$result = !$a

half-pseudo-code(using pseudo-code that are already implemented):

if($a == true){
    $result = false
}else{
    $result = true
}

Other boolean operations are also easy to implement.

Natural number System

Use several . to express a unary number:

0 = .
1 = ..
2 = ...
$n+1 -> $n .

Now we have successors, let's implement predecessor:

half-pseudo-code:

;let's pretend this is a comment
4 = .....
$x = 4
if($x==0){ $n = 0 }
else{
    $temp = 1
    $n = 0
    while(temp!=x){ 
	     temp++
	     n++ ;wow! new systactic sugar!
    }
}
;now the anwser is $n

It looks similar to how λ-calculus gets the predecessor.

Now it is easy to add 2 numbers up:

concat them together, then precede it.

Array implement

The solution is quite simple:

concat the array_name with the index.

half-pseudo-code:

;you have already got array as a string, and index as a index_pointer.
$combined_name = array $index ;use combined_name to temporaly store array[idx] pointer.
;read
$result = $$conbined_name
;write
$$combined_name = value ;the first $ gets the name, and the second $ points at where value stored

The array is unbounded(of course you can set one).

Turing Complete

Obviously, the above implementations support implementing most of turing-complete languages, like brainfuck.Can somebody implement one?

Q.E.D. (fantastic)

Examples

Cat

output = input

Note: never input "output"!!!

NOT

$result = error;plz_enter_"True"_or_"False"
: input False _true
: input True _false
: always always end
_true
$result = True
: always always end
_false
$result = False
end
output = $result

Interpreters

Interpreter written in Python by User:GUAqwq

See also

  • Stringle, another language with a similar concept