Why Invest in a Niche Tech?
A TCP lightning chat
What is a Niche Tech?
let 💬 = "Hi Crafters!"
for i in 0 ..< 💬.len:
echo 💬[0 .. i]
H Hi Hi Hi C Hi Cr Hi Cra Hi Craf Hi Craft Hi Crafte Hi Crafter Hi Crafters Hi Crafters!
Nim is a
statically typed
compiled
programming language
for everything
const N = 3
type Matrix = array[N, array[N, int]]
let
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
B = [[1, 1, 1], [0, 1, 1], [0, 0, 1]]
func `*`(a, b: Matrix): Matrix =
for i in 0 ..< N:
for j in 0 ..< N:
for k in 0 ..< N:
result[i][j] += a[i][k]*b[k][j]
echo A*B
[[1, 3, 6], [4, 9, 15], [7, 15, 24]]
type
Grid = array[3, array[3, Cell]]
Cell = enum X, O
func initGrid: Grid =
[[X,O,X],[O,X,O],[X,O,X]]
proc show(g: Grid) =
for row in g:
echo row
proc update(g: var Grid) =
for i in g.low .. g.high:
for j in g[i].low .. g[i].high:
g[i][j] = if g[i][j] == X: O else: X
⠀
var g = initGrid()
show g # command
[X, O, X] [O, X, O] [X, O, X]
g.update # method
g.show
[O, X, O] [X, O, X] [O, X, O]
update(g) # function
show(g)
[X, O, X] [O, X, O] [X, O, X]
fibonacci.nim
import nimpy
func fib*(n: int): int {. exportpy .} =
if n < 2: 1 else: fib(n - 1) + fib(n - 2)
main.py
import nimporter
from fibonacci import fib
print(fib(10))
python3 main.py
89
hello.nim
import nimib
nbInit
nbText: "A sample program with _Nimib_"
nbCode:
echo "hello RC!"
nbSave
nim r hello
Essay by Bret Victor (2011)
"Explorable Explanations is my umbrella project for ideas that enable and encourage truly active reading. The goal is to change people's relationship with text. People currently think of text as information to be consumed. I want text to be used as an environment to think in."See more at explorabl.es
Goal: make in NimibLand better tools for explorable explanations.
hi.py
import nimib as nb
nb.init()
nb.text("Welcome to `nimib.py`!")
message = "hello"
with nb.code():
print(message)
nb.save()
python hi.py
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!```
1. Copying bad design is not good design.
2. If the compiler cannot reason about the code,
neither can the programmer.
3. Don’t get in the programmer’s way.
4. Move work to compile-time:
Programs are run more often than they are compiled.
5. Customizable memory management.
6. Concise code is not in conflict with readability,
it enables readability.
7. (Leverage meta programming to keep the language small.)
8. Optimization is specialization:
When you need more speed, write custom code.
9. There should be one and only one programming language
for everything.
That language is Nim.