Skip to content

Commit 7a7e267

Browse files
committed
Docs update
1 parent 3438c3e commit 7a7e267

4 files changed

Lines changed: 102 additions & 86 deletions

File tree

docs/rules/en/Rules.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,15 @@ D. FEEDBACK / REPORTING (`lsfusion_report_feedback`)
244244

245245
4. An expression whose comma is NOT enclosed in brackets of
246246
its own — `OVERRIDE a, b`, `CONCAT sep, a, b`,
247-
`GROUP CONCAT expr, sep` — MUST NOT go straight into a
248-
comma-separated list (`PROPERTIES`, `EXPORT FROM`,
249-
`JSON FROM`, `ORDER`, group-object and parameter lists):
250-
that comma reads as the list separator and the list
251-
silently reshapes. Group it, or name it as a property, in
252-
whichever form the enclosing block accepts. A comma inside
253-
an ordinary call's own parentheses is safe.
247+
`GROUP CONCAT expr, sep`, `MAX a, b` — MUST NOT go
248+
straight into a comma-separated list (`PROPERTIES`,
249+
`EXPORT FROM`, `JSON FROM`, `ORDER`, group-object and
250+
parameter lists): that comma reads as the list separator
251+
and the list silently reshapes. Group it, or name it as
252+
a property, in whichever form the enclosing block accepts.
253+
A call's own commas — `f(a, b)` — are safe in the enclosing
254+
list, but they do not fence off such an expression placed
255+
inside them: `f(MAX a, b)` passes one argument, not two.
254256

255257
5. When introducing a new parameter, the assistant MUST
256258
declare its class explicitly at the first use

docs/rules/en/Rules_logic.md

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,42 @@ title: 'Rules: domain logic'
164164
silently drops the fractional part;
165165
the correct form is `NUMERIC[16,4](a) * b / c`.
166166

167-
17. A parameter's class annotation (`prop(SubClass x)`) is a
167+
17. The class of an expression's result can be wider than
168+
the classes it is built from, and the assistant MUST
169+
account for that wherever a narrower class is required —
170+
above all in a `+=` implementation, where it is
171+
a server startup error.
172+
173+
Arithmetic widens further than it looks:
174+
175+
- `+` and `-` — like `MIN` / `MAX` and the selection
176+
operators — take the common ancestor, widening the
177+
whole part and the scale independently, so the result
178+
can be wider than either operand:
179+
`NUMERIC[16,2] + NUMERIC[10,4]` is `NUMERIC[18,4]`;
180+
- `*` adds both the whole parts and the scales:
181+
`NUMERIC[16,2] * NUMERIC[10,4]` is `NUMERIC[26,6]`;
182+
- `/` widens catastrophically: with the default settings
183+
its scale is always the maximum `NUMERIC` scale (`32`),
184+
so `NUMERIC[16,2] / NUMERIC[16,2]` is `NUMERIC[48,32]`.
185+
186+
A `GROUP` aggregate mostly keeps the class of what it
187+
aggregates — a `GROUP SUM`, `GROUP MAX` or `GROUP LAST`
188+
over a `NUMERIC[16,2]` is `NUMERIC[16,2]` — but it
189+
carries outward whatever that expression already widened
190+
to. `GROUP CONCAT` is the aggregate that widens by
191+
itself: its result is a string of unlimited length.
192+
String concatenation widens as well, summing the
193+
operands' lengths: `ISTRING[200] + ISTRING[126]`
194+
is `ISTRING[326]`.
195+
196+
A narrower class is obtained only by an explicit cast of
197+
the whole expression. With operands of integer classes
198+
the operand cast of rule 16 does not bound the result —
199+
the division still widens to scale `32` — so both casts
200+
are needed: `NUMERIC[16,2](NUMERIC[16,2](a(x)) / b(x))`.
201+
202+
18. A parameter's class annotation (`prop(SubClass x)`) is a
168203
signature, not a runtime filter: it resolves same-named
169204
properties and sets the signature, but the computed set is
170205
determined by the properties used in the expression.
@@ -176,7 +211,7 @@ title: 'Rules: domain logic'
176211
an explicit `x IS SubClass` condition (or use a property
177212
declared on that subclass).
178213

179-
18. In the `GROUP ... BY` operator the assistant MUST NOT
214+
19. In the `GROUP ... BY` operator the assistant MUST NOT
180215
list in the `BY` block the upper parameters used
181216
in the operator's expressions: each such parameter
182217
is already implicitly a group — a parameter of the
@@ -187,7 +222,7 @@ title: 'Rules: domain logic'
187222
to the parameters not used in the expressions;
188223
a mismatch in count or classes is an error.
189224

190-
19. `MAX` and `MIN` are prefix operators over a comma-separated
225+
20. `MAX` and `MIN` are prefix operators over a comma-separated
191226
operand list (`MAX a, b`), not infix ones: `a MAX b`
192227
does not parse — the platform reports
193228
`no viable alternative at input 'MAX'`.
@@ -212,42 +247,13 @@ title: 'Rules: domain logic'
212247
`specified` and `expected` lines name the implementation's
213248
class and the declared one.
214249

215-
Arithmetic is what widens the class most often, and it
216-
widens further than it looks:
217-
218-
- `+` and `-` — like `MIN` / `MAX` and the selection
219-
operators — take the common ancestor, widening the whole
220-
part and the scale independently, so the result can be
221-
wider than either operand:
222-
`NUMERIC[16,2] + NUMERIC[10,4]` is `NUMERIC[18,4]`;
223-
- `*` adds both the whole parts and the scales:
224-
`NUMERIC[16,2] * NUMERIC[10,4]` is `NUMERIC[26,6]`;
225-
- `/` widens catastrophically: with the default settings
226-
its scale is always the maximum `NUMERIC` scale (`32`),
227-
so `NUMERIC[16,2] / NUMERIC[16,2]` is `NUMERIC[48,32]`.
228-
229-
A `GROUP` aggregate mostly keeps the class of what it
230-
aggregates — a `GROUP SUM`, `GROUP MAX` or `GROUP LAST`
231-
over a `NUMERIC[16,2]` is `NUMERIC[16,2]` — but it carries
232-
outward whatever that expression already widened to.
233-
`GROUP CONCAT` is the aggregate that widens by itself: its
234-
result is a string of unlimited length (`ISTRING` against
235-
a declared `ISTRING[250]`). Plain string concatenation
236-
widens as well, summing the operands' lengths
237-
(`ISTRING[326]` against a declared `ISTRING[250]`).
238-
239-
Any such expression the assistant MUST wrap in an explicit
250+
An expression that widens the value class — arithmetic
251+
above all, and division most of all (rule 17 of the
252+
property rules) — the assistant MUST wrap in an explicit
240253
cast to the declared class:
241254
`f(X x) += NUMERIC[16,2](a(x) / b(x));`
242255
`f(X x) += ISTRING[250](a(x) + b(x));`
243256

244-
For operands of integer classes the cast MUST go on an
245-
operand first, so that the division is not integer
246-
division (see rule 16 of the property rules); the result
247-
still widens to scale `32` like any other division, so
248-
the outer cast is needed as well:
249-
`f(X x) += NUMERIC[16,2](NUMERIC[16,2](a(x)) / b(x));`
250-
251257
### Ordering rules (`ORDER`)
252258

253259
1. Where two rows can share an order key and the answer depends

docs/rules/ru/Rules.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,17 @@ D. ОБРАТНАЯ СВЯЗЬ / ОТЧЁТЫ (`lsfusion_report_feedback`)
248248
строкового литерала в lsFusion и НЕ ДОЛЖНЫ использоваться.
249249

250250
4. Выражение, чья запятая НЕ заключена в собственные скобки —
251-
`OVERRIDE a, b`, `CONCAT sep, a, b`, `GROUP CONCAT expr, sep`
252-
НЕ ДОЛЖНО попадать прямо в список с разделением запятыми
253-
(`PROPERTIES`, `EXPORT FROM`, `JSON FROM`, `ORDER`, списки
254-
групп объектов и параметров): эта запятая читается как
255-
разделитель списка, и список молча перекраивается.
251+
`OVERRIDE a, b`, `CONCAT sep, a, b`, `GROUP CONCAT expr, sep`,
252+
`MAX a, b` — НЕ ДОЛЖНО попадать прямо в список
253+
с разделением запятыми (`PROPERTIES`, `EXPORT FROM`,
254+
`JSON FROM`, `ORDER`, списки групп объектов и параметров):
255+
эта запятая читается как разделитель списка,
256+
и список молча перекраивается.
256257
Сгруппируйте его или назовите свойством — той формой, какую
257-
принимает внешний блок. Запятая внутри собственных скобок
258-
обычного вызова безопасна.
258+
принимает внешний блок. Собственные запятые вызова —
259+
`f(a, b)` — во внешнем списке безопасны, но не отгораживают
260+
такое выражение, помещённое внутрь них: `f(MAX a, b)`
261+
передаёт один аргумент, а не два.
259262

260263
5. Вводя новый параметр, ассистент ОБЯЗАН задавать его
261264
класс явно при первом использовании (`prop(Class x)`,

docs/rules/ru/Rules_logic.md

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,42 @@ title: 'Rules: domain logic'
163163
молча отбрасывает дробную часть;
164164
правильная форма — `NUMERIC[16,4](a) * b / c`.
165165

166-
17. Класс в объявлении параметра (`prop(SubClass x)`) — это
166+
17. Класс результата выражения может оказаться шире классов,
167+
из которых оно построено, и ассистент ОБЯЗАН учитывать
168+
это везде, где требуется более узкий класс, — прежде
169+
всего в реализации `+=`, где это ошибка старта сервера.
170+
171+
Арифметика расширяет класс сильнее, чем кажется:
172+
173+
- `+` и `-` — как `MIN` / `MAX` и операторы выбора —
174+
дают общего предка, расширяя целую часть и шкалу
175+
независимо, поэтому результат может оказаться шире
176+
любого из операндов:
177+
`NUMERIC[16,2] + NUMERIC[10,4]` — это `NUMERIC[18,4]`;
178+
- `*` складывает и целые части, и шкалы:
179+
`NUMERIC[16,2] * NUMERIC[10,4]` — это `NUMERIC[26,6]`;
180+
- `/` расширяет катастрофически: при настройках
181+
по умолчанию его шкала всегда равна максимальной шкале
182+
`NUMERIC` (`32`), поэтому
183+
`NUMERIC[16,2] / NUMERIC[16,2]` — это `NUMERIC[48,32]`.
184+
185+
Агрегат `GROUP` в основном сохраняет класс того, что
186+
агрегирует, — `GROUP SUM`, `GROUP MAX` или `GROUP LAST`
187+
по `NUMERIC[16,2]` дают `NUMERIC[16,2]`, — но выносит
188+
наружу то, до чего расширилось агрегируемое выражение.
189+
Сам по себе расширяет `GROUP CONCAT`: его результат —
190+
строка неограниченной длины. Конкатенация строк тоже
191+
расширяет, складывая длины операндов:
192+
`ISTRING[200] + ISTRING[126]` — это `ISTRING[326]`.
193+
194+
Более узкий класс получается только явным приведением
195+
всего выражения. Для операндов целочисленных классов
196+
приведение операнда из правила 16 не ограничивает
197+
результат (деление всё равно расширяется до шкалы `32`),
198+
поэтому нужны оба приведения:
199+
`NUMERIC[16,2](NUMERIC[16,2](a(x)) / b(x))`.
200+
201+
18. Класс в объявлении параметра (`prop(SubClass x)`) — это
167202
сигнатура, а не фильтр времени выполнения: он разрешает
168203
одноимённые свойства и задаёт сигнатуру, но вычисляемое
169204
множество определяется свойствами, использованными
@@ -176,7 +211,7 @@ title: 'Rules: domain logic'
176211
добавить явное условие `x IS SubClass` (или использовать
177212
свойство, объявленное на этом классе-потомке).
178213

179-
18. В операторе `GROUP ... BY` ассистент НЕ ДОЛЖЕН
214+
19. В операторе `GROUP ... BY` ассистент НЕ ДОЛЖЕН
180215
перечислять в блоке `BY` верхние параметры,
181216
использованные в выражениях оператора: каждый такой
182217
параметр уже неявно является группировкой — параметром
@@ -188,7 +223,7 @@ title: 'Rules: domain logic'
188223
не использованные в выражениях; несовпадение
189224
количества или классов даёт ошибку.
190225

191-
19. `MAX` и `MIN` — префиксные операторы над списком
226+
20. `MAX` и `MIN` — префиксные операторы над списком
192227
операндов через запятую (`MAX a, b`), а не инфиксные:
193228
`a MAX b` не разбирается — платформа выдаёт
194229
`no viable alternative at input 'MAX'`.
@@ -214,43 +249,13 @@ title: 'Rules: domain logic'
214249
`specified` и `expected` которой указаны класс реализации
215250
и объявленный класс.
216251

217-
Чаще всего класс расширяет арифметика, причём сильнее,
218-
чем кажется:
219-
220-
- `+` и `-` — как `MIN` / `MAX` и операторы выбора —
221-
дают общего предка, расширяя целую часть и шкалу
222-
независимо, поэтому результат может оказаться шире
223-
любого из операндов:
224-
`NUMERIC[16,2] + NUMERIC[10,4]` — это `NUMERIC[18,4]`;
225-
- `*` складывает и целые части, и шкалы:
226-
`NUMERIC[16,2] * NUMERIC[10,4]` — это `NUMERIC[26,6]`;
227-
- `/` расширяет катастрофически: при настройках
228-
по умолчанию его шкала всегда равна максимальной
229-
шкале `NUMERIC` (`32`), поэтому
230-
`NUMERIC[16,2] / NUMERIC[16,2]` — это `NUMERIC[48,32]`.
231-
232-
Агрегат `GROUP` в основном сохраняет класс того, что
233-
агрегирует, — `GROUP SUM`, `GROUP MAX` или `GROUP LAST`
234-
по `NUMERIC[16,2]` дают `NUMERIC[16,2]`, — но выносит
235-
наружу то, до чего расширилось агрегируемое выражение.
236-
Сам по себе расширяет `GROUP CONCAT`: его результат —
237-
строка неограниченной длины (`ISTRING` при объявленном
238-
`ISTRING[250]`). Обычная конкатенация строк тоже
239-
расширяет, складывая длины операндов (`ISTRING[326]`
240-
при объявленном `ISTRING[250]`).
241-
242-
Любое такое выражение ассистент ОБЯЗАН обернуть в явное
243-
приведение к объявленному классу:
252+
Выражение, расширяющее класс значения, — прежде всего
253+
арифметику, и в первую очередь деление (правило 17 правил
254+
свойств), — ассистент ОБЯЗАН обернуть в явное приведение
255+
к объявленному классу:
244256
`f(X x) += NUMERIC[16,2](a(x) / b(x));`
245257
`f(X x) += ISTRING[250](a(x) + b(x));`
246258

247-
Для операндов целочисленных классов приведение ОБЯЗАНО
248-
сначала стоять на операнде, чтобы деление не оказалось
249-
целочисленным (см. правило 16 правил свойств); результат
250-
при этом всё равно расширяется до шкалы `32`, как любое
251-
деление, поэтому внешнее приведение тоже нужно:
252-
`f(X x) += NUMERIC[16,2](NUMERIC[16,2](a(x)) / b(x));`
253-
254259
### Правила упорядочивания (`ORDER`)
255260

256261
1. Там, где две строки могут разделить ключ порядка, а ответ

0 commit comments

Comments
 (0)