MATL
MATLAB with the names taken away. Every function is one or two characters, and the data sits on a stack.
2015 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 9 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
MATL keeps as close to MATLAB and Octave as it can, but writes programs in reverse Polish notation. A program is compiled to Octave code, so : is MATLAB's colon, s is sum and D is disp. Arrays are the natural data, and most functions work on every element at once.
Read the story
When a function finds too few values on the stack, it reads the missing ones from the input. At the end the stack is displayed, one value per line.
The machine
One stack of arrays. Every value is a row of numbers, characters or logicals.
| Code | Does |
|---|---|
5 'text' [1 2 3] 1:5 | Push a number, a string, a row, a range |
+ - * / ^ \ | Element-wise arithmetic, \ is mod |
= < > ~ | Compare, not |
: | The range 1 to n |
s p n | Sum, product, number of elements |
q Q E | Minus 1, plus 1, times 2 |
t w x y b | Duplicate, swap, delete, copy the one below, rotate three |
i j D | Read a value, read a line of text, display |
" ` ? } ] | For each, do while, if, else, end | |
@ | The loop value |
Numbers display with %.15g and rows with one space between elements.
Example
10: is the range 1 to 10 and s adds it.
10: is the range 1 to 10 and s adds it. The last program is from esolangs.org. It pushes 1 twice, reads n, and runs yy+ n minus 2 times, each time copying the two numbers below the top and adding them. What is left on the stack is the first n Fibonacci numbers, each displayed on its own line.
This implementation is a subset, after the compiler in the lmendo/MATL repository, which TIO runs on Octave. It has scalars and rows, the functions in the table and a few more, and the loops. Matrices, cell arrays, complex numbers, the clipboards and the many two-character functions stop the run with the reason.
Patterns it teaches
- Code golf: a full numeric language behind single characters.
- Stack machines: input is taken when the stack runs short.
Try this
- Print the squares of 1 to 10.
- Read a number and print whether it is even.
- Hard: print the factorial of every number from 1 to 10.
Further
See also
Golfing languages
Stack-based
Write your own in Run Convert a program from MATL
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: matl.
Command line
shib run matl -e '+' --input '3
4'shib manual matlSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/matl.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org