-
Notifications
You must be signed in to change notification settings - Fork 1
Tutorial
Thunno understands three different data types:
- Numbers
- Strings
- Lists
To create a number in Thunno, you can just write it:
-
123
pushes 123 to the stack -
1.23
pushes 1.23 to the stack -
.123
pushes 0.123 to the stack
You can do operations on these numbers by using commands after the two numbers:
-
1 2+
adds 1 and 2 together -
10 .2*
multiplies 10 by 0.2 -
2 8^
raises 2 to the power of 8
(You can see the full list of commands here)
As the input is implicitly placed on the stack at the start, these are also possible:
-
1-
subtracts 1 from the input -
2/
halves the input -
2^
squares the input
There are a few ways you can start a string in Thunno:
- The easiest way is to use double quotes (
""
). The code"Hello, world!"
will push the stringHello, world!
. - However, single quotes can be used for one-character strings. The code
'H
will push the stringH
. - You can also use
Z"
,Z'
,z"
andz'
for 2, 3, 4 and 5 character strings repectively (see the list of commands). -
A"
andA'
will start formatted string literals.A"{a} {b} {c}"
will push the first, second, and third items on the stack in a string.
You can add strings using +
:
-
"Hello, ""world!"+
outputsHello, world!
You can multiply a string and an integer together to repeat a string:
-
"Hello "5*
outputsHello Hello Hello Hello Hello
You can create an empty list in Thunno by using l
. You can append to a list by using T
.
This means, to create a list, use l
and then put a T
after every element:
-
l1T2T3T4T5T
outputs[1, 2, 3, 4, 5]
-
l'aT'bT'cT'dT'eT
outputs['a', 'b', 'c', 'd', 'e']
-
ll.1T.2TTl.3T.4TTl.5T.6TT
outputs[[0.1, 0.2], [0.3, 0.4], [0.5, 0.6]]
The elements of a list don't all have to be the same type.
In Thunno, many commands automatically vectorise. This means that you can apply a command like +
to a list:
-
l1T2T3T1+
will add 1 to[1, 2, 3]
to get[2, 3, 4]
-
l'aT'bT'cT3*
will multiply['a', 'b', 'c']
by 3 to get['aaa', 'bbb', 'ccc']
-
ll.1T.2TTl.3T.4TT2*
will multiply[[0.1, 0.2], [0.3, 0.4]]
by 2 to get[[0.1, 0.2, 0.1, 0.2], [0.3, 0.4, 0.3, 0.4]]
(Vectorisation only happens to a depth of 1)
Thunno, like many other golfing languages uses a stack.
Any inputs the program receives are placed on the stack at the start. Then, items can be popped (removed) from the stack, or pushed (added) to the stack.
On the commands page, the second column in the table is "Elements popped". This shows how many items are removed from the top of the stack. Many commands will also push the result to the top of the stack.
MIT License
Copyright (c) 2023 Rujul Nayak
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.