A very concise golfing language
$ pip install thon
https://github.com/nayakrujul/thon
<a href="https://github.com/nayakrujul/thon">Thon</a>
[Thon](https://github.com/nayakrujul/thon)
Use the thon
command in the terminal, followed by your code.
$ thon "NS"
The thon
command takes in some flags. Here they are. An example usage is thon "S" -il
.
- Without the
-el
flag, the element at the top of the stack is implicitly output at the end of the program. - Just using
-el
removes the implicit output - Specifying a number,
n
, after-el
, e.g.-el 3
, meansn
elements from the top of the stack will be output at the end of the program.
Implicitly push "Hello, world!"
at the start of the program.
Implicitly input one integer at the start of the program.
Implicitly input a list of integers, separated by spaces, at the start of the program.
Implicitly input one string at the start of the program.
Implicitly input a list of strings, separated by spaces, at the start of the program.
Join the elements that are implicitly output at the end by a space.
Join the elements that are implicitly output at the end by a comma.
Join the elements that are implicitly output at the end by a new line.
Thon, like many other golfing languages, is stack-based. This means that whenever you perform an operation, the result is pushed to the top of the stack, a list of every variable that has been used.
Unlike many other golfing languages, Thon does not use special symbols. Every character in Thon is in the printable ASCII character set, meaning you can find it on a standard keyboard.
To push a number to the top of the stack, just write it. These are all valid numbers:
1
= integer, 1123
= integer, 1231.23
= float, 1.231.
= float, 1.0.1
= float, 0.1
Thon has these operators for numbers:
+
: addition-
: subtraction*
: multiplication/
: division^
: exponentiation
In Thon, the numbers come first, and the operator is at the end. For example, to add 1
and 2
, use:
1 2+
A string in Thon starts and ends with a double quote ("
)
"Hello, world!"
However, if the closing quote is at the very end of the program, you can leave it out. It will be autocompleted by the interpreter:
"Hello, world!
To create an empty list in Thon, use L
. Then, to append to it, use A
:
L1A2A3A
(creates a list, [1, 2, 3]
)
To remove the first instance of an element from a list, use R
:
L1A23A1R
(creates a list, [1, 2, 3]
, then removes 1 from it, leaving the list as [2, 3]
)
To get the sum of a list, use S
:
L1A2A3AS
(creates a list, [1, 2, 3]
, then sums it, giving an output of 6
)
To get the product of a list, use P
:
L1A2A4AP
(creates a list, [1, 2, 4]
, then gets its product, giving an output of 8
)
Lists and strings can be indexed. In Thon, these keys are used for indexing:
q
= 1st elementw
= 2nd elemente
= 3rd elementr
= 4th elementt
= 5th elementy
= 5th last elementu
= 4th last elementi
= 3rd last elemento
= 2nd last elementp
= last element
For example:
"Hello, world!"i
This outputs 'l'
, because l
is the 3rd last element of the string
To input an integer, use n
.
To input a list of integers, separated by spaces, use N
.
To input a string, use c
.
To input a list of strings, separated by spaces, use C
.
The Thon equivalent of a for
loop is {
}
:
L"Hello"{A}
Loops through the string "Hello"
, and appends each character to the empty list declared at the start. Output: ['H', 'e', 'l', 'l', 'o']
To convert an integer to any base (up to 64), use B
, specifying the number, and then the base.
18 2B
Output: '10010'
(18 in binary)
To convert a number in any base to decimal (base-10), use D
.
"10010"2D
Output: 18
Thon has a ternary conditional operator which is similar to many other programming languages.
It follows the form: condition ? if_true : if_false
For example:
n?"Yes":"No"
If the user input is truthy, i.e. not 0, it will output "Yes"
. Otherwise, it will output "No"
.
You can use the operators >
, <
, and =
with numbers. They work just like arithmatic operators:
n5>?"Yes":"No"
This will output "Yes"
if the user input was greater than 5, and "No"
if it wasn't.
Here are some example programs in Thon, compared with their Python equivalents.
print("Hello, world!")
"Hello, world!
print(sum(map(int, input().split())))
NS
S
print(bin(int(input(), 16))[2:])
c16D2B
16D2B