|
752 | 752 |
|
753 | 753 | - `INT: FROZEN(SYMBOL: name)` and `INT: PERMAFROZEN(SYMBOL: name)` = MUST report the freeze state of `name`. `FROZEN` MUST return `-1` for permanently frozen bindings, `1` for non-permanent frozen bindings, and `0` otherwise. `PERMAFROZEN` MUST return `1` only for permanently frozen bindings and `0` otherwise. If `name` is undefined, both operators MUST return `0`. |
754 | 754 |
|
| 755 | +--- |
| 756 | + |
755 | 757 | #### 9.1.2 Conversion and construction operators |
756 | 758 |
|
757 | 759 | - `INT: INT(INT|FLT|STR: value)` and `FLT: FLT(INT|FLT|STR: value)` = MUST perform explicit scalar conversion among the three numeric and string types. Converting a `FLT` to `INT` MUST truncate toward zero. Converting a `STR` to `INT` or `FLT` MUST parse a base-prefixed numeric literal; a `STR` that does not parse as a valid integer literal MUST be treated as it's boolean representation (converted to `FLT` for `FLT`). Passing a type other than `INT`, `FLT`, or `STR` MUST raise a runtime error. |
|
768 | 770 |
|
769 | 771 | - `FLT: ROUND(FLT: value, STR: mode = "floor", INT: ndigits = 0)` = MUST round `value` to `ndigits` places to the right of the radix point, where negative `ndigits` values round to positions to the left of the radix point. Supported modes MUST include `"floor"`, `"ceiling"` and `"ceil"`, `"zero"`, and `"logical"` and `"half-up"`. When exactly two arguments are supplied and the second argument is an `INT`, it MUST be interpreted as `ndigits` and the mode MUST default to `"floor"`. |
770 | 772 |
|
| 773 | +--- |
| 774 | + |
771 | 775 | #### 9.1.3 Arithmetic operators |
772 | 776 |
|
773 | 777 | - `INT|FLT: ADD/SUB/MUL/DIV/CDIV/POW/MOD(INT|FLT: a, INT|FLT: b)` = MUST implement, respectively, addition, subtraction, multiplication, division, ceiling division, exponentiation, and remainder. Except where an operator explicitly states otherwise, `a` and `b` MUST have the same numeric type. Division by zero MUST raise a runtime error. |
|
792 | 796 |
|
793 | 797 | - `INT: LEN(INT|STR: a1, ..., INT|STR: aN)` = MUST return the number of supplied arguments. Passing a `TNS` or any other unsupported type MUST raise a runtime error. |
794 | 798 |
|
| 799 | +--- |
| 800 | +
|
795 | 801 | #### 9.1.4 Logical and comparison operators |
796 | 802 |
|
797 | 803 | - `INT: AND/OR/XOR(ANY: a1, ..., ANY: aN)` and `INT: NOT(ANY: value)` = MUST perform boolean conjunction, disjunction, exclusive disjunction, and negation using the language's truthiness rules. |
|
806 | 812 |
|
807 | 813 | - `INT: GT/LT/GTE/LTE(INT|FLT: a, INT|FLT: b)` = MUST perform the corresponding ordered comparison on like-typed numeric operands and return `1` when the relation holds and `0` otherwise. Mixed `INT` and `FLT` comparisons MUST raise a runtime error. |
808 | 814 |
|
| 815 | +--- |
| 816 | +
|
809 | 817 | #### 9.1.5 String operators |
810 | 818 |
|
811 | 819 | - `INT: SLEN(STR: value)` = MUST return the character length of `value`. |
|
824 | 832 |
|
825 | 833 | - `STR: REPLACE(STR: value, STR: old, STR: new)` = MUST return `value` with every occurrence of the non-empty substring `old` replaced by `new`. |
826 | 834 |
|
| 835 | +--- |
| 836 | +
|
827 | 837 | #### 9.1.6 Tensor operators |
828 | 838 |
|
829 | 839 | - `TNS: TNS(TNS: shape, ANY: value)` and `TNS: TNS(STR: value)` = MUST construct tensors. In the shape form, `shape` MUST be a one-dimensional tensor of positive `INT` lengths and the result MUST be filled with `value`. In the string form, the result MUST be a one-dimensional tensor of one-character `STR` elements. |
|
846 | 856 |
|
847 | 857 | - `TNS: TADD/TSUB/TMUL/TDIV/TPOW(TNS: tensor, INT|FLT: scalar)` = MUST perform tensor-scalar arithmetic. All tensor elements and the scalar MUST share the same numeric type, except where a specific operator explicitly permits widening. Division by zero MUST raise a runtime error. |
848 | 858 |
|
| 859 | +--- |
| 860 | +
|
849 | 861 | #### 9.1.7 Map operators |
850 | 862 |
|
851 | 863 | - `TNS: KEYS(MAP: map)` and `TNS: VALUES(MAP: map)` = MUST return one-dimensional tensors containing, respectively, the keys and values of `map` in insertion order. |
|
856 | 868 |
|
857 | 869 | - `MAP: INV(MAP: map)` = MUST return a new map whose keys and values are reversed. Every value in `map` MUST be a scalar key type (`INT`, `FLT`, or `STR`), and duplicate values MUST raise a runtime error. |
858 | 870 |
|
| 871 | +--- |
| 872 | +
|
859 | 873 | #### 9.1.8 Function and module operators |
860 | 874 |
|
861 | 875 | - `RUN(STR: source)` = MUST parse and execute `source` as Prefix code in the caller's current lexical environment. Parse failure or runtime failure inside the executed source MUST raise a runtime error. If console output is currently suppressed by `SHUSH`, `RUN` MUST temporarily disable that suppression for the duration of the executed source and then restore the prior shush state afterward. |
|
880 | 894 |
|
881 | 895 | - `INT: EXPORT(SYMBOL: symbol, MODULE: module)` = MUST copy the caller's current binding for `symbol` into the namespace of the already imported module designated by `module`, making the exported binding available through that module's qualified namespace. `EXPORT` MUST return `0` on success and MUST raise a runtime error if `module` is not currently imported. |
882 | 896 |
|
| 897 | +--- |
| 898 | +
|
883 | 899 | #### 9.1.9 Concurrency operators |
884 | 900 |
|
885 | 901 | The expression form `ASYNC{ ... }` and the statement form `THR(symbol){ ... }` are defined in [3.6](#36-asynchronous-execution-and-threads). The operators in this subsection act on `THR` handles. |
|
898 | 914 |
|
899 | 915 | - `THR: RESTART(THR: thread)` = MUST reinitialize `thread` and begin its execution again, returning the restarted handle. |
900 | 916 |
|
| 917 | +--- |
| 918 | +
|
901 | 919 | #### 9.1.10 Serialization |
902 | 920 |
|
903 | 921 | This section specifies the on-the-wire JSON encoding used by the `SER` and `UNSER` operators. Implementations MUST follow this schema and the encoding rules below to ensure interoperability. |
|
996 | 1014 |
|
997 | 1015 | - `ANY: UNSER(STR: text)` = MUST parse `text` as JSON and reconstruct the runtime value according to the schema above. `UNSER` MUST raise a runtime error for invalid JSON, invalid/missing fields, invalid numeric spellings, unsupported key types for `MAP`, unknown discriminators that cannot be reconstructed, or other structural violations. |
998 | 1016 |
|
| 1017 | +--- |
| 1018 | + |
999 | 1019 | #### 9.1.11 File and host operators |
1000 | 1020 |
|
1001 | 1021 | - `STR: READFILE(STR: path, STR: coding = "UTF-8")` = MUST read the filesystem object at `path` and return its contents as a `STR`. Supported `coding` values MUST include `UTF-8`, `UTF-8 BOM`, `UTF-16 LE`, `UTF-16 BE`, `ANSI`, `binary`, and `hexadecimal`, along with the aliases `bin` for `binary` and `hex` for `hexadecimal`. Coding names MUST be matched case-insensitively. Text decoders MUST tolerate invalid data using replacement semantics. `UTF-8` MUST accept and strip a BOM if present. `ANSI` MUST map to Windows-1252 on Windows and Latin-1 on other hosts. `binary` MUST return an 8-bit-per-byte bitstring, and `hexadecimal` MUST return lowercase hexadecimal text. Read failure MUST raise a runtime error. |
|
1010 | 1030 |
|
1011 | 1031 | - `TNS: ARGV()` = MUST return the process argument vector as a one-dimensional tensor of `STR`, preserving the host-provided order. |
1012 | 1032 |
|
| 1033 | +--- |
| 1034 | + |
1013 | 1035 | #### 9.1.12 Console and process operators |
1014 | 1036 |
|
1015 | | -`INT: PRINT(INT|STR: arg1, ..., INT|STR: argN)` = MUST render each argument according to the language's `STR` conversion rules for `INT` and `STR`, separate adjacent rendered arguments with a single space, append a trailing newline, write the result to the console output, record the corresponding I/O event in the execution log, and return `0`. |
| 1037 | +- `INT: PRINT(INT|STR: arg1, ..., INT|STR: argN)` = MUST render each argument according to the language's `STR` conversion rules for `INT` and `STR`, separate adjacent rendered arguments with a single space, append a trailing newline, write the result to the console output, record the corresponding I/O event in the execution log, and return `0`. |
1016 | 1038 |
|
1017 | | -`STR: INPUT()` or `STR: INPUT(STR: prompt)` = MUST read a single line of text from the console input and return it as a `STR`. If `prompt` is supplied, the interpreter MUST write it to the console before reading input. The resulting input event MUST be recorded in the execution log, and if a prompt was supplied the recorded event MUST include that prompt text. |
| 1039 | +- `STR: INPUT()` or `STR: INPUT(STR: prompt)` = MUST read a single line of text from the console input and return it as a `STR`. If `prompt` is supplied, the interpreter MUST write it to the console before reading input. The resulting input event MUST be recorded in the execution log, and if a prompt was supplied the recorded event MUST include that prompt text. |
1018 | 1040 |
|
1019 | | -`INT: WARN(INT|STR: arg1, ..., INT|STR: argN)` = MUST behave like `PRINT`, except that output MUST occur only when the interpreter was started with `-verbose`, the rendered line MUST be prefixed with `WARNING: `, and the operator MUST return `1` when output occurred and `0` otherwise. Arguments outside `INT` and `STR` MUST raise a runtime error. |
| 1041 | +- `INT: WARN(INT|STR: arg1, ..., INT|STR: argN)` = MUST behave like `PRINT`, except that output MUST occur only when the interpreter was started with `-verbose`, the rendered line MUST be prefixed with `WARNING: `, and the operator MUST return `1` when output occurred and `0` otherwise. Arguments outside `INT` and `STR` MUST raise a runtime error. |
1020 | 1042 |
|
1021 | | -`INT: CL(STR: command)` = MUST execute `command` using the host command shell and return the resulting subprocess exit code as an `INT`. Failure to start the subprocess MUST raise a runtime error. The execution log MUST record the command text and resulting exit code. |
| 1043 | +- `INT: CL(STR: command)` = MUST execute `command` using the host command shell and return the resulting subprocess exit code as an `INT`. Failure to start the subprocess MUST raise a runtime error. The execution log MUST record the command text and resulting exit code. |
1022 | 1044 |
|
1023 | | -`EXIT()` or `EXIT(INT: code)` = MUST immediately terminate the interpreter and return process exit code `0` or the supplied integer `code`, respectively. The termination event MUST be recorded in the execution log when logging is enabled. |
| 1045 | +- `EXIT()` or `EXIT(INT: code)` = MUST immediately terminate the interpreter and return process exit code `0` or the supplied integer `code`, respectively. The termination event MUST be recorded in the execution log when logging is enabled. |
1024 | 1046 |
|
1025 | | -`INT: SHUSH()` = MUST suppress forwarding of console output produced by operators such as `PRINT`, `WARN`, and shell-output capture from `CL`, while leaving the corresponding I/O events available for deterministic logging and replay. `INPUT` prompts MUST continue to be forwarded while shushing is active. `RUN` MUST temporarily disable shushing for the duration of the executed source. `SHUSH` MUST return `0`. |
| 1047 | +- `INT: SHUSH()` = MUST suppress forwarding of console output produced by operators such as `PRINT`, `WARN`, and shell-output capture from `CL`, while leaving the corresponding I/O events available for deterministic logging and replay. `INPUT` prompts MUST continue to be forwarded while shushing is active. `RUN` MUST temporarily disable shushing for the duration of the executed source. `SHUSH` MUST return `0`. |
1026 | 1048 |
|
1027 | | -`INT: UNSHUSH()` = MUST clear the shush state established by `SHUSH` so that subsequent console output is forwarded normally again. `UNSHUSH` MUST return `0`. |
| 1049 | +- `INT: UNSHUSH()` = MUST clear the shush state established by `SHUSH` so that subsequent console output is forwarded normally again. `UNSHUSH` MUST return `0`. |
1028 | 1050 |
|
1029 | 1051 | ### 9.2 Statements |
1030 | 1052 |
|
|
1036 | 1058 |
|
1037 | 1059 | An expression written in statement position MUST be evaluated for its side effects and its resulting value MUST be discarded. Expression statements MUST otherwise obey the same evaluation-order and runtime-error rules as the corresponding expression in expression position. |
1038 | 1060 |
|
| 1061 | +--- |
| 1062 | + |
1039 | 1063 | #### 9.2.2 Declaration and assignment statements |
1040 | 1064 |
|
1041 | 1065 | The declaration form `TYPE: name` MUST record the static type of `name` without creating a readable runtime binding. Reading that symbol before a later assignment MUST raise a runtime error. |
|
1044 | 1068 |
|
1045 | 1069 | Indexed assignment statements `tensor[i1, ..., iN] = expression` and `map<k1, ..., kN> = expression` MUST follow the same typing, indexing, and mutation rules defined in [3.2](#32-declarations-and-assignment). Slice assignment to tensors MUST require exact shape agreement between the selected slice and the right-hand-side tensor value. |
1046 | 1070 |
|
| 1071 | +--- |
| 1072 | + |
1047 | 1073 | #### 9.2.3 Conditional statements |
1048 | 1074 |
|
1049 | 1075 | The conditional statement form `IF(condition){ ... }` MAY be followed immediately by zero or more `ELSEIF(condition){ ... }` clauses and at most one trailing `ELSE{ ... }` clause. Any `ELSEIF` or `ELSE` not directly attached to a preceding `IF` or `ELSEIF` MUST be rejected as a syntax error. |
1050 | 1076 |
|
1051 | 1077 | Conditions in statement position MUST accept only `INT`, `STR`, or `TNS`, with `STR` and `TNS` values interpreted according to the truthiness rules defined elsewhere in this specification. The interpreter MUST evaluate the `IF` branch first, then each `ELSEIF` in source order until one branch is taken, and finally the `ELSE` block when present and no earlier branch matched. |
1052 | 1078 |
|
| 1079 | +--- |
| 1080 | + |
1053 | 1081 | #### 9.2.4 Exception-handling statements |
1054 | 1082 |
|
1055 | 1083 | Structured exception handling MUST use either `TRY{ ... }CATCH{ ... }` or `TRY{ ... }CATCH(SYMBOL: name){ ... }`. The `CATCH` block MUST immediately follow its `TRY` block, and exactly one `CATCH` block MUST be provided for each `TRY` statement. |
1056 | 1084 |
|
1057 | 1085 | If execution of the `TRY` block completes normally, the corresponding `CATCH` block MUST be skipped. If execution raises an interpreter-level runtime error, execution of the `TRY` block MUST stop and the `CATCH` block MUST run; in the parameterized form, the temporary binding named by `name` MUST be a `STR` containing the error message for the duration of that handler block only. |
1058 | 1086 |
|
| 1087 | +--- |
| 1088 | + |
1059 | 1089 | #### 9.2.5 Loop statements |
1060 | 1090 |
|
1061 | 1091 | The statement `WHILE(condition){ ... }` MUST evaluate `condition` before each iteration and execute its body only while that condition remains truthy. When the condition becomes false, control MUST continue with the statement following the loop. |
|
1064 | 1094 |
|
1065 | 1095 | Loop counters introduced by `FOR` and `PARFOR` MUST be loop-local. Other declarations created in loop bodies MUST remain bound in the enclosing environment, subject to the merge and race semantics defined for `PARFOR`. |
1066 | 1096 |
|
| 1097 | +--- |
| 1098 | + |
1067 | 1099 | #### 9.2.6 Function-definition and return statements |
1068 | 1100 |
|
1069 | 1101 | Named function definitions MUST use the `FUNC` statement form with an explicit return type, function name, typed parameter list, and block body. Parameters MAY declare default expressions, coerced parameters MUST be marked with `~`, and all parameter-binding and default-evaluation behavior MUST follow the rules defined in [4.6](#46-functions) and [5.3](#53-function-symbols-and-call-binding). |
|
1072 | 1104 |
|
1073 | 1105 | The statement `POP(SYMBOL: name)` MUST be valid only inside a function body. It MUST retrieve the current value bound to `name`, delete that binding from the environment, and then return the retrieved value as though `RETURN(name)` had executed immediately before the deletion. Using `POP` outside a function, or applying it to an unreadable binding, MUST raise a runtime error. |
1074 | 1106 |
|
| 1107 | +--- |
| 1108 | + |
1075 | 1109 | #### 9.2.7 Asynchronous and thread statements |
1076 | 1110 |
|
1077 | 1111 | The statement form `ASYNC{ ... }` MUST start execution of its block in a background task that runs asynchronously with respect to the caller while sharing the same lexical environment. When used as a statement, any resulting `THR` handle MUST be ignored. |
1078 | 1112 |
|
1079 | 1113 | The statement form `THR(symbol){ ... }` MUST create a background task and bind its handle to `symbol` with static type `THR` in the current lexical environment. Runtime failures originating in either asynchronous statement form MUST be reported through the runtime's asynchronous error-reporting mechanisms and MUST NOT synchronously abort another execution context. |
1080 | 1114 |
|
| 1115 | +--- |
| 1116 | + |
1081 | 1117 | #### 9.2.8 Loop-control and jump statements |
1082 | 1118 |
|
1083 | 1119 | The statement `BREAK(n)` MUST exit the innermost `n` enclosing loops, where `n` evaluates to a strictly positive `INT`. The statement `CONTINUE()` MUST skip the remainder of the current iteration of the innermost enclosing loop and proceed according to the next-iteration rules of that loop. Using either statement outside an applicable loop context MUST raise a runtime error. |
1084 | 1120 |
|
1085 | 1121 | The statement `GOTOPOINT(n)` MUST register a jump target identified by runtime value `n`, and `GOTO(n)` MUST transfer control to a previously registered matching target within the permitted visibility scope. Invalid target values, unregistered targets, or jumps that otherwise violate the control-flow rules defined in [3.7](#37-loop-control-and-jumps) MUST raise runtime errors. |
1086 | 1122 |
|
| 1123 | +--- |
| 1124 | + |
1087 | 1125 | ## 10. Standard library |
1088 | 1126 |
|
1089 | 1127 | The standard library is a set of packages and modules bundled with the interpreter that provide a set of common utilities. |
|
0 commit comments