Repository navigation
Examples
PlainLogic works at the level where the behavior is clear. English steps can describe substantial work, and exact expressions can pin down the decisions that need precision. The first four examples below are complete canonical documents; copy each into its own UTF-8 .plog file. The optional checker accepts their structure without executing the described behavior.
See Syntax reference, Aliases and native blocks, and Using PlainLogic for the language rules and agent workflow.
This example uses the original 0.1 syntax, still supported in 0.3. Whole-cent arithmetic and the threshold/rounding rule are explicit, while implementation structure is left to the target project.
plainlogic 0.1
unit QuoteTotal
state ready
intent "Compute a caller-supplied line-item quote in whole cents."
scope "Pure arithmetic. Caller guarantees nonnegative prices and quantities; no taxes, storage, or new input validation."
require R1 "Sum each price_cents times quantity."
require R2 "At a subtotal of at least 10000 cents, discount 10 percent rounded down to whole cents."
require R3 "Return subtotal, discount, and total in cents."
record Line:
price_cents: Int
quantity: Int
record Quote:
subtotal_cents: Int
discount_cents: Int
total_cents: Int
fn quote(lines: List[Line]) -> Quote:
covers R1, R2, R3
subtotal = 0
for line in lines:
subtotal = subtotal + line.price_cents * line.quantity
discount = 0
if subtotal >= 10000:
discount = subtotal * 10 // 100
return Quote(subtotal_cents=subtotal, discount_cents=discount, total_cents=subtotal - discount)
case empty:
given lines = []
expect quote(lines) == Quote(subtotal_cents=0, discount_cents=0, total_cents=0)
case below_threshold:
given lines = [Line(price_cents=9999, quantity=1)]
expect quote(lines) == Quote(subtotal_cents=9999, discount_cents=0, total_cents=9999)
case threshold_and_rounding:
given lines = [Line(price_cents=10009, quantity=1)]
expect quote(lines) == Quote(subtotal_cents=10009, discount_cents=1000, total_cents=9009)
Record construction uses named fields. The cases expose empty input, the threshold, and rounding as candidate tests. They are not executed by the checker. The scope deliberately gives the caller responsibility for valid prices and quantities; an implementation should not add a new validation policy implicitly.
This 0.2 example also works under a 0.3 header. The English loop introduces value, and the exact comparison fixes which values count:
plainlogic 0.2
unit PositiveTotal
state ready
intent "Sum strictly positive integer values."
scope "Pure arithmetic over caller-supplied integers; no input validation or side effects."
require R1 "Return the sum of strictly positive input values; return zero if none are positive."
fn total_positive(values: List[Int]) -> Int:
covers R1
> Start a local total at zero.
> For each value in values, in input order:
if value > 0:
> Add value to total.
> Return total.
case empty:
given values = []
expect total_positive(values) == 0
case mixed:
given values = [-4, 0, 3, 5]
expect total_positive(values) == 8
The checker accepts prose structurally and warns that meaning and feasibility require semantic validation. It does not reject total or value because their introduction is English, nor does it establish that they have coherent scope. That judgment belongs to validation and implementation.
The following document illustrates a lookup contract. Its ref is a hypothetical project locator: implementation must find and verify the real project behavior rather than assume this path or method exists.
plainlogic 0.3
unit ExistingOrder
state ready
intent "Report whether an order is present using the existing lookup."
scope "Read one order; no creation, deletion, retries, or error translation."
require R1 "Return True when lookup returns an order and False when it returns None."
require R2 "Propagate lookup errors unchanged."
ref repository_get "src/orders.py#OrderRepository.get"
type OrderId = Text
record Order:
id: OrderId
port load_order(id: OrderId) -> Order | None:
effect read
contract "Return the matching order or None when absent. Propagate lookup errors unchanged."
bind repository_get
fn exists(order_id: OrderId) -> Bool:
covers R1, R2
order = load_order(order_id)
return order is not None
case absent:
given order_id = "missing"
stub load_order(order_id) returns None
expect exists(order_id) == False
case present:
given order_id = "known"
stub load_order(order_id) returns Order(id=order_id)
expect exists(order_id) == True
The stub describes a returned value for its scenario. It does not intercept a real repository call or prove that errors propagate. The contract and R2 make that behavior reviewable; target-language tests should verify it. A ref is data and is never executed or opened by the structural checker.
The HTTP request idea leaves the output's meaning open. “JSON string” could refer to response JSON text, a newly serialized response value, or an envelope. This canonical draft preserves the input method choices and marks the unresolved result policy:
plainlogic 0.3
unit ExecuteRequestDraft
state draft
intent "Implement the HTTP helper at the described level of abstraction."
scope "HTTP helper; resolve existing client and serializer mappings from project context."
require R1 "Initialize a client, serialize requestBody, and send the request using url and requestType."
require R2 "The only requestType choices are GET, POST, DELETE, and PUT."
require R3 "Return a JSON string whose response representation is resolved by Q1."
open Q1 "Should the result preserve response JSON text, serialize a response value, or return an envelope? Check existing conventions first."
type JSONString = Text
type RequestType = Text
fn executeRequest(url: Text, requestType: RequestType, requestBody: Object) -> JSONString:
covers R1, R2, R3
> Initialize the HTTP client using the project's existing conventions.
> Serialize requestBody and send the request using url and requestType.
ask Q1
RequestType = Text does not itself enforce enum membership; the allowed set is retained in R2. Object is a symbolic type to map against the actual project. ask Q1 is a draft marker, not a runtime exception or guessed return. Normal structural checking accepts this draft; --ready rejects it until the decision and state are resolved. There is no executable scenario yet, so a missing-case warning is expected.
Aliases and native blocks has two complete 0.3 documents: starting a coroutine with a NewThread: body and preserving a TypeScript generic declaration with native blocks. Both demonstrate surfaces that require semantic review beyond structural acceptance.
For a tiny informal excerpt, the body-taking alias looks like this:
alias NewThread -> Create and run new coroutine
NewThread:
for i = 1 to 100:
> Print i to console
The counted loop includes 1 and 100. Scheduling, capture, errors, and control-flow targets come from the behavior contract and runtime context, not from the name NewThread.
The agent workflow accepts this informal fragment, which is not a full canonical checker document:
function JSONString executeRequest(string url, enum requestType [GET, POST, DELETE, PUT], object requestBody):
> Initialize http client
> Serialize requestBody
> Send request
> Return result as serialized JSON string
It can review the logic and ask a consequential question without making the user first rewrite the signature as fn name(param: Type) -> Type. Normalization should preserve the method choices and intended output, and should not invent error handling or client policy. The draft above demonstrates how to retain an actual ambiguity when canonical form is useful.
From the source repository root, check one saved document:
python tools/check_plainlogic.py quote-total.plog --ready
Use the first three complete examples with --ready. Check the HTTP draft without that flag. These commands check syntax, declared coverage, and readiness; they never run the behavior or validate referenced source. For actual implementation or the narrower write/validate modes, see Using PlainLogic, Codex plugin, and Claude Code plugin.
Source baseline: repository examples/, docs/plainlogic.md, and tools/check_plainlogic.py. The port and explicit-ask drafts on this page are documentation examples checked against that implementation.
PlainLogic 0.3 · Home · Implementation source · Validation limits
Learn
Install and use
Check and contribute