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
let | |
ages = @[20, 25, 18, 32] | |
proc reader(lst: seq[int]): iterator(): int = | |
result = iterator (): int = | |
for n in lst: | |
yield n | |
proc main() = | |
let read = reader(ages) # How to pass an argument? |
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
let numbers = @[2, 6, 3, 8, 5] | |
iterator read(): int{.closure.} = | |
for n in numbers: | |
yield n | |
proc main() = | |
var | |
first = read | |
second = read |
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 times | |
template benchmark*(benchmarkName: string, code: untyped) = | |
block: | |
let timeStart = cpuTime() | |
code | |
echo benchmarkName | |
echo cpuTime() - timeStart, "s" | |
var seqBase = @[@[1, 2], @[322146413, 397146891], @[2100521352, 391739920], @[ |
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 | |
macro `&*`[J:static[int]](a: array[J, int], x: static[int]): untyped = | |
result = nnkBracket.newTree() | |
for i in 0 ..< x: | |
for j in 0 ..< J: | |
result.add a[j] | |
expandMacros: | |
let key = [1,2,3] &* 10 |
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
template vkMakeVersion*(major, minor, patch: untyped): untyped = | |
(((major) shl 22) or ((minor) shl 12) or (patch)) | |
const | |
vkVersion10* = vkMakeVersion(1, 0, 0) | |
template vkVersionMajor*(version: untyped): untyped = | |
((uint32)(version) shr 22) | |
template vkVersionMinor*(version: untyped): untyped = | |
(((uint32)(version) shr 12) and 0x000003FF) | |
template vkVersionPatch*(version: untyped): untyped = | |
((uint32)(version) and 0x00000FFF) |
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
#? stdtmpl | standard | |
# view( | |
# for i in 0..12: | |
# if true == true: | |
<h1>hello world $i</h1> | |
# end if | |
# end for | |
# ) |