Created
January 23, 2010 18:10
-
-
Save nddrylliog/284712 to your computer and use it in GitHub Desktop.
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
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