diff --git a/README.md b/README.md index 8932c6e..4f9a0a2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ print tally(); //3 * [Embedding Toy](embedding-toy) * [Compiling Toy](compiling-toy) * [Using Toy](using-toy) - * ~~[Standard Libary](standard-library)~~ + * [Standard Libary](standard-library) * [Types](types) * [Developing Toy](developing-toy) * [Roadmap](roadmap) diff --git a/quick-start-guide.md b/quick-start-guide.md index 590804b..37705bb 100644 --- a/quick-start-guide.md +++ b/quick-start-guide.md @@ -23,6 +23,8 @@ var f = 3.14; var s = "Hello world"; ``` +See [Reserved Keywords](#reserved-keywords) for a list of keywords that can't be used as a name. + ## Compounds Larger containers of data are available - arrays and dictionaries. Arrays are collections of data stored sequentially, while dictionaries are hash-maps of key-value pairs: @@ -169,3 +171,59 @@ assert answer == 42, "This will not be seen"; assert null, "This will be seen before the script exits"; ``` +## Reserved Keywords + +The following list cannot be used as names, due to their significance (or potential later use) in the language. + +* any +* as +* astype +* assert +* bool +* break +* class (reserved) +* const +* continue +* do (reserved) +* else +* export +* false +* float +* fn +* for +* foreach (reserved) +* if +* import +* in (reserved) +* int +* null +* of (reserved) +* print +* return +* string +* true +* type +* typeof +* var +* while + +## Full List of Operators + +The following mathematical operators are available. A definition is omitted here, as they are commonly used in most programming languages. + +``` ++ - * / % += -= *= /= %= ++(prefix) --(prefix) (postfix)++ (postfix)-- +``` + +Likewise, the following logical operators are available (`&&` is more tightly bound than `||` due to historical reasons): + +``` +( ) [ ] { } ! != == < > <= >= && || +``` + +Other operators used throughout the language are: the assignment, colon, semicolon, comma, dot and rest operators: + +``` += : ; , . ... +``` + diff --git a/roadmap.md b/roadmap.md index fe1138f..23d0966 100644 --- a/roadmap.md +++ b/roadmap.md @@ -28,6 +28,28 @@ Some things I'd like to add in the future include: Some of these have always been planned, but were sidelined or are incomplete for one reason or another. +## Planned Standard Library Functions + +* _concat(self: any, x: any): any - This function requires an array or dictionary with a matching type as "x". This function returns a new dictionary instance which contains the contents of the current array or dictionary combined with the contents of "x". In the event of a dictionary key clash, the key-value pair in the current dictionary is included, and the key-value pair from "x" is discarded. +* _containsKey(self: [any : any], k: any): bool - This function returns true if the dictionary contains a key "k", otherwise it returns false. +* _containsValue(self: any, v: any): bool - This function returns true if the array or dictionary contains a value "v", otherwise it returns false. +* _every(self: any, cb: fn(k: any, v: any): bool): bool - This function calls "cb" once for every entry in the array or dictionary (self), with that element passed in as "k" and "v", until cb returns false, at which point "every" returns false. If it reaches the end of the array or dictionary, then "every" returns true. +* _filter(self: any, cb: fn(k: any, v: any)(bool)): any - This function calls "cb" once for every entry in the array or dictionary (self), with that key and value passed in as "k" and "v", respectfully. This returns a new array or dictionary that contains every key-value pair for which the call to "cb" returned true. +* _indexOf(self: string, str: string): int - This function returns the position of the first instance of "str" in the string "self". +* _insert(self: any, key: any, x: any) - This function inserts "value" at the index/key "key", shifting the remaining entry up 1 index if it's an array. This alters the memory. +* _keys(self: any): [type] - This function returns an array containing each key in the dictionary. The order of the keys is undefined. +* _map(self: any, cb: fn(k: any, v: any): any): any - This function calls "cb" once for every entry in the array or dictionary, with that key passed in as "k" and value passed in as "v". It returns a new array or dictionary with the keys copied from the current "self", and values replaced with the results of calls to "cb". +* _reduce(self: any, default: any, cb: fn(acc: any, k: any, v: any): any): any - This function calls "cb" once for every element in the array or dictionary "self", with that element passed in as "k" and "v", and the value of the previous call passed in as "acc". For the first call to "cb", "default" is used for "acc". The final value of "acc" is returned by "reduce". +* _remove(self: any, k: any) - This function deletes the value at the index or key "k", shifting the remaining entries down 1 index if it's an array. This alters the memory. +* _replace(self: string, pat: string, rep: string): string - For each instance of "pat" that it finds in the calling string "self", it replaces it with "rep", then returns the new string. +* _some(self: any, cb: fn(k: any, v: any): bool): bool - This function calls "cb" once for every entry in the array or dictionary (self), with that element passed in as "key" and "value", until cb returns true, at which point "some" returns true. If it reaches the end of the array or dictionary, then "some" returns false. +* _sort(self: [any], cb: fn(lhs: any, rhs: any): int): [any] - This function sorts the entries of an array according to the callback "cb". "cb" may be called any number of times during the sorting process. "cb" must be a function that takes two parameters, "lhs" and "rhs" and returns an integer. If "lhs" is less than "rhs", then the returned integer should be negative. If they are equal, then it should be 0. Otherwise it should be positive. This returns the sorted array, leaving the original intact. +* _toLower(self: string): string - This function returns a new string, which is the same as the calling string, except all characters are lower case. +* _toString(self: any): string - This function returns a string representation of the input "self". For arrays and dictionaries, each element is converted to a string where possible, and separated by commas (and colons for dictionaries). Finally, the whole string is surrounded by brackets. +* _toUpper(self: string): string - This function returns a new string, which is the same as the calling string, except all characters are upper case. +* _trim(self: string, chars: string): string - Every character in the string "chars" is removed from the calling string's beginning and end, and the new string is returned. The original string is not modified. +* _values(self: [any : any]): [any] - This function returns an array containing each value in the dictionary. The order of the values is undefined. + ## Nope Features Some things I simply don't want to include at the current time include: diff --git a/standard-library.md b/standard-library.md new file mode 100644 index 0000000..99d9ab9 --- /dev/null +++ b/standard-library.md @@ -0,0 +1,14 @@ +# Standard Library + +The standard library offers a number of miscellaneous utility functions, which can be used for various purposes. These functions are implemented by the host program, so they may not all be provided by default. + +The standard library can usually be accessed with the `import` keyword: + +``` +import standard; +``` + +## Clock() + +This function returns the current timestamp. +