5. Composing Specs

Specs can depend on other specs. The uses keyword imports another spec into the current one, making its rules and data available as if they were defined locally.

This is useful when several specs share common inputs or logic. Define it once, reference it everywhere.

The uses keyword

uses customer_tier tells Lemma to load the customer_tier spec and make its rules available under the customer_tier prefix. When you consult customer_eligibility, Lemma evaluates customer_tier first and passes the results through.

You reference imported rules using dot notation: customer_tier.is_premium reads as "the result of the is_premium rule in customer_tier".

Importing from LemmaBase

You can import any published spec from LemmaBase using its registry path:

uses @lemma/geography as geo

The as keyword sets the local alias. Without it, the last segment of the path is used. See Using LemmaBase for more on the registry.

Data sharing

Data fields flow down automatically. When you consult a spec that uses another, you supply data for both specs in one request. Lemma matches field names across the dependency tree. If two specs have a field with the same name and type, they share the value.