# Script Shell Lang
```Makefile
# IMPORT
imp test
imp test as t
imp { test }
imp { test as t }
imp {
test as t,
test2,
test3
}
# These two imports can bring to "the function is already defined" error
inc f1 of test
inc { f1, f2 } of test
# Type
function
int
float
string
list
tuple
record
optional (Just(1) or None)
# Var
x = 0
y = 1.1
# Function
add = (a, b) -> a + b
multiply = (x, y) -> x * y
applyFunction = (func v1 v2) -> func v1 v2
# Function Call
res = add 1 2
res2 = applyFuction add 1 2
# Conditional expression
isEven = (n) -> if n % 2 == 0 then "Even" else "Odd"
# Pattern Matching
describe = (x) -> match x {
0 -> "Zero",
1 -> "One",
_ -> "Many"
}
# Recursion
fact = (n) -> if n == 0 then 1 else n * fact (n - 1)
# Collections
list = [1, 2, 3, 4, 5] # mutable with cons and concat
head = hd list # 1
tail = tl list # [2, 3, 4, 5]
head, tail = list
first, second, tail = list
new_list = 0 : list # [0, 1, 2, 3, 4, 5] cons operator
new_list = list ++ [6, 7, 8, 9]
match_list = (l) -> match l {
[] -> 0,
[single] -> 0,
[first, second] -> 0,
first : second : tail -> 0,
head : tail -> 0
}
increment = (x) -> x + 1
incrementedNumbers = map increment, [1, 2, 3]
isPositive = (x) -> x > 0
positiveNumbers = filter isPositive [-2, -1, 0, 1, 2]
sum = (acc, x) -> acc + x
total = fold sum 0 [1, 2, 3, 4, 5]
tuple = (1, "a", 2, "b") # immutable
first = tuple.0
second = tuple.1
(one, a, two, b) = tuple
type Person = {
name String,
age Int
}
record = { name="Fede", age=24 }
name = record.name
{ name, age } = record
# Currying (partial application)
add = (a) -> (b) -> a + b
addFive = add(5)
result = addFive(10) // result is 15
# Type annotation
add: (Int, Int) -> Int = (a, b) -> a + b
greet: (String) -> String = (name) -> "Hello, " + name
x: int = 5
```
# Sider
## Redis clones
- [redis-rs](https://github.com/redis-rs/redis-rs) redis clone in rust
## Current used in redis
- [jemalloc](https://github.com/jemalloc) allocator
- [jmalloc paper](https://people.freebsd.org/~jasone/jemalloc/bsdcan2006/jemalloc.pdf) A Scalable Concurrent malloc(3) Implementation for FreeBSD
- [redis-tools](https://github.com/antirez/redis-tools) repository of `antirez`
- [Memory allocation in redis](https://stackoverflow.com/questions/12845020/memory-allocation-in-redis) stack overflow
## In-memory compression algorithms
- [lz4](https://github.com/lz4/lz4) repository -- It also contains the comparison with other in-memory compression algorithms
- [snappy](https://github.com/google/snappy) repository by Google
## Crates.io
- [libz-sys](https://crates.io/crates/libz-sys) official bidings
- [zlib-rs](https://crates.io/crates/zlib-rs) (new implementation?)
- [zlib](https://crates.io/crates/zlib) (partial implementation)
## Other links
### Allocators
- [memory-allocation-strategies](https://www.gingerbill.org/article/2019/02/01/memory-allocation-strategies-001/) blog serie of `gingerbill`
- [Custom allocator in rust](https://nical.github.io/posts/rust-custom-allocators.html) blog post
### Redis
- Redis blog post -- [Using redis allocator in rust](https://redis.io/blog/using-the-redis-allocator-in-rust/)
- Blog post -- [Compressing large data sets in Redis with Zlib – Ruby test case](https://mensfeld.pl/2013/04/compressing-large-data-sets-in-redis-with-gzip-ruby-test-case/)
- Google discussion -- [Compressing strings before inserting to redis](https://groups.google.com/g/redis-db/c/tI6uwr_nJjE)
- [Build you own redis](https://app.codecrafters.io/courses/redis/overview)