Declarative programming
Polar is a declarative language. Instead of specifying how to compute a result, you describe the conditions under which something is true, and the Polar runtime evaluates it. Polar works like a database: you write rules (similar to inserting data) and later issue queries against those rules. At runtime, the Polar engine evaluates your queries and returns matches based on the rules you’ve defined.Logic programming
Polar is also a logic programming language. It’s designed to answer questions based on a set of rules. You’ll see this in action in the examples below.How Polar executes
Info: For the next few examples, we’ll use only the base language, without touching authorization just yet. In Polar, rules are written as statements. For example:father("SisterBear", "PapaBear")
as true. You don’t need to declare the function, each rule is a standalone fact.
You can define multiple rules for the same predicate:
- “
father
is also true when it’s called on the strings"BrotherBear"
and"PapaBear"
.”
father
predicate — adding a new rule is much like adding a new database entry.
Querying Polar from Oso Cloud
Info: In the following steps, you’ll create an Oso Cloud account and configure your local environment to work with it.
Add rules
Once you’ve created your account:- Go to the Rules Editor
- Copy the rules we created above and paste them into the editor
- Add:
- Click “Deploy”
Configure the CLI
- In the Oso Cloud UI, go to Organization Settings → API Keys.
- Create a new API Key in your current environment.
- When prompted, set the access level to Read Only.
- Copy and store the key securely, you’ll use it to authenticate the CLI.
- Navigate to the Install tab under CLI, and follow the installation instructions for your platform.
- After installation, verify that the CLI is configured correctly:
- This command should return your current policy from Oso Cloud:
- If your environment is configured correctly, you’ll see the rules we entered in the Rules Editor:
Query examples
Ask if SisterBear’s father is PapaBear:father
holds for the arguments "SisterBear"
and "PapaBear"
.
Reverse the arguments and the result is false:
_
wildcard returns all values that make the query true.
Conditional rules
So far, we’ve used rules that are always true—unconditional. You can also define rules that are conditionally true usingif
.
In conditional rules, you can introduce variables—for example: grandchild
, grandparent
, and parent
. Oso Cloud requires all variables to have type annotations. Use syntax like grandchild: String
or parent matches String
to make types explicit. If you omit these, the system will raise a warning.
Here’s a rule that defines a grandfather
relationship using two father
rules:
statement if condition;
pattern. See the other modeling patterns for practical usage.