This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pub*[T] = object | |
subs: seq[proc(e: T)] | |
proc init*[T](pub: var Pub[T]) = | |
if pub.subs == nil: | |
pub.subs = @[] | |
proc `()`*[T](pub: Pub, e: T) = | |
if pub.subs != nil: | |
for sub in pub.subs: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros | |
proc makeRef(obj: PNimrodNode): PNimrodNode {.compiletime.} = | |
var typeName: string | |
var assignments = newSeq[PNimrodNode]() | |
for i in obj.children: | |
if i.kind == nnkIdent: | |
typeName = $i | |
elif i.kind == nnkExprColonExpr: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jester, templates | |
proc view(obj: Todo): string = tmpli html""" | |
<ul> | |
$for item in obj { | |
<li>$item</li> | |
} | |
</ul> | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dont remove any ()'s! | |
import sequtils, future | |
iterator items(num = 10): int = | |
for i in 1.. num: | |
yield i | |
let values = toSeq(numbers()) | |
.filter(x => (x mod 2 == 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Old | |
# Import "test" class from C++: | |
class(test, ns: pp, header: "../test.hpp"): | |
proc multiply[T](value, by: T): int | |
proc output: void {.isstatic.} | |
proc max[T](a, b: T): T | |
var fieldName, notherName: int | |
## New |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
when someModule: | |
proc a = | |
const someHtml = """ | |
<div>breaks indentation</div> | |
""" | |
proc b = | |
const someHtml = """ | |
<div>extra indentation</div> | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import math | |
# Constants | |
const RAND_MAX = 0x7fff | |
# Types | |
type | |
TVec2 = object | |
x, y: float |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import zlib | |
import sockets, jester | |
# Types | |
type TCompressStream* = ref object of TObject | |
client: TSocket | |
when defined(usegzip): | |
stream: TZStream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import templates, macros | |
template master(content: stmt): stmt {.immediate.} = | |
template body = content | |
tmpli html""" | |
<html> | |
<body> | |
${ body() } | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import templates | |
let NO_PROC = proc(n:var string) = discard | |
proc master(result: var string, head = NO_PROC, body = NO_PROC, footer = NO_PROC) = tmpl html""" | |
<head> | |
${ head(result) } | |
</head> | |
<body> | |
${ body(result) } |