Part I — Foundations · Chapter 5 · Lesson 1 of 5 · 10 min read
Lesson 1: null, Booleans, Numbers, Strings, Lists, and String-Keyed Maps
Lesson level: Foundation
Purpose: Build a precise mental model of PeaLang's core portable values and choose representations that make data meaning, absence, and structure explicit.
Learning objectives
By the end of this lesson, you should be able to:
- distinguish null from false, zero, and empty values;
- use booleans for explicit two-state facts;
- reason about integers and floating-point values;
- create and interpret strings;
- represent ordered data with lists;
- represent named fields with string-keyed maps;
- recognize nested portable structures;
- choose a suitable value shape for a domain concept; and
- validate values before relying on their contents.
1. Core values form the portable boundary
PeaLang's portable data model consists of null, booleans, integers, floating-point numbers, strings, lists, and string-keyed maps. These values can be passed between PeaLang and supported hosts without exposing host-specific objects.
Lists and maps can contain other portable values, allowing nested records and sequences. A boundary remains portable only when every nested value is portable.
2. null represents absence
The value null represents no value or an unavailable result. It is not the same as false, zero, an empty string, an empty list, or an empty map.
let assigned_agent = null if assigned_agent == null { print "No agent assigned" }
Use null only when absence is meaningful and expected. Document whether a field or function result may be null, and check it before using operations that require a present value.
3. Absence versus emptiness
- null — no value is present;
- false — a present boolean fact is negative;
- 0 — a present numeric value equals zero;
- "" — a present string contains no characters;
- [] — a present list contains no items; and
- {} — a present map contains no entries.
These states can carry different domain meaning. An absent response time differs from a measured response time of zero.
4. Booleans represent explicit facts
The values true and false represent two-state facts. Comparisons and equality tests also produce booleans.
let security_relevant = false let has_affected_users = affected_users > 0 let is_gold_customer = customer_tier == "gold"
Choose positive, question-like names such as is_active, has_discount, or requires_review. Avoid confusing double negatives.
5. Truthiness is broader than booleans
Conditions interpret values by truthiness, but a truthy value is not necessarily the boolean true. For domain rules, prefer explicit comparisons when the value itself has meaning.
if affected_users > 0 { print "Users are affected" }
This is clearer than relying on the numeric value directly as a condition.
6. Integers
Integers represent whole numbers such as counts, indices, thresholds, and identifiers that are genuinely numeric.
let quantity = 3 let affected_users = 125 let retry_count = 0
Use integers for discrete values. Do not use a number for a code that must preserve leading zeros or is never used arithmetically; use a string instead.
7. Floating-point numbers
Floating-point values represent numbers with fractional parts, such as rates, measurements, and calculated amounts.
let unit_price = 12.5 let tax_rate = 0.18 let confidence = 0.875
Printed integral floats omit the trailing decimal part, so 12.0 may appear as 12. Do not infer the original literal spelling from printed text.
8. Numeric operations
Numbers support arithmetic, comparisons, and unary minus. Validate before dividing and make units visible in names.
let subtotal_amount = unit_price * quantity let average_score = total_score / item_count let within_limit = memory_mb <= max_memory_mb
Mixed integer and floating-point calculations can produce floating-point results. Test the actual numeric behavior rather than assuming text formatting or host-language rules.
9. Floating-point precision
Binary floating-point arithmetic may produce small representation differences. For derived measurements and round trips, compare against a documented tolerance rather than requiring identical decimal text.
For money-like examples in this foundational chapter, keep formulas explicit and avoid claiming accounting-grade decimal guarantees. A production contract should define precision, rounding, and currency policy deliberately.
10. Numeric validation
- Check nonnegative amounts before calculations.
- Check positive divisors before division.
- Check rates against an approved interval.
- Check counts against realistic bounds.
- Keep units consistent across operations.
- Test below, exact, and above threshold values.
11. Strings represent text
Strings are sequences of characters written with matching single or double quotation marks. Use them for names, labels, reason codes, identifiers, messages, and textual categories.
let customer_tier = "gold" let case_id = "CASE-1042" let reason_code = "IMPACT"
A quoted number such as "00125" remains text and preserves leading zeros. An unquoted 125 is numeric and supports arithmetic.
12. String equality and categories
String equality is exact and case-sensitive. Normalize external categories at a trusted boundary when the contract permits it, or require one canonical spelling.
if customer_tier == "gold" { print "Gold policy applies" }
Stable categories and reason codes should be documented. A misspelled category may be syntactically valid but semantically unsupported.
13. Interpolation and text conversion
Interpolated strings embed expressions inside braces:
print "Case {case_id}: {affected_users} affected users"
The expression result is converted to text. Keep complex calculations outside the string when a named intermediate improves clarity. Use doubled braces for literal brace output.
14. Strings are not structured records
A string such as "CASE-1042|gold|6" may look compact, but its fields and validation rules are hidden. Use a map when values have names, and use a list when values form an ordered collection.
Do not build machine interfaces from ad hoc printed text unless the protocol explicitly defines parsing and escaping rules.
15. Safe string handling
- Do not place secrets in source or output.
- Mask sensitive identifiers when full values are unnecessary.
- Distinguish human messages from stable codes.
- Validate approved categories.
- Preserve identifiers as strings when arithmetic is irrelevant.
- Keep protocol traffic separate from ordinary output.
16. Lists represent ordered collections
A list stores values in sequence order. Use it when position or traversal order matters and items share one conceptual role.
let scores = [8, 9, 10] let priorities = ["low", "medium", "high"] let mixed = ["CASE-1", 6, false, null]
PeaLang lists can contain different portable value categories, but homogeneous lists are often easier to validate and process.
17. Empty and nested lists
An empty list is present but contains no items:
let warnings = []
Lists can contain lists or maps:
let rows = [["A", 10], ["B", 20]] let cases = [{"id": "CASE-1"}, {"id": "CASE-2"}]
Nested structures remain portable when every nested value is portable.
18. String-keyed maps represent records
A map associates string keys with values. Use it when fields have names or when a portable record must cross a host boundary.
let case = { "id": "CASE-1042", "customer_tier": "gold", "service_impact": 6, "security_relevant": false }
Keys express field meaning. Values may be any portable value, including nested lists and maps.
19. Stable map contracts
A map is flexible, but a reusable interface still needs a schema-like contract: required keys, optional keys, allowed value categories, nullability, units, and invariants.
Do not access a required field before verifying that the expected key is present through supported map operations. A missing-key failure should be distinguished from a present key whose value is null.
20. Lists versus maps
- Use a list for ordered items with the same conceptual role.
- Use a map for named fields in one record.
- Use a list of maps for ordered records.
- Use a map of lists when each named field owns a sequence.
- Avoid positional lists for records when readers must remember what each index means.
21. Nested portable example
let report = { "case_id": "CASE-1042", "valid": true, "scores": [20, 15, 10], "decision": { "priority": "medium", "response_minutes": 240 }, "note": null }
This structure combines every core value category except a floating-point number. It can remain portable across supported host boundaries because all keys are strings and all nested values are portable.
22. Validate shape before content
Validation should proceed from broad structure to specific meaning:
- Confirm that a required value is present rather than null.
- Confirm the expected value category or collection shape.
- Confirm required map keys or list positions.
- Validate ranges, categories, and units.
- Validate relationships between fields.
This ordering prevents later checks from assuming structure that has not been established.
23. Equality and semantic meaning
Equality asks whether values compare equal according to the language's value rules. A later lesson examines collection equality, copying, and mutation in depth. At this stage, distinguish equality from identity and from domain equivalence.
For example, two different textual spellings may refer to the same business category only if the contract defines normalization. Two floating-point calculations may be close enough for a tolerance even when their exact representations differ.
24. Choosing a representation
- Use null for documented absence.
- Use a boolean for one explicit two-state fact.
- Use an integer for discrete numeric quantities.
- Use a float for fractional numeric values under an explicit precision policy.
- Use a string for text, categories, labels, and non-arithmetic identifiers.
- Use a list for ordered items.
- Use a string-keyed map for named fields.
- Combine lists and maps for nested portable structures.
25. Common mistakes
- Using null as a universal error. Callers cannot distinguish absence from several failure causes.
- Confusing false with null. A negative fact differs from no fact.
- Using zero for missing data. Zero may be a valid measured value.
- Using floats without a precision policy. Exact text comparisons become fragile.
- Using numbers for textual identifiers. Leading zeros and formatting are lost.
- Using a positional list as a record. Field meaning becomes implicit.
- Using a map without a contract. Missing or inconsistent keys become runtime defects.
- Accessing a map field before checking its presence. Missing-key failures occur before validation can respond.
- Mixing unrelated value categories in one list. Every consumer needs extra branching.
- Passing host-specific objects through a portable boundary. Portability and isolation are broken.
Guided practice
- Explain the difference between null, false, 0, "", [], and {}.
- Choose integer, float, or string for an employee number, tax rate, retry count, and currency code.
- Write boolean names for account status, approval, and required review.
- Represent three ordered scores as a list.
- Represent a support case as a map with named fields.
- Convert a positional record list into a string-keyed map.
- Create a list of two case maps.
- Identify which nested values make a structure portable.
- Write validation steps for a nullable map field.
- Explain when a floating-point tolerance is more appropriate than exact equality.
Hands-on lab: Build a portable case-record validator
Scenario. Create a source-defined support-case record and validate its core value shape before using it.
Record fields
- case_id — nonempty string;
- customer_tier — approved string category;
- service_impact — integer from 0 through 10;
- affected_users — nonnegative integer;
- security_relevant — boolean;
- tags — list of strings;
- metrics — map containing numeric response and confidence values; and
- assigned_agent — string or null.
Requirements
- Create a valid nested map using only portable values.
- Validate required key presence before field access using supported map operations.
- Distinguish a missing assigned_agent key from a present key with null.
- Validate category values and numeric ranges.
- Validate every tag as a string.
- Return one result map containing validity, stable reason code, and a safe summary.
- Keep the validator free of printing.
- Print the result separately.
Test variants
- valid record;
- missing required key;
- null required value;
- invalid tier;
- impact below and above range;
- negative affected-user count;
- wrong tag value category;
- empty tags list;
- assigned agent null; and
- nested metrics with an invalid rate.
Deliverable. Submit the valid record, validation functions, result contract, test matrix, output, and a representation rationale for every field.
Review questions
- Which value categories form PeaLang's portable data model?
- How does null differ from false and zero?
- Why are explicit boolean conditions often clearer than truthiness?
- When should a whole number be stored as a string rather than an integer?
- Why can floating-point calculations require a tolerance?
- What kinds of values are appropriate for strings?
- When is a list preferable to a map?
- When is a map preferable to a positional list?
- What makes a nested structure portable?
- Why must required map keys be checked before access?
- How does a missing key differ from a key whose value is null?
- In what order should structural and semantic validation occur?
Applied challenge: Portable order payload
Design a portable order payload containing an order identifier, customer record, list of line-item maps, nullable promotion code, monetary summary, boolean flags, and validation metadata. Use only null, booleans, numbers, strings, lists, and string-keyed maps.
Write a representation rationale, required-key contract, nullability rules, units, approved categories, and invariants. Create valid, empty, boundary, malformed, and missing-field cases. Validate shape before content and return a complete portable validation result.
Success criteria
- Every field uses a representation suited to its meaning.
- Textual identifiers remain strings.
- Absence is distinct from empty or zero values.
- Lists represent ordered items; maps represent named records.
- All nested values remain portable.
- Required fields are checked before access.
- Numeric units and ranges are explicit.
- Validation results use stable reason codes.
Lesson summary
PeaLang's core portable values are null, booleans, integers, floating-point numbers, strings, lists, and string-keyed maps. Reliable programs distinguish absence from empty or false values, make numeric units and precision explicit, use strings for text and non-arithmetic identifiers, represent order with lists, represent named records with maps, and validate structure before content. Nested collections remain portable only when every contained value is portable.
Next lesson: Indexing, Slicing, Mutation, Copying, and Equality
Lesson status: Approved.