Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

My first post on Swift (for Linux)

$
0
0

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....


My first post on Swift (for Linux)

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

Greetings,

Blag.

Development Culture.


Viewing all articles
Browse latest Browse all 11063

Trending Articles