|
| 1 | +# Charon API |
| 2 | + |
| 3 | +A list of objects, functions and operators. |
| 4 | + |
| 5 | +**WARNING**: Under construction! |
| 6 | + |
| 7 | +## Library functions |
| 8 | + |
| 9 | + - `def` |
| 10 | + - `def-impure` |
| 11 | + - `let` |
| 12 | + - `apply` |
| 13 | + - `if` |
| 14 | + - `try` |
| 15 | + - `catch` |
| 16 | + - `do` |
| 17 | + - `fn` |
| 18 | + - `...` |
| 19 | + - `+` |
| 20 | + - `-` |
| 21 | + - `/` |
| 22 | + - `*` |
| 23 | + - `^` |
| 24 | + - `=` |
| 25 | + - `<>` |
| 26 | + - `>` |
| 27 | + - `<` |
| 28 | + - `>=` |
| 29 | + - `<=` |
| 30 | + - `and` |
| 31 | + - `or` |
| 32 | + - `not` |
| 33 | + - `nand` |
| 34 | + - `nor` |
| 35 | + - `xor` |
| 36 | + - `->` |
| 37 | + - `<-` |
| 38 | + - `str` |
| 39 | + - `import` |
| 40 | + - `def-value` |
| 41 | + - `def-extern` |
| 42 | + - `when` |
| 43 | + - `unit` |
| 44 | + - `true` |
| 45 | + - `false` |
| 46 | + - `some?` |
| 47 | + - `or?` |
| 48 | + - `>>=` |
| 49 | + - `atom` |
| 50 | + - `opaque-call` |
| 51 | + - `call` |
| 52 | + - `println` |
| 53 | + - `print` |
| 54 | + - `file/open` |
| 55 | + - `file/close` |
| 56 | + - `file/write` |
| 57 | + - `file/read` |
| 58 | + |
| 59 | +## Library objects and collections |
| 60 | + |
| 61 | +### string |
| 62 | + |
| 63 | +Methods related: |
| 64 | + |
| 65 | + - `string/byte` |
| 66 | + - `string/char` |
| 67 | + - `string/dump` |
| 68 | + - `string/find` |
| 69 | + - `string/format` |
| 70 | + - `string/gmatch` |
| 71 | + - `string/gsub` |
| 72 | + - `string/len` |
| 73 | + - `string/lower` |
| 74 | + - `string/match` |
| 75 | + - `string/rep` |
| 76 | + - `string/reverse` |
| 77 | + - `string/sub` |
| 78 | + - `string/upper` |
| 79 | + |
| 80 | +### vector |
| 81 | + |
| 82 | +A vector is a collection of incrementing integer keys, like lists or arrays in |
| 83 | +other languages. |
| 84 | + |
| 85 | +```clj |
| 86 | +; Example of creation |
| 87 | +(def-value v [1 2 3 4]) |
| 88 | +``` |
| 89 | + |
| 90 | +Methods related: |
| 91 | + |
| 92 | + - `vector/map` |
| 93 | + - `vector/each` |
| 94 | + - `vector/get` |
| 95 | + - `vector/filter` |
| 96 | + - `vector/merge` |
| 97 | + - `vector/add` |
| 98 | + - `vector/drop` |
| 99 | + - `vector/drop-left` |
| 100 | + - `vector/len` |
| 101 | + |
| 102 | +### table |
| 103 | + |
| 104 | +A table is a collection of arbitrarily keyed objects. This means that a table's |
| 105 | +key can be anything, even `unit`! |
| 106 | + |
| 107 | +To create a new table use the literal `{}`. |
| 108 | + |
| 109 | +```clj |
| 110 | +; Example |
| 111 | +(def-value my-table |
| 112 | + { :hello "World" |
| 113 | + :use "symbols for keys, usually." |
| 114 | + 55 "But you can really use anything" |
| 115 | + }) |
| 116 | +``` |
| 117 | + |
| 118 | +Methods related: |
| 119 | + |
| 120 | + - `table/get` |
| 121 | + - `table/get?` |
| 122 | + - `table/remove` |
| 123 | + - `table/merge` |
| 124 | + |
| 125 | +### atom |
| 126 | + |
| 127 | +Atoms are special objects dedicated to the state mutation. Atoms hold an |
| 128 | +internal state that can be read with `atom/get` and mutated with `atom/reset!` |
| 129 | +or `atom/apply!`. |
| 130 | + |
| 131 | +Therefore all read/write operations to an atom are impure. |
| 132 | + |
| 133 | +```clj |
| 134 | +(let [count (atom 0)] |
| 135 | + (atom/reset! count 1) |
| 136 | + (atom/apply! count + 1) |
| 137 | + (println "count = " (atom/get count))) |
| 138 | +``` |
| 139 | + |
| 140 | +Methods related: |
| 141 | + |
| 142 | + - `atom/get` |
| 143 | + - `atom/reset!` |
| 144 | + - `atom/apply!` |
| 145 | + |
| 146 | +### record |
| 147 | + |
| 148 | +**Planned feature.** |
| 149 | + |
| 150 | +Represents an arbitrary data tree with associated methods, but |
| 151 | +in distinction of an object it can ensure purity. |
| 152 | + |
| 153 | +### object |
| 154 | + |
| 155 | +An object is anything that is not a primitive, or a standard collection. The |
| 156 | +underlying implementation is a any Lua table, and is the primary method for |
| 157 | +interacting with existing Lua codebase. |
| 158 | + |
| 159 | +```clj |
| 160 | +; Creates a new Lua table, keys are not symbols but strings (Plain old Lua). |
| 161 | +(def-value my_second_object |
| 162 | + (object/new |
| 163 | + { :some_field "Hey" |
| 164 | + :some_other 539 |
| 165 | + })) |
| 166 | +``` |
| 167 | + |
| 168 | +Related methods: |
| 169 | + |
| 170 | + - `object/new` |
| 171 | + - `object/new-raw` |
| 172 | + - `object/get` |
| 173 | + - `object/set` |
| 174 | + |
| 175 | +### unit |
| 176 | + |
| 177 | +Unit is a singleton object which contains no data. Acts like `null` in other |
| 178 | +languages, but it's a single object that can be referenced. |
| 179 | + |
| 180 | +This means that there is a distinction between no-value (unit) and non-existent |
| 181 | +reference or variable, which has no type in Charon but would translate to `nil` |
| 182 | +in Lua. |
| 183 | + |
| 184 | +All that has no value will return unit in charon (including void methods). Unit |
| 185 | +can be used as a key for indexing a table, which is different from not having |
| 186 | +the entry at all. |
0 commit comments