Variables and Data Types
Variables let a program keep values and refer to them later by name. A value might be a number, a piece of text, a true/false answer, a list, or a record containing named fields. For example, an invoice can be a record whose amount and status fields are read separately.
This page explains how to create those values, read their contents, and update fields. Read Syntax Basics first for the meaning of equals and multi-word names. Expression snippets show the value being described; use them after equals, Print, or Respond with in a program.
Primitive Types
Section titled “Primitive Types”# Numbers (integers and floating-point values)count equals 42rate equals 0.15
# Strings (double-quoted)name equals "Solar Project Alpha"
# Booleansis_active equals truehas_errors equals false
# Nulllegacy_field equals nilVariable Naming
Section titled “Variable Naming”Write multi-word names naturally. Devlish normalizes them to snake_case.
contract value equals 500000# Internally stored as contract_value
total exposure equals contract_value plus deductibleFor extracted variables, use explicit snake_case in save as:
Find liability cap and save as liability_capRecords
Section titled “Records”Create structured data with named fields using record with.
record with 1200 as amount and "pending" as statusrecord with "Solar Farm" as name and 5000000 as value and true as activeCreate ordered collections with list of.
list of "approved", "pending", and "rejected"list of 85, 92, 78, and 95Accessing Record Fields
Section titled “Accessing Record Fields”Use field of record syntax to read a field value.
amount of invoicename of projectNested access chains naturally:
city of address of customerMissing fields return nil rather than causing an error.
Setting Record Fields
Section titled “Setting Record Fields”Use Set to mutate a field in place.
Set amount of invoice to 1300Set status of project to "complete"Nested updates create intermediate records if they do not exist:
Set city of address of customer to "Austin"Record Keys and Values
Section titled “Record Keys and Values”Extract structure from records:
keys of invoicevalues of invoiceentries of invoiceRecord Shape Validation
Section titled “Record Shape Validation”Check that a record has expected fields or matches a type shape:
Require invoice has fields amount, customer
invoice_shape equals record with "number" as amount and "text" as customerRequire invoice matches shape invoice_shapeShape values use type names: text, number, boolean, list, record, any.
Type Checking
Section titled “Type Checking”Inspect the type of any value at runtime:
type of invoice# Returns "record", "list", "number", "text", "boolean", or "null"