SkillAgentSearch skills...

Tampio

Tampio: An object-oriented programming language made to resemble Finnish

Install / Use

/learn @fergusq/Tampio

README

The Tampio Programming Language

Tampio is an object-oriented programming language that looks like a natural language – Finnish. It is named after a famous Finnish programmer.

To see this language in action, see the Tic-Tac-Toe example. (For technical reasons, it's named "ristiruutu" instead of "ristinolla", which is the proper Finnish translation.)

This branch currently contains a new iteration of the language that is imperative instead of functional. The functional language is in the functional branch.

Dependencies

  • Python 3
  • Libvoikko (package libvoikko in Ubuntu and Fedora). It seems that some versions of Voikko are not compatible. I have tested that the program works with 3.8 and 4.1.1.
  • Finnish morphological dictionary (Eg. this or this. The latter may work better with newer versions of libvoikko, but the former is confirmed to work with libvoikko 3.8.)

The morphological dictionary must be unzipped to ~/.voikko/.

Usage

To open an interactive prompt:

python3 tampio.py

To compile a file to JavaScript:

python3 tampio.py file.itp

To print Markdown code that contains the syntax highlighting data of the file:

python3 tampio.py -s markdown-lists file.itp

To print a HTML page that contains both JavaScript and the syntax highlighted code:

python3 tampio.py -i -p file.itp

Introduction

Tampio is an object-oriented language that compiles to JavaScript. Its syntax is directly inspired by the Finnish language and is therefore based on inflecting words.

A Tampio file is a list of definitions, each which defines either a class, a function, a method, a comparison operator or a global variable. For example, here is a simple program that calculates the factorial of a given number.

Pienen luvun kertoma on
    riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi,
    joko yksi
    tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla.

Luvun edeltäjä on se vähennettynä yhdellä.

Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla.

Kun nykyinen sivu avautuu,
    pieneen muuttujaan luetaan luku
    ja nykyinen sivu näyttää pienen muuttujan arvon kertoman.

It contains two functions definitions, one variable definition and one method definition. Let's iterate these line by line.

Pienen luvun kertoma on

This is the signature of the kertoma function, which has one parameter pieni luku. As you can see, the name of the parameter comes before the name of the function and is in the genitive case. The last word, on, is a keyword that separates the signature of the function and its body.

riippuen siitä, onko se pienempi tai yhtä suuri kuin yksi,

This is a ternary expression. It tests if se is less than or equal to (pienempi tai yhtä suuri kuin) one (yksi). se is like this in JavaScript and always means the first parameter (here pieni luku).

joko yksi

If the condition is true, the function returns one, (yksi). joko is a keyword that comes after the condition of riippuen siitä expression.

tai pieni luku kerrottuna pienen luvun edeltäjän kertomalla.

If the condition is false (pieni luku is greater than one), the function returns the value of this expression. It is a product (kerrottuna is the multiplication operation) of pieni luku and pienen luvun edeltäjän kertoma. The right operand of kerrottuna consists of two function calls (which are similar to the signature of the function). First, the predecessor (edeltäjä) of pieni luku is calculated, and then its factorial (kertoma). The arguments of functions are in the genitive case.

Luvun edeltäjä on se vähennettynä yhdellä.

This is a helper function that calculates the predecessor of a number. It simply consists of a vähennettynä operator with operands se (the parameter) and yksi (one).

Olkoon pieni muuttuja uusi muuttuja, jonka arvo on nolla.

Olkoon is a keyword that is used to define global variables. The name of the variable is pieni muuttuja and its value is a new object. The object is created using the uusi keyword and its type is the muuttuja class. jonka keyword is used to set the initial values of the fields of the object. In this case, the arvo field is initialized to nolla (zero).

Kun nykyinen sivu avautuu,

This line declares a new method for the sivu class. (sivu is an alias to the HTMLDocument JavaScript class.) It begins with the Kun keyword. The name of the method is avautuu and the name of the "self" object is nykyinen sivu. (As in Python, the "self" object must be named in the signature of a method.)

pieneen muuttujaan luetaan luku

Here we call the luetaan luku method of pieni muuttuja. The method will prompt a number from the used and store it to the arvo field of pieni muuttuja. pieni muuttuja is in the illative case, because the luetaan luku method requires that case.

ja nykyinen sivu näyttää pienen muuttujan arvon kertoman.

ja keyword is used to specify that this is the last statement in the body of the method. It is another method call, calling the näyttää method of nykyinen sivu. (An alias to HTMLDocument.write.) The argument of the method is a function call and the argument of kertoma is pienen muuttujan arvo (note the genitive case of both arguments). The field access syntax is identical to the function call syntax.

Lists

List syntax is used always when there is a block containing multiple items. The block can be a body of a class, function, if statement or an array.

In many programming languages blocks are created with keywords or symbols that mark the beginning and the end of the block, for example begin/end or {/}. In Tampio, as in natural languages, the block (called a list) is instead defined by using special separators that mark either continuation or ending of the list.

After each item in the list except the last, there must be a separator token. A comma (,) is used when the list continues after the following item, and ja is used when the list ends after the following item.

[first item], [second item], ..., [second-last item] ja [last item]

There is a special syntax that must be used when there is only one item in the list:

[only item] eikä muuta

However, if the current definition would end immediately after the list (ie. there is a period), it is allowed to leave eikä muuta out.

Classes

As Tampio is an object-oriented language, classes are a crucial feature. Each class is defined using a set of fields and number of methods. The fields must be defined together with the class, but methods can be added afterwards.

A class declaration consists of the name of the class in the adessive case and the on keyword.

[name/adessive] on [field list/nominative].

For example:

Vektorilla on komponentit.

This very simple class, vektori, has one field: komponentit. As the name of the field is plural, it is an array.

There is a special syntax that is used to declare a subclass:

[name/nominative] on [super type/nominative], jolla on [field list/nominative].

Fields

Each field is simply either a singular or plural noun. Plural nouns are arrays, singular nouns objects.

A field can have a default value that can be set using one of the following alternative syntaxes:

[field name/nominative], joka on [predicative/nominative],
[field name/nominative], joka on aluksi [predicative/nominative],
[field name/nominative], joka on alussa [predicative/nominative],
[field name/nominative], joka on yleensä [predicative/nominative],
[field name/nominative] [[predicative/nominative]]
[field name/nominative] [aluksi [predicative/nominative]]
[field name/nominative] [alussa [predicative/nominative]]
[field name/nominative] [yleensä [predicative/nominative]]

Please note that some syntaxes contain the literal [] characters.

Functions

In Tampio, a function is always defined for one class and is polymorphic to that class. This means that it is possible to define the same function differently for multiple classes.

A function normally has one parameter and one expression that is the return value. Certain essive functions can have two parameters.

[parameter/genitive] [function name] on [predicative/nominative].
[parameter/nominative] [function name/essive] on [predicative/nominative]
[parameter/nominative] [function name/past passive participle essive] [parameter] on [predicative/nominative]

The name of the parameter must have two words: an adjective and the name of the class. For example, to define a function called dimensio for the vektori class, we must use parameter name that ends in vektori:

Lyhyen vektorin dimensio on lyhyen vektorin komponenttien määrä.

This function will return the dimension of a vector, that is, the number of its components. The name of the function is dimensio and its parameter is lyhyt vektori. määrä is a function that return the size of a list.

Here's another function that return the "tail" of a vector:

Lyhyen vektorin häntä on uusi vektori, jonka komponentit ovat lyhyen vektorin komponentit toisesta alkaen.

Again, its parameter is lyhyt vektori. The function returns a new vector (using the uusi keyword), and its components are formed using the slice syntax.

It is possible to not name the parameter, in which case only the class name appears in the signature. In the body, the word se can be used to refer to the unnamed parameter.

Vektorin dimensio on sen komponenttien määrä.

If the function name is in essive case and is a past passive participle (ie. ending with -ttuna/-ttynä), i

View on GitHub
GitHub Stars245
CategoryDevelopment
Updated2mo ago
Forks5

Languages

Python

Security Score

100/100

Audited on Jan 23, 2026

No findings