Skip to content

Instantly share code, notes, and snippets.

proc fib(n: int): int =
if n <= 0: 1
else: fib(n-1) + fib(n-2)
static:
echo fib(3)
@def-
def- / foo.nim
Created September 7, 2017 11:06
import tables, sequtils
let t = {1: "one", 2: "two"}.toTable
let k = toSeq(t.keys())
echo k
@def-
def- / foo.nim
Created September 5, 2017 16:58
import sequtils
proc `[]`[T](s: openarray[T], x: int, y: Slice[int]): seq[T] =
result = newSeq[T]()
for i in countup(x, y.b, y.a - x):
result.add(s[i])
let x = toSeq(0..20)
echo x[3,5..13]
/* Generated by Nim Compiler v0.10.3 */
/* (c) 2015 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, amd64, gcc */
/* Command for C compiler:
gcc -c -w -O3 -fno-strict-aliasing -I/media/nim/lib -o /home/deen/nimcache/asd.o /home/deen/nimcache/asd.c */
#define NIM_INTBITS 64
#include "nimbase.h"
#include <stdio.h>
import times
proc fib(n: int32): int32 =
if n <= 1: n
else: fib(n-1) + fib(n-2)
proc main =
let timeStart = epochTime()
var result: int32 = 0
import os, times, future, math, sequtils, strutils
proc get_primes7(n: int32): seq[int32] =
if n < 2:
return @[]
result = @[2'i32]
if n == 2:
return
import threadpool
# Array needs explicit size to work, probably related to issue #2287
const a: array[0..5, int] = [1,2,3,4,5,6]
proc f(n) = echo "Hello ", n
proc main =
parallel:
for i in countup(0, a.high-1, 2):
@def-
def- / foo.nim
Created February 24, 2017 21:19
import base64, strutils, sha256, os
import libsodium.sodium
import libsodium.sodium_sizes
const
usage = """
DDCATool - Tool to establish and manage a DDNet CA
usage:
ddcatool <command>
Commands:
template inReverse(x, y) =
y
x
inReverse do:
echo "Hello World"
do:
echo "Goodbye World"
@def-
def- / at.nim
Last active June 19, 2016 18:02 — forked from Varriount/at.nim
import asyncdispatch
template doAsync(name: expr; body: untyped): untyped {.immediate.} =
proc name() {.async.} =
body
asyncCheck(name())
doAsync(namething):
echo "hello"