Home

Awesome

Minipyth

Minipyth is a minimal programming language, inspired by Pyth. Minipyth is intended to be programmed from my phone. As a result, the only characters used in Minipyth are lowercase letters. Additionally, Minipyth is a golfy language: Each character is an independent atom of the language. Ideally, anything can be programmed using a short program.

To run a Minipyth program, you can simply run:

cargo run <program> <input>

For higher performance, run

cargo run --release -- <program> <input>

You'll need rust installed, here's the instructions to do so: https://www.rust-lang.org/learn/get-started

Input is optional, defaults to 0.

Two potentially useful flags are --debug, which prints the parse tree, and --pretty, which pretty-prints the output.

About Minipyth

Minipyth is a highly minimalistic language, and intentionally lacks many features that are taken for granted in other languages. Minipyth lacks:

Now that we know what Minipyth lacks, let's talk about its features.

High-level semantics

There are three types of characters in the language:

Basic functions

A basic function takes 1 argument and returns 1 output. Functions are applied to the input by default, in order from right to left. For instance, consider the program

hs

s is the sum function, while h functions as the successor function in this context. By default, the functions are applied to the input on STDIN. Suppose that STDIN consists of two numbers, newline seaparated:

4
5

These arguments are internally converted to a list:

[4, 5]

The program hs sums the list, and increments the result, returning 10.

Higher-order functions

A higher-order function takes one or more functions as input, and returns a function, which is then applied as usual. By default, the input basic function is the following character, or the basic function returned by the following character.

For instance, consider the program

mh

m is the map higher-order function. It creates the function which maps its input function over a list.

Suppose that the input is the list [4, 5]. The program mh returns [5, 6].

Binding character

A binding character runs before the characters listed above, at parse time. Binding characters look back through the program, find a certain string of functions, and package them into one function, for use in higher-order functions.

For instance, consider the program

mhhz

z is the bind-1 binder. It packages hh into a single function. Therefore, this program increases each input by 2. If the input is the list [4, 5], this program returns [6, 7].

Object types

An object can be any of the following types:

Sometimes, functions need to interpret objects as truthy or falsy. The falsy objects are 0, [], and all errors. All other objects are falsy.

Sometimes, functions need to output a truth value. 1 represents true, 0 represents false.

Language reference

Updated: 2021-12-23

charsmnemonicTypeFunction
aall-pairsbasicGiven [x, [a, b, c, ...]], create [[x, a], [x, b], ...]. Given [[a, b, c, ...], int], create [[a, int], [b, int], ...]. Given list of ints l, same as [l, l]. Given int i, [[i, 0], [i, 1], ..., [i, i-1]].
bbifurcatehigher-2Given two funcs, apply each to input, make list.
ccombinebasicTransponse list. Int: permutations.
ddeduplicatebasicRemove all repeated elements. Int: partitions.
eequalbasicGiven a list, check if all elements identical. Int: subset permutations.
ffilterhigherto_list: filter func over list
hheadbasicInt: x+1. List: first element
iinversehigherInvert. Defined case-by-case.
jdeep-indexhigherGiven list and func, apply func to list length, then deep index the result into the input. Int unimplemented.
kconstantbasic0
llengthbasicList: length. Int: To binary.
mmaphigherto_list: map func over list.
nnegatebasicInt: -x. List: reverse
oorderhigherto_list: order by key given by func
pproductbasicInt: prime-factorization. List(Int): product. List(List): Cartesian product
qquotebinderPair with next q, combine everything within into one function. If odd number, first q pairs with earliest eligible location in the program.
rrepeathigherApply func a number of times equal to input[0], starting with input[1]. Return all results. If input is length 1 or non-list, use input as both times and start.
ssumbasicInt: logical negation. List(Int): integer sum. List(List): concatenate
ttailbasicInt: x-1. List: All but first element
uupdatehigherGiven [i, list] and func, update list[i] using func.
vreverse-lookuphigherFind first input to func that produces arg as output.
wwhilehigher-2Apply second func until first func returns falsy or error. Return starting value and all results.
xfixed-pointhigherApply until result repeats or errors. Return all results.
ypower-setbasicInt: 2^x. List: power-set
zbind-eagerbinderCombine everything backwards until unbound higher-order function into one function.

Glossary: