Skip to content

Instantly share code, notes, and snippets.

@yohm
Created April 26, 2015 06:33
Show Gist options
  • Save yohm/444cf984b7b420d6d1b9 to your computer and use it in GitHub Desktop.
Save yohm/444cf984b7b420d6d1b9 to your computer and use it in GitHub Desktop.
A sample of x10 Point class
class Point01 {
static def p( o: Any ) {
Console.OUT.println( o );
}
public static def main( args: Rail[String] ) {
Console.OUT.println("hello");
// construct a 1-d point from Long
val p1 = Point.make(3);
p( p1 ); // [3]
// construct a 2-d point from 2 Long
val p2 = Point.make( 4, 5 );
p( p2 ); // [4,5]
// construct n-d point from Rail[Long]
val p3 = Point.make( [1,2,3] );
p( p3 ); // [1,2,3]
// construct n-d point from Func
val p4 = Point.make( 5, (n:Long) => n*n );
p( p4 ); // [0,1,4,9,16]
// coords
for( i in 0..4 ) {
p( p4(i) ); // 0,1,4,9,16
p( p4.coords()(i) ); // 0,1,4,9,16
}
p( p3.equals( Point.make(1,2,3) ) ); // true
p( p4.hashCode() ); // 6204. This value is calculated from coordinates.
p( p3.equals( [1,2,3] ) ); // false ???
p( p3.equals( [1,2,3] as Point ) ); // true
// p( p3 == [1,2,3] ); // compile error
p( p3 == Point.make([1,2,3]) ); // false (同一objectでなければfalse)
p( p3 + 5 ); // [6,7,8]
p( p3 + [4,5,6] ); // [5,7,9]
p( -p3 ); // [-1,-2,-3]
p( p3 - 5 ); // [-4,-3,-2]
p( p3 - [1,2,3] ); // [0,0,0]
p( p3 * 3 ); // [3,6,9]
p( 3 * p3 ); // [3,6,9]
p( p3 * [3,2,1] ); // [3,4,3]
p( p3 / 2 ); // [0,1,1]
p( p3 / [3,2,1] ); // [0,1,3]
p( p3 < [1,2,4] ); // true
p( p3 < [0,9,9] ); // false
p( p3 < [1,2,-1] ); // false
p( p3 <= [1,2,3] ); // true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment