e466775b7977ba9a86896bf626c3d0b4edb1ff02
Misc/_Moelang.md
| ... | ... | @@ -1,62 +0,0 @@ |
| 1 | -# Types |
|
| 2 | -## Primitives |
|
| 3 | -- Int (Int8, Int16, Int32, **Int64**, IntU8, IntU16, IntU32, IntU64) |
|
| 4 | -- Float (Float32, **Float64**) |
|
| 5 | -- Char (Char8, **Char16**) |
|
| 6 | -- Bool |
|
| 7 | -- Void |
|
| 8 | - |
|
| 9 | -## Dynamic structures |
|
| 10 | -- List[T] |
|
| 11 | - - Dynamic list of elements of type T |
|
| 12 | -- Map[K, V] |
|
| 13 | - - Dynamic map of keys of type K, and values of type V |
|
| 14 | - - Using V=Void makes it essentially a set |
|
| 15 | - |
|
| 16 | -## Other features |
|
| 17 | -- `@` |
|
| 18 | - - Reference instead of copy |
|
| 19 | -- `?` |
|
| 20 | - - Optional (can be `null`) |
|
| 21 | -- `Type1(<paramX:TypeX>*)` |
|
| 22 | - - Callable with params |
|
| 23 | - - Example Int(x: Int, y: Int) - a function with parameters x: Int, and y: Int, which returns Int |
|
| 24 | - |
|
| 25 | -## Example type usage (`Complex` module) |
|
| 26 | -``` |
|
| 27 | -module Complex |
|
| 28 | - struct Complex |
|
| 29 | - re: Float |
|
| 30 | - im: Float |
|
| 31 | - end |
|
| 32 | - |
|
| 33 | - func conjugate -;;> Complex(c: Complex) |
|
| 34 | - return Complex { |
|
| 35 | - re=c.re, |
|
| 36 | - im=-c.im, |
|
| 37 | - } |
|
| 38 | - end |
|
| 39 | - |
|
| 40 | - cast -;;> Complex(f: Float) |
|
| 41 | - return Complex { |
|
| 42 | - re=f, |
|
| 43 | - im=0.0, |
|
| 44 | - } |
|
| 45 | - end |
|
| 46 | - |
|
| 47 | - cast -;;> Complex(i: Int) |
|
| 48 | - return Complex { |
|
| 49 | - re=Float {i}, |
|
| 50 | - im=0.0, |
|
| 51 | - } |
|
| 52 | - end |
|
| 53 | - |
|
| 54 | - operator["+"] -> Complex() |
|
| 55 | -end |
|
| 56 | -``` |
|
| 57 | -# Type casting |
|
| 58 | -You put type and then the value to be cast: |
|
| 59 | -``` |
|
| 60 | -Complex { re=1.0, im=2.0 } // cast anonymous struct to Complex |
|
| 61 | -Float 3 // cast integer 3 to Float |
|
| 62 | -``` |
|
| ... | ... | \ No newline at end of file |