# Stuck

Stuck is a stack-based programming language written in Python by Shebang of the Code Golf SE site. It was inspired by CJam/GolfScript.

## Overview

Stuck comes with 3 plugins: Stuck Base, Stuck Math and Stuck SciPy. If you want to use the latter, you must have numpy and scipy installed. If you do not need it, you may remove the `stuck_scipy.py` file from the plugins folder. You can easily create your own plugins as well, look at the format of the existing ones to see how to design your own.

Stuck supports inline parsing of integers, floats and strings. If you want to use a list or tuple (hardcoded), you must first put it in a string (surround with `"`s) and then use `~` (`eval` in Python). The only time spaces are needed is between two different number literals, i.e. `34*` would fail to execute, as it would be interpreted as `(empty) * 34`, not `3 * 4`.

The stack at the end of execution is printed implicitly, unless an explicit call to the print function was made somewhere within the program.

Basic

Command Function Example
`g` Stores the top value of the stack in the variable register. `1 2 3 g` puts `3` on the variable register and `1 2` are on the stack.
`G` Pops an index off the stack, and gets the item in the variable register. `1 2 0 G` with variable register `3` will leave `1 2 3` on the stack.
`:` For-each looping construct, uses string on top of stack as Stuck code. `3 R "R" :` produces* `[[1], [1, 2], [1, 2, 3]]`
`'` Triggers char mode, next char is interpreted as length-1 string. `4 'a` produces `4 "a"`.

* - `R` is the range function, mentioned below.

Stuck Math

Command Function Example
`+` Performs addition. `3 4 +` becomes `7`.
`-` Performs subtraction. `2 3 -` becomes `-1`.
`*` Performs multiplication. `6 6 *` becomes `36`.
`/` Performs division. `3 4 /` becomes `0.75`.
`%` Performs modulus. `5 3 %` becomes `2`.
`^` Performs power. `2 5 ^` becomes `32`.
`#` Performs square. `4 #` becomes `16`.
`\` Performs square root. `2 \` becomes `1.41421356237`.
`>` Performs greater-than comparison. `3 2 >` becomes `True`.
`<` Performs less-than comparison. `4 3 <` becomes `False`.
`=` Performs equality comparison. `9 9 =` becomes `True`.
`{` Performs left bit-shift. `2 4 {` becomes `32`.
`}` Performs right bit-shift. `9 1 }` becomes `4`.
``` Performs distance calculation. `0 0 4 3 `` becomes `5`.
`Σ` Performs summation. `9 9 9 9 Σ` becomes `36`.
`Π` Performs reduction by multiplication. `9 9 9 9 Π` becomes `6561`.
`!` Performs factorial calculation. `9 !` becomes `362880`.
`|` Performs absolute value calculation. `-4 |` becomes `4`.
`(` Performs ceiling. `6.2 (` becomes `7`.
`)` Performs floor. `5.5 )` becomes `5`.
`P` Performs permutation calculation. `15 4 P` becomes `32760`.
`M` Performs combination calculation. `15 4 M` becomes `1365`.
`X` Performs Cartesian product. `[1,2] [3,4] X` becomes `[(1,3),(1,4),(2,3),(2,4)]`.*
`v` Performs primality calculation. `661 v` becomes `True`.
`π` Pushes pi onto the stack. `π` becomes `3.14159265359`.
`e` Pushes e onto the stack. `e` becomes `2.71828182846`.

* - Note that the actual program would need to look like `"[1,2]" ~ "[3,4]" ~ X` to work.

Stuck Base

Command Function Example
`i` Input via `input()`. n/a
`s` Input via `raw_input()`. n/a
`t` Input via `raw_input()`, split by delimeter* and evaluated. n/a
`y` Pop the last element. `2 3 1 4 y` becomes `2 3 1`.
`,` Pop all but the last element. `2 3 1 4 ,` becomes `4`.
`;` Swap the top two elements. `4 4 5 ;` becomes `4 5 4`.
`@` Rotate the elements right one place. `1 2 3 @` becomes `3 1 2`.
`u` Rotate the elements left one place. `3 1 2 u` becomes `1 2 3`.
`_` Duplicate the top element. `1 2 3 _` becomes `1 2 3 3`.
`~` Evaluates the top element with `eval()`. `"[1,2,3]" ~` becomes `[1,2,3]`.
`z` Zips the top two lists together. `[1,2,3] [4,5,6] z` becomes `[(1, 4), (2, 5), (3, 6)]`.
`Z` Zips the top two lists by longest. `[1,2] [4,5,6] Z` becomes `[(1, 4), (2, 5), (None, 6)]`.
`r` Pops top value `n`, creates range `[0,n)`. `3 r` becomes `[0,1,2]`.
`R` Pops top value `n`, creates range `[1,n]`. `3 R` becomes `[1,2,3]`.
`]` Flattens the top list element by one dimension. `[[1,2,3],[4,5,6]] ]` becomes `[1,2,3] [4,5,6]`.
`[` Wraps all elements on the stack in a list. `3 4 5 ]` becomes `[3,4,5]`.
`m` Maps a list by a Python lambda expression. `[4,5,6] "x:x+2" m` becomes `[6,7,8]`.
`f` Filters a list by a Python lambda expression. `[4,5,6] "x:x>4" f` becomes `[5,6]`.
`l` Gets the length of the top string/list. `"This?" l` becomes `5`.
`j` Joins top list/stack if not list by delimiter. `[3,4,5] "-" j` becomes `"3-4-5"`.
`C` Compresses a string via zlib. `"Hello" C` becomes `"[cmpressed]"`.
`D` Decompresses a string via zlib. `"[cmpressed]"` becomes `"Hello"`.
`b` If a string, encode to Base64. Otherwise, base conversion. `10 2 b` becomes `1010`, `"Hello" b` becomes `"SGVsbG8="`.
`B` Decode a Base64 string. `"SGVsbG8=" B` becomes `"Hello"`.
`Q` Replace a sequence in string with new sequence. `"Hello" "l" "yes" Q` becomes `"Heyesyeso"`.
`o` Performs run-length encoding on the top element. `"aaabbc" o` becomes `[[3,'a'],[2,'b'],[1,'c']]`.
`O` Undoes run-length encoding using the top element. `[[3,'a'],[2,'b'],[1,'c']] O` becomes `"aaabbc"`.
`\$` Sorts the top element. `[3,1,5,4,2] \$` becomes `[1,2,3,4,5]`.
`c` Convert a string or char list to list of ASCII values. `"abc" c` becomes `[97,98,99]`.
`d` Convert a list of ASCII values to a string. `[97,98,99] d` becomes `"abc"`.
`T` Transposes the top element. `[[1,2,3],[4,5,6]] T` becomes `[[1,4],[2,5],[3,6]]`.
`&` Gets an index off the stack, returns element in list. `[1,2,3] 2 &` becomes `3`.
`I` Gets item off the stack, returns its index in list. `["a","b","c"] 'c I` becomes `2`.
`U` Removes all falsy elements from list. `[1,2,0,"a","",[1,2],[],True,False]` becomes `[1,2,"a",[1,2],True]`.

* - The delimiter in this case is the | character.

Stuck SciPy

Command Function Example
`İ` Calculate the inverse of a matrix on the top of the stack. `[[1,2],[3,4]] İ` becomes `[[-2,1],[1.5,-0.5]]`.*
`Ɗ` Calculate the determinant of a matrix on the top of the stack. `[[1,2],[3,4]] Ɗ` becomes `-2.0`.

* - Note that there may be rounding errors in this calculation (-1.9999999999999996 instead of -2).

## Examples

### Hello, World!

`"Hello, World!"`

Alternatively, a zero-byte solution will also print this.

### First 100 primes

`100R_"v":z"x:x[1]"f"0&":`

or

`100R"_v;0?":"x:x"f`

or

`100R"_v;0?":U`

### First 5 tetrahedral numbers

`5R"__1+;2+Π6/p":`