Skip to content

Tutorial

Rujul Nayak edited this page Dec 31, 2022 · 2 revisions

Data Types

Thunno understands three different data types:

  • Numbers
  • Strings
  • Lists

Numbers

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

Strings

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 string Hello, world!.
  • However, single quotes can be used for one-character strings. The code 'H will push the string H.
  • You can also use Z", Z', z" and z' for 2, 3, 4 and 5 character strings repectively (see the list of commands).
  • A" and A' 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!"+ outputs Hello, world!

You can multiply a string and an integer together to repeat a string:

  • "Hello "5* outputs Hello Hello Hello Hello Hello

Lists

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)

The stack

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.

Clone this wiki locally