We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Teg

From Esolang
Jump to navigation Jump to search

Teg is an esolang based on strings invented by User:A. It has condensability as well as minimalism and legibility in mind. Normally, it is used to code golf, but it might be used in other circumstances. (By the way, it is a Text derivative.) What differs between this and other esolangs is:

  • Alphanumerical characters are automatically printed (including quotation marks)
  • There are readable and straightforward if statements, for and while loops(at least better than Keg)
  • A few commands should be remembered
  • And so on...

Simple documentation

[]:evaluate operator. Note that this prevents a block of Teg code to be printed.

a?b:c:If a is not 0, return b. Otherwise, return c.
a?b:If a is not 0, return b.

f(i:end){block}:For loop. Sequentially set i into values from 0 to end while executing block. For example: if end is 5, i will be set to 0, 1, 2, 3, 4, and 5.
f(i:begin,end){block}:Also a for loop. Like the one above, sets i into values from begin to end.
f(i:begin,end,step){block}:Yet another variation of the for loop. Sets i into values from begin to end with a step. For example: if begin=0 and end=8 and step=2, i will be set to 0, 2, 4, 6, and 8. Another example: if begin=8 and end=0 and step=-2, i will be set to 8, 6, 4, 2, and 0.

=: define a variable(or possibly a macro).

==: check if equal

!=: check if not equal

>: greater than

<: less than

>=: greater than or equal

<=: less than or equal

!: bitwise NOT

&: bitwise AND

|: bitwise OR

+: add

-: subtract

*: multiply

/: divide

%: find the remainder

^: to the power of

:x:: input a variable(macro?) x

`x`: switch between integer and character variables

Examples

99 bottles of beer

This non-cheating version is a lot shorter than the cheating version of Keg.

b= bottle[i!=1?s] of beer
f(i:99,1){[i][b] on the wall,
[i][b].
Take one down, pass it around,
i?[i-1]:no more[b] on the wall.}

Hello, world!

Hello, World!

Quine

Q

Cat program

w(1){:q:[q]}

FizzBuzz program

f(i:z){!i%3?!i%5?FizzBuzz:Fizz:!i%5?Buzz:[i]
}

Fibonacci sequence

a=1;b=1;w(1){[a] a=a+b;t=a;a=b;b=t}

Deadfish interpreter

c(i);w(1){>>:i:i=="d"?[a=a-1]:i=="i"?[a=a+1]:i=="o"?[a]:i=="s"?[a=a*a]}

Factorial

:c:f(i:c,1){a=a*i}[a]

Truth-machine

:c:c?w(1){1}:0