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

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

Lesson 1: What PeaLang Is—Design Goals, Use Cases, and Safe Extensibility

Lesson level: Foundation

Purpose: Build an accurate mental model of PeaLang before writing substantial programs.

Learning objectives

By the end of this lesson, you should be able to:

1.1 The central idea

PeaLang is a programming language and portable execution environment designed for writing rules, data transformations, extension logic, and service-side workflows. A PeaLang program lives in a .pea source file and can be run directly, checked with development tools, compiled to portable bytecode, or loaded by a host application.

The language is not defined only by its syntax. Its runtime model is equally important. PeaLang is intended to extend an application without automatically exposing unrestricted operating-system access or arbitrary host-language reflection. The host chooses which capabilities, functions, data, and resource budgets a script receives. This makes the boundary between the script and its environment an explicit part of program design.

1.2 A layered mental model

Think of PeaLang as four cooperating layers:

A beginner primarily works in the language and tooling layers. Advanced users deliberately choose execution and integration strategies. Expert users design capability boundaries, packages, observability, deployment controls, and release evidence around the complete system.

1.3 Design goals

Readable application logic. PeaLang provides familiar constructs such as let, const, functions, conditionals, loops, collections, and print output. This keeps ordinary rules and transformations approachable.

Gradual rigor. Untyped programs remain valid, while optional annotations, semantic analysis, generics, protocols, and explicit Option, Result, and Future types support stronger contracts when a project needs them.

Portable execution. Programs can move across direct interpretation, VM execution, host embedding, a service-side runtime, and browser-oriented artifacts while using a shared portable-value contract.

Safe extensibility. Sensitive operations are capabilities rather than automatic privileges. Filesystem, HTTP, logging, and concurrency operations can be denied unless the host grants them.

Operational completeness. The project includes testing, debugging, packaging, signatures, resource limits, connectors, observability, serving, deployment, and supply-chain controls so language code can progress beyond prototypes.

1.4 Good use cases

Business rules. Pricing, eligibility, validation, routing, and policy decisions benefit from readable logic that can be separated from a larger host application.

Controlled application extensions. A host can expose a narrow set of approved operations instead of giving scripts broad access to the host language or operating system.

Data preparation and analytics. PeaLang includes structured data, DataFrame operations, SQL integration, connectors, time-series tools, forecasting, and machine-learning foundations.

Portable service logic. The same conceptual module and value contracts can be used through Python embedding, a Java sidecar, TypeScript clients, React-facing back ends, or browser-safe execution profiles.

Governed model workflows. Model bundles, registries, monitoring, promotion, rollback, signing, encryption, and audit records support controlled ML lifecycles.

1.5 Cases that require caution

PeaLang should not be treated as an unrestricted replacement for a general-purpose host language. Low-level operating-system programming, hardware drivers, arbitrary native-library access, and host-object reflection belong outside the script boundary. A host should expose only the operations that the application actually requires.

Preview features also require deliberate risk management. Bytecode or browser artifacts marked as preview should not be assumed to have permanent compatibility guarantees. Likewise, optional provider integrations require their own dependencies, credentials, configuration, and live validation.

Finally, built-in analytical and ML methods are foundations, not automatic proof that a model is appropriate. Production use still requires domain validation, governance, security review, and operational monitoring.

1.6 The host–script boundary

The host application owns environment access. It loads a script, supplies approved values or functions, configures permissions and resource limits, invokes exported behavior, validates returned values, and records operational evidence. The PeaLang script owns domain logic within that contract.

The portable boundary values are null, boolean, integer, float, string, list, and string-keyed map. Host-specific objects should be converted before crossing the boundary. This prevents a script from depending silently on internal host implementation details.

Example boundary. An HR application may pass an employee record as a string-keyed map and expose an approved function for retrieving a policy band. The script computes an eligibility decision and returns a validated map. It does not receive a database connection, filesystem handle, or arbitrary host object unless those powers are explicitly designed into the contract.

1.7 A safe extension pattern

1.8 Common mistakes

1.9 Worked architecture example

Suppose an e-commerce platform needs configurable discount rules. The host converts a cart into a map containing approved product, quantity, customer-tier, and subtotal fields. It invokes an exported PeaLang function under an execution deadline and instruction budget. The script returns a map containing the discount amount, reason code, and explanatory message. The host validates these fields, prevents a negative total, records the decision, and applies the result.

This design keeps frequently changing policy in PeaLang while leaving identity, payment, persistence, secrets, and final enforcement in the host. The script receives enough information to decide, but not enough authority to charge a card, query arbitrary tables, or open files.

1.10 Guided practice

For each scenario, decide whether PeaLang is a strong fit, a conditional fit, or a poor fit. Then identify the host boundary.

Suggested reasoning: Scenarios 1, 2, 4, and 5 can fit when capabilities, validation, and resource limits are explicit. Scenario 3 is a poor fit because it requires low-level native and operating-system control.

1.11 Hands-on lab: Design a safe rules extension

Scenario: A support platform needs a configurable rule that assigns an incoming case a priority of low, medium, or high.

Step 1 — Define inputs. Use portable fields such as customer tier, service impact, affected-user count, and security relevance.

Step 2 — Define output. Return a map containing priority, reason code, and explanation.

Step 3 — Separate responsibilities. The script calculates the recommendation. The host authenticates the caller, retrieves the case, validates data, enforces allowed priority values, persists the result, and emits the audit record.

Step 4 — Select capabilities. The first version needs no filesystem or HTTP capability. Logging should be structured and must not include sensitive case details.

Step 5 — Select limits. Add a short deadline, bounded instructions, bounded output size, and reasonable collection limits.

Step 6 — List failure tests. Include missing fields, invalid tier, negative affected-user count, an oversized list, a timeout, denied logging, and an invalid returned priority.

Deliverable: Write a one-page design containing the input schema, output schema, host responsibilities, script responsibilities, capability list, resource limits, and failure tests. Implementation will follow after the syntax lessons.

1.12 Review questions

1.13 Applied challenge

Choose one extension scenario from your own domain. Write a concise architecture brief that answers five questions: What decision or transformation belongs in PeaLang? What data crosses the boundary? Which capabilities are required? Which limits and validations apply? What remains exclusively under host control?

Lesson summary

PeaLang combines an approachable programming language with portable execution and deliberate host-controlled capabilities. Its strongest applications isolate changeable rules, transformations, or model workflows behind explicit contracts. Safe PeaLang systems use portable values, least privilege, resource budgets, validation, observability, adversarial testing, and clear separation between script logic and host authority.

Lesson status: Approved.

Next →