|
| 1 | +# MeTTaScript 2.6.0 |
| 2 | + |
| 3 | +Two additions. `metta check` now catches a top-level action form that is stored as data instead of run, and |
| 4 | +the standard library gained the pair of grounded ops that take a string apart into characters and put it |
| 5 | +back together. The engine is otherwise unchanged: no existing program's evaluation or output differs. |
| 6 | + |
| 7 | +## A stored action form is reported |
| 8 | + |
| 9 | +MeTTa evaluates a top-level form only when it carries a leading `!`; every other form is added to the space |
| 10 | +as data. That is what you want for a fact or a rule. It is not what you want for an op that exists for its |
| 11 | +effect, because such an op returns the unit type `(->)`, which produces nothing a later query can match. The |
| 12 | +stored call is inert: the assertion never checks, the `add-atom` never adds, the `println!` never prints. |
| 13 | +Nothing reports it, so an unbanged `assertEqualToResult` reads as a passing test. |
| 14 | + |
| 15 | +`metta check` now warns on that form and offers to insert the `!`: |
| 16 | + |
| 17 | +``` |
| 18 | +warning: `assertEqualToResult` runs for its effect, so this top-level form is stored as data and never evaluated |
| 19 | +``` |
| 20 | + |
| 21 | +The check reads the unit return type from each op's own signature rather than from a list of builtin names, |
| 22 | +so an op you declare `(-> ... (->))` yourself is covered on the same footing as the assert family, |
| 23 | +`add-atom`, and `println!`. It is a warning, so it never changes the exit code and cannot break a gate. It |
| 24 | +stays quiet when the `!` is separated from its form by a comment, which still binds, when the op also |
| 25 | +carries a non-arrow type, and when the argument count matches no declared overload, since the arity error |
| 26 | +already names the real problem. |
| 27 | + |
| 28 | +## Characters of a string |
| 29 | + |
| 30 | +`atom_concat` joins symbols but cannot split one, so a name like `e1_ep` could not be taken apart into a base |
| 31 | +and a sort at run time. `stringToChars` splits a `String` into an `Expression` of single-character symbols |
| 32 | +and `charsToString` joins one back, matching hyperon-experimental and mettalog, where a character is a |
| 33 | +single-character symbol: |
| 34 | + |
| 35 | +```metta |
| 36 | +!(stringToChars "e1_ep") ; (e 1 _ e p) |
| 37 | +!(let $cs (stringToChars "e1_ep") (charsToString $cs)) ; "e1_ep" |
| 38 | +``` |
| 39 | + |
| 40 | +The character list is ordinary data, so `car-atom`, `cdr-atom`, and `decons-atom` walk it. `charsToString` |
| 41 | +takes its list unevaluated, the way `car-atom` does, because the characters of `"+ab"` are `(+ a b)` and |
| 42 | +evaluating that argument would run an addition instead of joining it back; bind a computed list with `let`. |
| 43 | +Astral characters stay whole rather than splitting into surrogate halves. |
| 44 | + |
1 | 45 | # MeTTaScript 2.5.1 |
2 | 46 |
|
3 | 47 | A `metta check` accuracy fix. The static analyzer stopped reporting false arity errors on overloaded doc |
|
0 commit comments