X-Git-Url: http://nitlanguage.org diff --git a/examples/extern_methods.nit b/examples/extern_methods.nit index faa6faa..333540b 100644 --- a/examples/extern_methods.nit +++ b/examples/extern_methods.nit @@ -21,21 +21,21 @@ module extern_methods redef enum Int # Returns self'th fibonnaci number # implemented here in C for optimization purposes - fun fib : Int import fib `{ - if ( self < 2 ) + fun fib: Int import fib `{ + if (self < 2) return self; else - return Int_fib( self-1 ) + Int_fib( self-2 ); + return Int_fib(self-1) + Int_fib(self-2); `} # System call to sleep for "self" seconds fun sleep `{ - sleep( self ); + sleep(self); `} - # Return atan2l( self, x ) from libmath - fun atan_with( x : Int ) : Float `{ - return atan2( self, x ); + # Return atan2l(self, x) from libmath + fun atan_with(x: Int): Float `{ + return atan2(self, x); `} # This method callback to Nit methods from C code @@ -45,13 +45,13 @@ redef enum Int # * to_s, a method of all objects # * String.to_cstring, a method of String to return an equivalent char* fun foo import fib, +, to_s, String.to_cstring `{ - long self_fib = Int_fib( self ); - long self_plus_fib = Int__plus( self, self_fib ); + long self_fib = Int_fib(self); + long self_plus_fib = Int__plus(self, self_fib); - String nit_string = Int_to_s( self_plus_fib ); - char *c_string = String_to_cstring( nit_string ); + String nit_string = Int_to_s(self_plus_fib); + char *c_string = String_to_cstring(nit_string); - printf( "from C: self + fib(self) = %s\n", c_string ); + printf("from C: self + fib(self) = %s\n", c_string); `} # Equivalent to foo but written in pure Nit @@ -63,7 +63,7 @@ print 12.fib print "sleeping 1 second..." 1.sleep -print 100.atan_with( 200 ) +print 100.atan_with(200) 8.foo 8.bar