Skip to content

Instantly share code, notes, and snippets.

@nddrylliog
Created January 23, 2010 18:10
Show Gist options
  • Save nddrylliog/284712 to your computer and use it in GitHub Desktop.
Save nddrylliog/284712 to your computer and use it in GitHub Desktop.
Nut: class {
cracker: Int
init: func(cracker: Int) {
this cracker = cracker
}
}
operator <=> (n1, n2: Nut) -> Int { n1 cracker > n2 cracker ? 1 : (n1 cracker < n2 cracker ? -1 : 0) }
main: func {
n1 := Nut new(42)
n2 := Nut new(217)
printf("%3d < %3d ? %d\n", n1 cracker, n2 cracker, n1 < n2)
printf("%3d > %3d ? %d\n", n1 cracker, n2 cracker, n1 > n2)
printf("%3d >= %3d ? %d\n", n1 cracker, n1 cracker, n1 >= n1)
printf("%3d <= %3d ? %d\n", n2 cracker, n1 cracker, n2 <= n1)
printf("%3d == %3d ? %d\n", n1 cracker, n1 cracker, n1 == n1)
printf("%3d == %3d ? %d\n", n1 cracker, n2 cracker, n1 == n2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment