Last active
April 11, 2018 20:00
-
-
Save sergiors/5f85fd7ba07b49a250570d7566795599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type(1) // => int | |
type(1.1) // => float | |
type('hello') // => string | |
type([1, 2, 3, 4]) // => array | |
type({true: 1, false: 0}) // => hashmap | |
type(?) // => null | |
// class | |
User { | |
str name, [str, ?] lastname | |
int yearsOld = 0 | |
construtor (str name, [str, ?] lastname = ?) { | |
this.name = name | |
this.lastname = lastname | |
} | |
get name() -> str { | |
return this.name.upper() | |
} | |
set name(string name) -> void { | |
this.name = name.trim() | |
} | |
yearsOld() -> int { | |
retutn this.yearsOld | |
} | |
} | |
// TypeError | |
User('Sérgio').name = 1 | |
-- | |
user = User('Sérgio') | |
print(user.name) // => Sérgio | |
user.name = 'Rafael' | |
print(user.name) // => RAFAEL | |
type(user) // => object | |
// function | |
fibonacc(int n) -> int { | |
if n < 1 { | |
return 0 | |
} | |
return n <= 2 | |
? 1 | |
: fibonacci(n - 1) + fibonacci(n - 2) | |
} | |
// lambda | |
pow = (int n) -> n * 10 | |
// control flow | |
if /*expression*/ { | |
// block | |
} | |
while /*expression*/ { | |
// block | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment