Last active
September 3, 2018 06:25
-
-
Save thosakwe/f6c041fa02bd6dad9d573174667e0dbd to your computer and use it in GitHub Desktop.
Hmmmrmrmr
This file contains 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
val Ascii = ( | |
A: 0x12, | |
// ... | |
z: 0x13 | |
) | |
type Number = Uint8 | Uint16 // Etc. | |
fn (Number n) toString() : String { | |
var chars = Array(Uint16).new() | |
var nbr = n | |
while (someMod) { | |
chars = [...chars, someAscii] | |
} | |
return String.fromBytes(chars) | |
} |
This file contains 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 MyEnum = enum { Foo, Bar, Baz } | |
type MyUnion = MyEnum | Int32 | |
type MyTuple = (Int32, Int64) | |
type MyTupleWithNames = (int: Int32, long: Int64) | |
type MyParameterized = (type T) (Int32, T) | |
type MySized = (val size: Int32) Array(Uint16, size * 2) | |
fn doIt (x: Int32, y: Int32): MyParameterized(Int64) { | |
return (2, 3) | |
} | |
fn main () : Int32 { | |
// This 'as' cast discards the other members | |
val result = doIt(1, 2) as (a: Int32) | |
// Just return the field we need | |
return result.a | |
} | |
This file contains 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 String = (length: Uint64, characters: Array(Uint16)) | |
// Instance method | |
fn (String this) reverse (): String { | |
val chars = Array(Uint16).new() | |
var i = 0 | |
while (i-- >= 0) { | |
chars = [...chars, this.characters at (this.length - 1 - i)] | |
} | |
return (this.length, chars) | |
} | |
fn String.fromBytes(characters: Array(Uint16)): String { | |
return (len(), characters) | |
} | |
fn main() : Int32 { | |
val s = 'hello'.reverse() // Literal, hooray | |
return s.length as Int32 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment