minigolf
minigolf is a tiny stack-based language inspired by Vyxal's corpus. Programs can be quite long compared to modern golfing languages due to its extremely limited set of builtins, but they tend to be shorter compared to practical languages. Besides constants and characters that transpile to minigolf, it currently has 8 commands (actually 12 due to operator overloading):
Command | Overload | Description |
---|---|---|
, ... ; |
(int / float) | map ... over [1..int(n)]
|
(list) | map ... over TOS
| |
: |
(any) | Duplicate TOS |
* |
(int/list, int) | Multiply. (Vectorizes) |
(list) | Flatten the list on TOS. | |
+ |
(int/list, int) | Add. (Vectorizes) |
(list) | Sum the TOS. (Vectorizes at depth 1) | |
i |
Push next (cyclic) input (or -1 if input is empty)
| |
n |
Push current item in map (or 2 if outside of loop)
| |
s |
(any, any) | Swap the top two stack items. |
= |
(list/int, int) | Equality. (Vectorizes) |
(list, list) | Zip two lists together. |
Additionally, the following characters transpile to their equivalent minigolf substring:
Character | Replacement |
---|---|
_ |
0;++ (useful for foreach loops)
|
# |
,1;+ (length of a list)
|
o |
:#s,ns_,; (reverse a list)
|
The input for the program is taken from STDIN, split by newlines, and each item is evaluated as Python. Strings are converted to lists of codepints. This produces an input list for the program.
The entire stack is implicitly outputted after the program. If the -c
flag is on, then each stack item is implicitly chr
'd. If TOS is an array, then the inner lists are flattened, then the inner lists mapped with chr
then joined with ""
, then the outer lists joined with "\n"
, and finally the resulting list is outputted.
It is important to note that unlike other stack-based langauges such as 05AB1E or Factor, the map builtin does not implicitly push the current iterated item onto the stack. An explicit n
is required to do that. (This makes the map builtin a bit more flexible.)
The map loop pops TOS after each iteration, and pushes a list of each popped item after the loop.
Additional constants and flags in minigolf can be found by reading the source code.
Example programs
Sort the input list
Here is a program I wrote on CGCC that sorts the input list via insertion sort.
0,;i,:#1,;ns,s,n2,;:,n_T*+0s,,_1_,o_,n__n1+,;o__
Deadfish interpreter
0i,nWT*+1,;,nB=,:_n0=,T+_n5=,1+_nF=,:*__::V=sT=+,0*__,_
Primalty checking
iT+:,:ns,:n*;s,_;*i=+0=s0=0=*
Factorial of the input
1i,n*_