Moki

			Code				Input
| | Len = Suppress
Reading Char 0
Stack: [0]
Moki rev 1.6.7

Introduction

Moki is a stack-based programming language. After dissatisfaction with my first language, Mochine, I've since turned to more golfy methods of representation. In this aspect I've made as many functions as string-compatible as possible. Multiplication, and even division work with strings. Instead of erroring out I try and think of alternative uses until the logic simply breaks down and I have to issue an error.

Changelog

1.6.7
Added N, creates an array of the first n natural numbers. Changed minimum stack requirements for a few operations.
1.6.6
Added Z, which filters array using a premade filter, in preparation for my addition of f [filter function].
1.6.5
Added z, which deletes falsey values from array, in preparation for my addition of f [filter function].
1.6.4
Added m, the map function, along with ¡, which applies a function to the last element of an array, À, which rotates the last item to the beginning of the array, and Á, which does the opposite.
1.6.3
Added U. Using ^ with a string or array invokes intersection instead.
1.6.2
Baleeted string exponentiation. Soon, it will be replaced as the INTERSECTION operator.
1.6.1
Any data type can now be the name of a function.
1.6
Define functions and constants using the following syntax:
'quintuple',',5*':
2'quintuple'`
1.5.3
Added MG (gcd) and MQ (quadratic formula).
1.5.2
Added Ć (nCr) and Ṕ (nPr).
1.5.1
Some trig functions. Base n log.
1.5
Found resolutions to many errors.
1.4.4
Improved warning code.
Fixed minor bugs with multiplication and factorial.
1.4.3
I've worked out, as far as I can tell, nearly every kink in the code.
1.4.2
Added random program and error suppression.
Various minor bugfixes.
1.4.1
Added escape character \' \\.
Added stack visualization.
1.4
Arrays:
Added P, a, p.
1.3
Minor bugfixes. Cleaned code.
Added Mx, Tx, I{}, W{}.
1.2.1
Added more errors... :(
The stack now starts with 0 again... :(
1.2
Added A, G, L, M, P, S, V, e, l, m, s, t, γ, and π.
The stack now starts empty.
1.1
Added ~.
Fewer errors
1.0
Initial Release.

Upcoming Features

filter()
the upcoming filter() function will probably take the following form:
[...] 'function' f -> filter('function',[...])

Dictionary

Let Sn = the nth item in the stack (looking down, eg., top of stack = 0).

(Whitespace)
Does nothing.
!
! := S0(λx.x==0 ? 1 : 0)
"
if S0 is a Real → converts S0 from decimal to unicode
if S0 is a String → do nothing
#
Delimits comments.
$
Push next line of input to stack.
%
S1 = S1 mod S0, pop S0
&
& := (S0,S1)(λ(y,x).(x!=0 & y!=0) ? x : 0)
'
Delimits strings.
(
if S0 is a Real → decrement
if S0 is a String → decrement its decimal value, but keep it a string
)
if S0 is a Real → increment
if S0 is a String → increment its decimal value, but keep it a string
*
if S0 is a String, return as if it were S0.charCodeAt(0)
if S1 is a Real → S1 = S0S1
if S1 is a String → concatenate it S0 times
don't forget to pop S0
+
if both are reals, return their sum
else return their concatenation
don't forget to pop S0
,
push 0 onto the stack
-
subtraction - treat characters like their charcodes
.
duplicate top of stack
/
division - treat string divisors as their charcodes, split dividend strings into n parts
0-9
if S0 is a Real → multiply top of stack by 10, add n
if S0 is a String → concatenate
;
pop top of stack
<
push 1 if a<b else push 0
=
push 1 if a=b else push 0
>
push 1 if a>b else push 0
?
a b c -> b if a else c
a b -> b
@
move top of stack to the bottom
A
arithmetic mean of stack
G
geometric mean of stack
I
If top of stack false, skip to next }
L
replace top of stack with push its length
M
mathlibrary prefix
N
creates an array for the first n natural numbers
P
push to array:
[...] # -> [...#] else
# [...] -> [#...] else
# $ -> [#,$]
T
timelibrary prefix
U
array/string union
V
push moki version string to stack
W
W{} = while top of stack is true, loop contents
Z
[array1] [array2] Z -> filters array1 using truthiness of corresponding indices of array2
[
### -> floor(###)
'ABC' -> 'abc'
\
swap top two stack items
]
### -> ceil(###)
'abc' -> 'ABC'
^
exponentiation.
with a string or array as an argument, instead acts as set intersection.
`
X` -> call function X
a
push empty array to stack
e
empty stack -> push e
TOS is number -> TOS*=e
l
# -> ln(#)
m
map:
[array] 'function' -> map(function,array)
p
[...#] -> [...] #
z
filters falsey values from an array
{
begin loops
|
# -> abs(#)
}
end loops
~
# -> -#
'abc' -> 'cba'
¡
maps to last array item:
[array] 'function' -> [array]+[function(array[array.length-1])]
À
rotate last array item to beginning
Á
rotate first array item to end
Ć
A B -> A nCr B
γ
empty stack -> push γ
TOS is number -> TOS*=γ
π
empty stack -> push π
TOS is number -> TOS*=π
A B -> A nPr B
Todo: Add Libraries to Dictionary

Programs

Program Shorter than Output (0 bytes)

Outputs "0".

 

Program Shorter than Positive Output (3 bytes)

My best solution, so far, to this codegolf challenge. Score: 5,040.

7M!

Alternate non-static solution better until August 12, 2066 (at the time of writing, Score = 2,507):

Tw[

nth Triangular Number (7 bytes)

Noice.

$.,2^MS

Output length n*program length (9 bytes)

My best solution to this codegolf challenge (Score: -16).

;'m',9*$*

moki (14 bytes)

Prints "moki" without the use of any characters.

109".)).,4-.((

Hello World (16 bytes)

Prints "Hello, World!".

;'Hello, World!'

Largest Number Printable (Score >107122)

My best solutions, sorted by size, so far, to this codegolf challenge.

1 → 1 | Score: 1

)

Or, alternatively,

L

2 → 1516378243.512 | Score: 189,547,280

Tt

3 → 4763842749.880693 | Score: 176,438,620

Ttπ

4 → 14966053385.882185 | Score: 233,844,584

Ttππ

7 → 16331239353195370 | Score: 47,612,942,720,686

1π,2/Mt

[Worked until 1.6.2] 8 → 9.999...×107124 | Score: 1.953...×107122

':'('~'^

Quadratic Solver (32 bytes)

Solves the quadratic with the given coefficients.

;$.$.~\,2^,4$*@@@@*-,1,2/^+,2/@/

Broken Shift (49 bytes)

Moki solution to this code challenge. Score: 2-13.

;'Dear C''omputer, please stop giving me shift!'[

Polyglots

Prints the name of the language.

Moki/Perl (22 bytes)

#;'Moki'#
print 'Perl'

Moki/Ruby (22 bytes)

#;'Moki'#
print 'Ruby'

Moki/Python (26 bytes)

##;'Moki'#
print('Python')

Moki/Haskell (27 bytes)

--;'Moki'#
putStr "Haskell"

Moki/JavaScript (33 bytes)

1,1//;'Moki'#
alert('JavaScript')

Moki/C (55 bytes)

#include<stdio.h>
int main(){printf("C");}//#;'Moki'