Skip to content

Instantly share code, notes, and snippets.

@ReneSac
Created February 25, 2014 06:12
Show Gist options
  • Save ReneSac/6dfe2a72d7d0f1822d43 to your computer and use it in GitHub Desktop.
Save ReneSac/6dfe2a72d7d0f1822d43 to your computer and use it in GitHub Desktop.
type
Tunits = tuple
s, m: int
Tsym = object
val: int
unit: Tunits
proc `+` (a, b: Tunits): Tunits =
for i in 0 .. 1:
result[i] = a[i] + b[i] # Error: cannot evaluate at compile time: i
proc `*` (a, b: Tsym): Tsym =
result.val = a.val * b.val
result.unit = a.unit + b.unit
let fourSeconds = Tsym(4, Tunits(1,0))
echo repr( fourSeconds * fourSeconds ) # should output something like {val: 8, {s: 2, m: 0}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment