This file contains hidden or 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
# counting point mutations | |
# count all mutations where C != C, G !=G, A != A, and T != T | |
import algorithm | |
# define string variables | |
var s: string = "GAGCCTACTAACGGGAT" | |
var t: string = "CATCGTAATGACGGCCT" | |
# define count variable for number of mutations | |
var mutations: int = 0 |
This file contains hidden or 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 algorithm | |
# Complementing a strand of DNA | |
# I want to reverse the string "s" and then replace | |
# all A's with T's | |
# all T's with A's | |
# all C's with G's | |
# all G's with C's | |
# define my string variable |
This file contains hidden or 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 tables | |
type X = ref object | |
case kind*: bool | |
of false: | |
discard | |
of true: | |
fields*: Table[int, int] | |
var t = X(kind: true, fields: initTable[int, int]()) |
This file contains hidden or 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
const data = "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" | |
var A, C, G, T = 0 | |
for letter in data: | |
case letter | |
of 'A': inc A | |
of 'C': inc C | |
of 'G': inc G | |
of 'T': inc T |
This file contains hidden or 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
proc f = | |
raise newException(ValueError, "foo") | |
proc g {.raises: [].} = | |
f() | |
# Fails with a nice error: | |
# x.nim(4, 18) template/generic instantiation from here | |
# x.nim(2, 3) Error: can raise an unlisted exception: ref ValueError |
This file contains hidden or 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
iterator `..`[T](s: Slice[T], step = 1): T {.inline.} = | |
var pos: T = int(s.a) | |
while pos <= int(s.b): | |
yield T(pos) | |
pos += step | |
for i in 1..10..2: | |
echo i |
This file contains hidden or 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 FiveBytes = array[5, byte] | |
var x: FiveBytes | |
echo sizeof(x) | |
var xs: array[10, FiveBytes] | |
echo sizeof(xs) |
This file contains hidden or 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 Foo = object | |
proc `()`(foo: Foo) = | |
echo "foo" | |
var x: Foo | |
x() |
This file contains hidden or 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 | |
Container[T] = concept c | |
c.len is Ordinal | |
items(c) is T | |
for value in c: | |
type(value) is T | |
proc foo(x: Container[int]) = | |
for item in x: | |
echo item |
This file contains hidden or 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 posix, os, streams, marshal | |
const fileName = "file.mem" | |
var x = ("", @[0]) | |
proc store = | |
let result = fork() | |
if result < 0: | |
raise newException(ValueError, "Fork failed") |