Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Библиотека · std.typeset

    BreakRule.Allowed

    Creates a selectable boundary with a signed preference.

    BreakRule.Allowed(int)
    Модуль
    std.typeset →
    Получатель
    Неприменимо
    Минимальное число аргументов
    1
    Максимальное число аргументов
    1

    Declaration and parameters

    Ссылка

    Доступность

    Включено по умолчанию · Не определено

    Import std.typeset in language mode 5.21.

    The current compiler selects std/typeset.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.

    Получатель

    Ограничения параметров

    Allowed carries an int preference for a selectable penalty. Negative values favor a break and positive values discourage it under the selected cost model. Zero is neutral. Every representable int remains an Allowed value rather than becoming a hard rule at a numeric threshold.

    Forced requires every successful paragraph plan to end a line at that boundary. A plan cannot cross it or omit it to improve cost. If the required line cannot be admitted, planning returns the applicable TypesetError instead of ignoring the constraint.

    Forbidden makes that penalty unselectable. It is not represented by a large Allowed preference. Penalty validation and duplicate-boundary rules determine the treatment of caller-supplied penalties at the same position.

    BreakKind records a category and BreakRule records a planning constraint. Selecting a kind does not turn an Allowed penalty into Forced or Forbidden. The selected cost model interprets the Allowed preference and preserves both hard rules.

    Constructing a rule creates an enum value and has no I/O or mutation. Allowed requires an int payload. An argument of another type is rejected with TPZ5001.

    Результат

    Эффекты

    Ошибки

    Result and effects

    Ссылка

    The int payload contributes according to the selected cost model. A negative value favors selection and a positive value discourages it. Numeric magnitudes do not turn this variant into Forced or Forbidden.

    Resolved contracts

    Ссылка

    Related entries

    Ссылка

    std.typeset →

    Express preference, mandatory breaks, and forbidden breaks explicitly

    Ссылка
    Правилоtopaz.stdlib.contract.typeset-break-rules.rule

    Express preference, mandatory breaks, and forbidden breaks explicitly

    Allowed carries an int preference for a selectable penalty. Negative values favor a break and positive values discourage it under the selected cost model. Zero is neutral. Every representable int remains an Allowed value rather than becoming a hard rule at a numeric threshold.

    Forced requires every successful paragraph plan to end a line at that boundary. A plan cannot cross it or omit it to improve cost. If the required line cannot be admitted, planning returns the applicable TypesetError instead of ignoring the constraint.

    Forbidden makes that penalty unselectable. It is not represented by a large Allowed preference. Penalty validation and duplicate-boundary rules determine the treatment of caller-supplied penalties at the same position.

    BreakKind records a category and BreakRule records a planning constraint. Selecting a kind does not turn an Allowed penalty into Forced or Forbidden. The selected cost model interprets the Allowed preference and preserves both hard rules.

    Constructing a rule creates an enum value and has no I/O or mutation. Allowed requires an int payload. An argument of another type is rejected with TPZ5001.

    Причина

    An explicit variant makes a hard constraint independent of scoring scale. Callers can change the cost model without changing the meaning of a mandatory or forbidden break. Signed preferences remain a separate choice about plan quality.

    Keep signed penalty preferences distinct from hard break rules

    Ссылка
    main.tpzKeep signed penalty preferences distinct from hard break rulesОткрыть песочницу →
    1. import std.typeset as ts
    2. import std.io
    3. import std.test
    4. let rules = [ts.BreakRule.Allowed(-10000), ts.BreakRule.Allowed(0), ts.BreakRule.Allowed(10000)]
    5. for rule in (rules) {
    6. match (rule) {
    7. case Allowed(value) => io.writeLine("{value}")
    8. case _ => io.writeLine("unexpected rule")
    9. }
    10. }
    Ожидаемый выводКод завершения 0
    -10000
    0
    10000
    
    $ topaz run main.tpz · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. -10000
    2. 0
    3. 10000

    Reject a noninteger break preference

    Ссылка
    main.tpzReject a noninteger break preferenceОткрыть песочницу →
    1. import std.typeset as ts
    2. let rule = ts.BreakRule.Allowed("avoid")
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check main.tpz --format json · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5001 →

      stdlib-break-rule-requires-integer at main.tpz:2:33

    Diagnostics

    Ссылка

    TPZ5001 →

    Меню

    Загрузка →