changed dot operator to access global functions

This commit is contained in:
2022-09-08 01:18:20 +01:00
parent 8550f3141c
commit 5861602f23
11 changed files with 81 additions and 378 deletions

View File

@@ -34,17 +34,17 @@ DONE: Import/export keywords
DONE: A way to check the type of a variable (typeOf keyword)
DONE: slice and dot notation around the builtin _index and _dot functions
DONE: maximum recursion/function depth
DONE: better sugar for _push, _pop, _length
TODO: nested compound assignment
TODO: better sugar for _push, _pop, _length
TODO: ternary operator?
TODO: Nullish types?
TODO: hooks on the external libraries, triggered on import
TODO: standard library
TODO: external script runner library
TODO: document how it all works - book?
TODO: better API
TODO: better API?
TODO: packaging for release?
NOPE: a = b = c = 1;

View File

@@ -433,15 +433,14 @@ var dict: [string const, int const] const = [
];
```
Dictionaries can be indexed using traditional bracket notation, or the dot operator when the keys are strings. Existing elements can be accessed or overwritten, or new ones inserted if they don't already exist this way by using the standard library functions.
Dictionaries can be indexed using traditional bracket notation. Existing elements can be accessed or overwritten, or new ones inserted if they don't already exist this way by using the standard library functions.
```
dict["foo"] = "bar";
print dict["foo"];
print dict.foo; //syntactic sugar, only works if the key is not a built-in function
```
## Indexing, Slice and Dot Notation
## Slice Notation
Strings, arrays and dictionaries can be indexed in several ways, via the globally available functions (see below). Elements can be accessed using traditional bracket notation:
@@ -485,11 +484,22 @@ print str[::-2]; //drwolH
0 cannot be used as the third argument.
### Globally available functions
### Globally Available Functions
The slice and dot notations (the latter of which only works on dictionaries) are simply syntactic sugar for the globally available functions.
The dot notation can be used to acces the globally available functions, like so:
```
obj.function(); //passes in obj as the first argument
```
A list of globally available functions is:
```
//usable with arrays, dictionaries and strings - probably a good idea not to use this one, just use index notation
fn _index(self, first, second, third, assign, op) {
//native code
}
//usable with arrays and dictionaries
fn _set(self, key, value) {
//native code