lunes, 28 de noviembre de 2016

My first post on Swift (for Linux)


As Apple kindly released Swift for Linux...I had to learn about it -:)

Of course...it's not fully implemented...so most of the things that makes Swift awesome on IOS are not here yet...but still...it's awesome! -:D

Swift is kind of functional...so you can see a lot from Haskell and Erlang...but it's also imperative and Object Oriented...so that makes it a really interesting language...

As usual...here's my Fibonacci numbers little app...

fibonacci.swift
func fib(num:Int,a:Int,b:Int) -> String{
 var result: String = "";
 if a > 0 && num > 1{
  result = result + String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: a);
 }else if a == 0{
  result = String(a) + " " + String(b) + " " + 
           String(a + b) + " " + 
           fib(num: (num - 1), a: (a + b), b: b);
 }
 return result;
}

print("Enter a number: ",terminator:"");
let number = Int(readLine(strippingNewline: true)!);

print(fib(num: number!, a: 0, b: 1));

And here's the result....


I already have the LED Numbers app ready...so just wait for it -;)

Greetings,

Blag.
Development Culture.