Nim is an incredibly fast systems programming language that is expressive, extensible and really fun to use.
echo("hello, world")
2,000+ PRs
2,500+ issues solved
500+ packages
$1500+ monthly contributions
...with a demo.
Search "Vektor 2089"
foo.Foo foo = new foo.Foo(foo.INIT_FOO);
Time for another demo!
const N = 1024 # int
const str = "a simple юникода string\n"
var x, y: float
let ch = '\u1234'
#[ Define and use a type ]#
type
T = ref object
a, b: int
var t0 = T(a: 42, b: 0)
# Control structures
if len(str) > 0:
x = N # no need to explicitly cast
let names: array[2, string] = ["Liam", "Andy"]
var numbers: seq[int] = @[1, 2, 3]
numbers.add(4)
let phoneBook: Table[string, string] = {
"John": "07712345678", "Jeremy": "0281234567", # ...
}.toTable()
type
Day = enum
Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday, Sunday
let weekend: set[Day] = {Saturday, Sunday}
import math
type
Point* = object
x*, y*: float
proc scale*(p: var Point, s: float) =
p.x *= s
p.y *= s
proc abs*(p: Point): float =
return sqrt(p.x*p.x + p.y*p.y)
var x = Point(x: 3, y: 4)
x.scale(5) # equivalent to scale(x, 5)
assert x.x == 15
proc say*(s: string) =
echo("Computer says: ", s)
"No".say()
say("No")
proc say*(s: string) =
echo("Computer says: ", s)
proc say*(s: string, count: int) =
for i in 0 .. <count:
say(s)
"No".say(5) # Output (x5): Computer says: No
proc say*[T](s: T) =
echo("Computer says: ", s)
say(0b01101011) # Output: Computer says: 107
Metaprogramming is the writing of computer programs with the ability to treat programs as their data. It means that a program could be designed to read, generate, analyse and/or transform other programs...
import jester, asyncdispatch, htmlgen
routes:
get "/":
resp h1("Hello world")
runForever()
proc fibonacci(n: int): int =
if n <= 2:
result = 1
else:
result = fibonacci(n - 1) + fibonacci(n - 2)
const fib20 = fibonacci(20)
echo fib20 # output: 6765
40% off: ctwnidevconf
Thank you for listening!