Poki Nanpa: A Toki Pona programming language

Development blog for Jack Mullin's graduation project.

kepeken e nasin la; How to call a function

| 0 comments

Unsurprisingly, the most important part of a functional language is defining and calling functions.

The first way of calling functions in Poki Nanpa came about as a natural result of considering how numbers are written in Toki Pona. First, a word like wan should act like a parameterless function returning the value 1. But also, it should act as a post-fix function that acts on the number preceding it, such that tu wan becomes 3. I have set out this way of calling functions in the specification for Poki Nanpa, which I introduced a few days ago.

The second, more complex way of calling functions is still a work in progress, complicated by the aesthetic aim not to include any punctuation in Poki Nanpa’s syntax. In Toki Pona grammar, there are various words that can be used to separate a verb (function) from an object (parameter). The most common is the particle e, but there are also prepositions like tawa (sort of like “to”) and tan (sort of like “from”).

Here’s an example: o jo e ilo e lipu tawa soweli means “give the pencil and homework to the dog.” Notice how each object in the sentence is preceded by the e particle, except for the final one which uses the tawa preposition. This is one solution to the problem of nested functions in a language without brackets; mandate that the user must use e before each parameter and then tawa or tan before the final parameter, depending on whichever makes the most contextual sense for the function in question. “Add x to y” might use tawa, while “Subtract x from y” might use tan. Toki Pona has other prepositions too.

The other solution is to disallow functions from having more than one definition, which was my first idea and that’s what’s in the specification right now, but I feel like this is not a very fun way to have to write a functional program.

tl;dr there are three ways to call a function:

  • the parameterless way: function
  • the postfix way: x function
  • the prefix way: function e x e y e... tawa/tan z

Technical details will be in the specification!

Leave a Reply

Required fields are marked *.