liveBook · Manning

Initial value

As explained in Building User-Friendly DSLs

An initial value is an optional expression-specified value assigned to an attribute when a new record is created.

An initial value is an optional expression on a data attribute. When a record is created, the expression supplies that attribute’s starting value. For example, a rental’s price before discount can start at 0.0 and its discount at 0; an attribute without an initial value receives no such specification. section 1.2.1 section 3.1.1

In the AST, an initial value is a contained object held by the attribute’s "initial value" setting. The attribute refers to that object rather than inlining it, so the value remains a distinct expression node with its own concept and settings. section 3.1.1

const rentalPriceBeforeDiscountInitialValue = {   #1
    concept: "Number",
    settings: {
        "value": "0.0"
    }
}
const rentalPriceBeforeDiscountAttribute = {
    concept: "Data Attribute",
    settings: {
        "name": "rental price before discount",
        "type": "amount",
        "initial value":
             rentalPriceBeforeDiscountInitialValue     #2
    }
}

const discountInitialValue = {
    concept: "Number",
    settings: {
        "value": "0"
    }
}
const discountAttribute = {
    concept: "Data Attribute",
    settings: {
        "name": "discount",
        "type": "percentage",
        "initial value": discountInitialValue
    }
}

This listing encodes two initial-value objects and attaches them to amount and percentage attributes through the "initial value" setting. section 3.1.1

An editable projection handles the optional value in three stages:

  • Show a “+ initial value” action only when the attribute has none; clicking it stores a placeholder that records the intent to provide one. section 6.1.2
  • Replace the placeholder by choosing an allowed expression concept: Attribute Reference or Number. section 6.1.2
  • Project the chosen expression normally, allowing its own value or referenced attribute to be edited. section 6.1.2

Removal belongs to the containing attribute, not to the initial-value object itself. When a selected initial-value object receives Backspace or Delete, its parent supplies a callback that deletes the "initial value" property. This preserves the distinction between no value and an expression-valued setting. section 6.3.1

Initializing a discount for rule effects

A discount attribute specified initially as 0% can initialize the runtime discount variable before business-rule consequences increment it. Increment effects therefore require the affected attribute to have an initial value. section 14.2.2

Structure changes can require migration. Renaming the Data Attribute concept to Attribute and its "initial value" property to "value" is performed by a depth-first traversal that updates matching AST objects. section 10.3.2

How Building User-Friendly DSLs covers it

How deep it goes
Works through AST containment, projection editing, deletion callbacks, migration, and a runtime initialization constraint.
Examples
Uses Rental attributes for price and discount, a 0% discount variable, and a rename from initial value to value.
What it assumes
Assumes JavaScript, React, and AST objects while introducing placeholder-based editing and containment-aware deletion.
What you can do after
Build it from scratch by encoding, editing, deleting, and migrating optional initial-value AST objects.
How it connects
Connects Data Attribute, Record Type, AST, Attribute Reference, Number, Projection, business rules, and AST migration.

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.