liveBook · Manning

Boolean

As explained in Building User-Friendly DSLs

A value or type with one of two truth values, true or false.

A boolean is a value or type with two truth values: true and false. Logical expressions produce boolean values, making them suitable for controlling business-rule conditions. section 14.1.1 section 14.4

Implementing boolean support in a DSL involves:

  • Registering boolean as a built-in type and rendering its type name as boolean. section 14.1.1
  • Type-checking each business-rule condition and reporting an issue when it does not produce a boolean. section 14.1.1
  • Requiring both the condition and consequence properties on every business rule. section 14.1.1

Boolean business-rule condition

A business rule follows the form “when <condition>, then <consequence>.” The condition must be a logical expression whose computed type is boolean; the consequence specifies a value change or other effect. section 14.4

Listing 14.1 Migration to add a business rules property
const addBusinessRulesProperty = (recordType) => {
    if (!Array.isArray(                               #1
             recordType.settings["business rules"])) {
        recordType.settings["business rules"] = []   #2
    }
    return recordType
}

// ...run migration from v1 -> v2 if necessary...
doMigration("v2", "v3", addBusinessRulesProperty)   #3

Use the built-in-type implementation as a concrete reference for registering boolean and converting its internal type representation to boolean. section 14.1.1

How Building User-Friendly DSLs covers it

How deep it goes
Defines the type, registers it, and type-checks rule conditions, but does not implement logical-expression evaluation.
Examples
Uses a built-in boolean type and a business-rule condition checked against that type.
What you can do after
Build it from scratch by adding boolean type registration and validating business-rule conditions against it.
How it connects
Connects boolean values to logical expressions, type checking, AST objects, and business rules.

Also explained in

Compare how 11 books explain boolean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.