🍗 Wiki

Nim

Nim

1. Try it online

You can try Nim programming online: Nim playground

2. Installation

In Nix, You can install Nim package instantly in your system by

nix-shell -p nim

and install it by adding pkgs.nim to your configuration.nix or home manager.

3. Writing and running Nim code instantly

Let’s write a simple Nim code, it consists of simple for-in loop.

# example.nim
import std/strformat

for i in 1 .. 5:
  echo(fmt"Number: {i}")

Then compile code with nim command.

# Basically compiled into native executable
nim compile example.nim
# or javascript
nim compile --backend=js example.nim

Then run it.

$ ./example
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
$ # or with nodejs
$ node example.js
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5