Skip to content

Instantly share code, notes, and snippets.

View flaviut's full-sized avatar

Flaviu Tamas flaviut

View GitHub Profile
@flaviut
flaviut / patch.diff
Last active August 29, 2015 14:04
Allow type constructors
diff --git a/compiler/ast.nim b/compiler/ast.nim
index bdb8d1c..b0d869c 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -847,7 +847,7 @@ type
const
OverloadableSyms* = {skProc, skMethod, skIterator, skClosureIterator,
- skConverter, skModule, skTemplate, skMacro}
+ skConverter, skModule, skTemplate, skMacro, skType}
(0, 1), (1, 5), (2, 8), (3, 6), (4, 3), (5, 7), (6, 2), (7, 4)(0, 1), (1, 6), (2, 8), (3, 3), (4, 7), (5, 4), (6, 2), (7, 5)(0, 1), (1, 7), (2, 4), (3, 6), (4, 8), (5, 2), (6, 5), (7, 3)(0, 1), (1, 7), (2, 5), (3, 8), (4, 2), (5, 4), (6, 6), (7, 3)(0, 2), (1, 4), (2, 6), (3, 8), (4, 3), (5, 1), (6, 7), (7, 5)(0, 2), (1, 5), (2, 7), (3, 1), (4, 3), (5, 8), (6, 6), (7, 4)(0, 2), (1, 5), (2, 7), (3, 4), (4, 1), (5, 8), (6, 6), (7, 3)(0, 51)(0, 2), (1, 7), (2, 3), (3, 6), (4, 8), (5, 5), (6, 1), (7, 4)(0, 51)(0, 49)(0, 3), (1, 5), (2, 8), (3, 4), (4, 1), (5, 7), (6, 2), (7, 6)(0, 49)(0, 4390240), (1, 2), (2, 7), (3, 8236), (4, 4), (5, 4390240), (6, 1), (7, 7), (8, 41), (9, 4), (10, 4390240), (11, 1), (12, 7), (13, 40), (14, 4), (15, 4390240), (16, 2), (17, 7), (18, 8236), (19, 4), (20, 4390240), (21, 1), (22, 7), (23, 41), (24, 4), (25, 4390240), (26, 1), (27, 7), (28, 40), (29, 4), (30, 4390240), (31, 2), (32, 7), (33, 8236), (34, 4), (35, 4390240), (36, 1), (37, 7), (38, 41), (39, 4)(0, 67527080), (1, 0), (2, 1
proc cst*[T1, T2](item: T1, desc: typedesc[T2]): T2 =
T2(item)
proc arange*(n: int, T: typedesc): seq[T] =
result = newSeq[T](n)
for i, val in result:
result[i] = 0.cst(T)
discard arange(10, float)
@flaviut
flaviut / style.nim
Last active August 29, 2015 14:04 — forked from Varriount/style.nim
# Option one
proc procedureWithlotsOfArgumentsAndAReallyLongName(
argOne: string, argTwo: int, argThree: float,
argFour: proc(), argFive: bool): returnType
# Option two
proc procedureWithlotsOfArgumentsAndAReallyLongName(
argOne: string, argTwo: int, argThree: float,
argFour: proc(), argFive: bool): returnType
type
Matrix[W, H] = array[1..W, array[1..H, float]]
let mat1 = [[1, 0],
[0, 1]]
let mat2 = [[0, 1],
[1, 0]]
proc add[W, H](a, b: Matrix[W, H]):
Matrix[W, H] =
import unsigned, math
type
Random* = generic x
next(var x) is uint64
proc next*[T](self: var T, n: int): int =
## Gets a random number in [0, n). This wastes entropy, so it should
## be used with caution in cases where randomness can be exhausted
assert n > 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import unsigned
import strutils
type
BigIntDigits=seq[uint32] #a sequence of digits used for a big integer
BigInt* =object
digits*:BigIntDigits #posetive digits in base maxvalue(uint)+1
neg*:bool #true if negative, false if zero or posetive
@flaviut
flaviut / .gitignore
Created June 28, 2014 03:47
Nimrod gitignore
*
!**/
!*.*
nimcache/
*.o
*.exe
*.so
*.dylib
*.zip
import unsigned
type
TBigInt* = object
d: seq[uint32] ## index 0 is the least significant int32
## index len-1 is the most significant int32
sign: TSign
TSign* {.pure.} = enum Negative, Zero, Positive
proc addCarry(a, b: uint32): tuple[res: uint32, carry: uint32] =