Homepage / Notes / Computer Science / Programming Languages / Nim
Fast general purpose programming language
echo "Hello World!"
Hello World!
echo 1+1
2
var letter = 'a'
echo letter
a
With type declaration:
var lang: string = "Nim"
echo lang
Nim
let
for immutables:
let name: string = "Damien"
echo name
Damien
const
for immutables known at compile-time:
const number: int = 9
echo number
9
Concatenation:
var name = "Damien"
var greeting = "Hello "
echo greeting & name
Hello Damien
echo ['a', 'b', 'c', 'd', 'e']
['a' | 'b' | 'c' | 'd' | 'e'] |
let list = ['a', 'b', 'c', 'd', 'e']
echo list[1]
echo list[^1]
b |
e |
for i in countup(1, 5):
echo i
1 |
2 |
3 |
4 |
5 |
Shorter syntax for countup()
:
for i in 1 .. 5:
echo i
1 |
2 |
3 |
4 |
5 |
if 1 < 2:
echo "Math is right"
Math is right
for letter in "Damien":
echo letter
D |
a |
m |
i |
e |
n |
for index, letter in ['a', 'b', 'c']:
echo index, " ", letter
0 | a |
1 | b |
2 | c |