PeaBox Lab › PeaLang › Learn › Chapter 1 › Lesson 5

Part I — Foundations · Chapter 1 · Lesson 5 of 5 · 6 min read

Chapter 1 Checkpoint: Build and Run a Small Command-Line Rules Program

Checkpoint level: Foundation

Purpose: Integrate Chapter 1 skills into one repeatable PeaLang workflow without introducing functions, loops, modules, or external capabilities.

Checkpoint outcomes

By completing this checkpoint, you will demonstrate that you can:

Project scenario: Support-case priority and response target

A support team needs a small command-line rules program that recommends a priority and response target for a case. The first version uses values declared at the top of the source file rather than interactive input. This keeps the checkpoint focused on language execution and disciplined testing.

The policy is:

1C.1 Required inputs

Declare these values at the beginning of case_priority.pea:

NameMeaningExample
case_idReadable case identifier"CASE-1042"
customer_tierCustomer service tier"gold"
service_impactImpact score from 0 through 106
affected_usersNumber of affected users25
security_relevantWhether the case concerns securityfalse

Use const for policy thresholds and response targets. Use let for scenario inputs and calculated outputs that you will change while testing.

1C.2 Required outputs

The program must print labeled lines for:

Reason codes make the decision traceable. Use SECURITY, IMPACT, USER_COUNT, GOLD_IMPACT, or DEFAULT according to the rule that wins.

1C.3 Implementation constraints

1C.4 Acceptance criteria

1C.5 Reference implementation

Attempt the project independently before comparing your work with this reference.

const critical_minutes = 15
const high_minutes = 60
const medium_minutes = 240
const low_minutes = 480
const high_impact_threshold = 8
const user_threshold = 100
const gold_impact_threshold = 5
let case_id = "CASE-1042"
let customer_tier = "gold"
let service_impact = 6
let affected_users = 25
let security_relevant = false
let priority = "low"
let response_minutes = low_minutes
let reason_code = "DEFAULT"
if security_relevant {
    priority = "critical"
    response_minutes = critical_minutes
    reason_code = "SECURITY"
} else if service_impact >= high_impact_threshold {
    priority = "high"
    response_minutes = high_minutes
    reason_code = "IMPACT"
} else if affected_users >= user_threshold {
    priority = "high"
    response_minutes = high_minutes
    reason_code = "USER_COUNT"
} else if customer_tier == "gold" and service_impact >= gold_impact_threshold {
    priority = "medium"
    response_minutes = medium_minutes
    reason_code = "GOLD_IMPACT"
} else {
    priority = "low"
    response_minutes = low_minutes
    reason_code = "DEFAULT"
}
print "Case: {case_id}"
print "Customer tier: {customer_tier}"
print "Service impact: {service_impact}"
print "Affected users: {affected_users}"
print "Security relevant: {security_relevant}"
print "Priority: {priority}"
print "Response target: {response_minutes} minutes"
print "Reason: {reason_code}"

1C.6 Why the order matters

The chain stops at the first true condition. A security case may also have high impact and many affected users, but the security rule appears first and therefore wins. This is policy precedence expressed through control-flow order.

The program initializes outputs to the default decision before entering the rule chain. Every branch then sets priority, response target, and reason code together. Updating the three outputs as one decision prevents mismatched results such as high priority with a low-priority target.

The final else branch repeats the defaults for clarity. In a larger program, tests should protect this invariant: every path must produce a complete and internally consistent decision.

1C.7 Expected result for the reference inputs

The reference inputs describe a gold-tier customer, service impact 6, 25 affected users, and no security relevance. The first three rules are false. The gold-and-impact rule is true, so the expected decision is:

Case: CASE-1042
Customer tier: gold
Service impact: 6
Affected users: 25
Security relevant: false
Priority: medium
Response target: 240 minutes
Reason: GOLD_IMPACT

1C.8 Required test matrix

CaseTierImpactUsersSecurityExpected decision
Astandard25falselow, 480, DEFAULT
Bgold520falsemedium, 240, GOLD_IMPACT
Cstandard810falsehigh, 60, IMPACT
Dstandard4100falsehigh, 60, USER_COUNT
Egold9150truecritical, 15, SECURITY
Fgold8100falsehigh, 60, IMPACT

Cases B, C, and D test exact thresholds. Cases E and F test precedence by making more than one condition true.

1C.9 Validation workflow

For each test case:

If a test fails, trace conditions from top to bottom. Stop at the first true condition, then confirm that all three output variables receive their matching values.

1C.10 Debugging requirement

Introduce one temporary defect, such as changing an exact-threshold comparison from >= to >. Confirm that the corresponding boundary test fails. Restore the correct operator and rerun the test.

Optionally start a debug session with a breakpoint on the first conditional line. Record the state needed to explain why the selected branch runs. Remove the temporary defect before submission.

1C.11 Submission package

1C.12 Assessment rubric

AreaEvidence of mastery
CorrectnessAll policy branches and expected outputs are accurate.
Boundary testingExact thresholds and overlapping conditions are tested.
ReadabilityNames, ordering, formatting, labels, and constants make intent clear.
Workflow disciplineFormatting, checking, execution, and evidence are recorded separately.
DebuggingA deliberate defect is detected, explained, corrected, and retested.
SecurityNo unnecessary permission, secret, file, network, or process access is used.
ExplanationThe learner can trace precedence and final state without guessing.

Completion standard: Every test passes, every acceptance criterion is met, and the learner can explain why cases E and F select their documented rules.

1C.13 Reflection questions

1C.14 Optional extensions

Complete these only after the required project passes:

Keep optional work within Chapter 1 constructs. Functions, loops, modules, and formal tests will be introduced later.

Chapter 1 summary

You now have a working mental model of PeaLang, a verified toolchain, a command-line development workflow, experience with a first program, and a complete rules checkpoint. You can create readable source, preserve secure defaults, validate it through distinct tooling stages, reason about ordered decisions, test boundaries, and explain results.

Transition to Chapter 2

Chapter 2 examines the language itself in greater precision. The next lesson covers source files, lexical structure, comments, identifiers, and literals. It will establish the vocabulary needed to describe how PeaLang reads source text before moving into variables, expressions, and evaluation.

Checkpoint status: Approved.

← Previous Next →