owned this note
owned this note
Published
Linked with GitHub
# Charles Montgomery Quince (CMQ) Specs
## Types:
- Integers (`1`, `12345`)
- Floats (`5.223`, `.3`)
- Complex (`i`, `1+2i`)
- Different bases (`10b2 = 2`)
- Collections
- Sets (`{1 2 3}`) - unordered, can only contain one of each value
- Lists (`[1 2 3]`) - ordered, can contain multiple counts of any value
- Sequences (`((n) -> {n)`) - ordered, infinite, defined by functions
- Above sequence = `(1 2 3 4...)` (natural numbers)
- Strings (`"Hello, World!"`, `'What?'`)
## Comments:
// This is a comment
## Builtin functions:
- `red(coll, function)`: reduce - reduces a collection into one number, through a function - works left to right
red([1 2 3] (a b) -> {a + b) // ->
// red([(1 + 2) 3] (a b) -> {a + b) =
// red([3 3] (a b) -> {a + b) = 6
- `conv(coll, function)`: convert - converts all elements of a collection to another number through a function
conv([1 2 3 4 5]
(n) -> {n in [0 1]: 1
{#(n - 1) + #(n - 2)
)
// [1 2 3 5 8]
- `range(start, end)`: generates a list from starting number to ending number (inclusive for start, exclusive for end), `start` is defaulted to 0
range(5) // [0 1 2 3 4]
- `ascii(list)`: converts all items of list to ASCII equivalent (mod 128), and then joins them as string
ascii([72 105 46]) // "Hi."
- `out(any)`: Outputs to STDOUT anythin
- `input(str)`: Gets input from STDIN, with `str` as prompt
## Other Builtins:
- get from ordered collections & strings: `[]` (0-indexed)
- get one element: `[n]` for n-th element
[1 2 3][0] // 1
- get multiple elements: `[start to end]`, `to` is a keyword, start is inclusive, end is exclusive - start defaults to 0
((n) -> {n)[0 to 5] // [0 1 2 3 4]
((n) -> {2 * n)[to 5] // [0 2 4 6 8]
- `in` keyword: checks if element is in list/set (cannot be used for sequences): `elem in coll`, returns a boolean
1 in [0 1] // true
- `true`, `false`: boolean values
## Functions:
// Ackermann function
Ack(m n) -> {m = 0: n + 1
{n = 0: #((m - 1) 1)
{#((m - 1) #(m (n - 1)))
// Golfed:
A(m n)->{m=0:n+1;n=0:#((m-1)1);#((m-1)#(m(n-1)))
---
```python
# Python equivalent
def Ackermann(m, n):
if m == 0:
return n + 1
elif n == 0:
return Ackermann(m - 1, 1)
else:
return Ackermann(m - 1, Ackermann(m, n - 1))
```
// Sum of Fibonacci numbers below n
fibSum(n) -> {red(((n) -> {n in [0 1]: 1
{#(n - 1) + #(n - 2))[to n]
(a b) -> {a + b)
// Golfed
S(n)->{red(((n)->{n in[0 1]:1;#(n-1)+#(n-2))[to n](a b)->{a+b)
---
## Variables:
- declared using an equals sign, variable can be of any type
int = 5337
float = .45
set = {1 2 3}
list = [1 4 7]
seq = ((n) -> {n)
string = "Hello, World!"