Skip to content

Commit d42bf83

Browse files
committed
Refine set syntax and more
The main changes are: Removed the overloading of the equality operator to do set membership tests and updated set generation syntax to align with the new membership test syntax. Also, got rid of the "[]" syntax in references and replaced with special "_" character that is treated as a special iterator. Documented this behaviour in the references section. Also, fixed semantics so that document content is defined in terms of the rule head which is in turn defined by instances of the body that evaluate to true. E.g., instead of "p :- 7", we now write "p = 7", which is short for "p = 7 :- true".
1 parent 86672fa commit d42bf83

File tree

2 files changed

+115
-111
lines changed

2 files changed

+115
-111
lines changed

docs/CONCEPTS.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ Content-Type: text/plain
8686
8787
package opa.examples
8888
89-
violations[] = server :-
90-
server = data.servers[]
91-
server.protocols[] = "http"
92-
server.ports[] = data.ports[i].id
93-
data.ports[i].networks[] = data.networks[j].id
89+
violations[server] :-
90+
server = data.servers[_]
91+
server.protocols[_] = "http"
92+
server.ports[_] = data.ports[i].id
93+
data.ports[i].networks[_] = data.networks[j].id
9494
data.networks[j].public = true
9595
```
9696

@@ -190,7 +190,7 @@ Conceptually, there are two kinds of documents in OPA:
190190

191191
When defining policies, rules are written which contain expressions that reference documents. The language that rules are written in ("Opalog") lets you reference base documents and virtual documents in exactly the same way.
192192

193-
<img src="https://cdn.rawgit.com/open-policy-agent/opa/9f5f1e6fa68fd0ee627122b9e5c8809519e5bba8/docs/data-model-logical.svg" />
193+
<img src="https://cdn.rawgit.com/open-policy-agent/opa/86672fab147c476cb8e8b0950b6c4fd48b5b2014/docs/data-model-logical.svg" />
194194

195195
## <a name="policies"></a> Policies
196196

@@ -243,15 +243,15 @@ import data.servers # import the data.servers docume
243243
import data.networks # same but for data.networks
244244
import data.ports # same but for data.ports
245245
246-
violations[] = server :- # a server exists in the violations set if:
247-
server = servers[] # the server exists in the servers collection
248-
server.protocols[] = "http" # and the server has http in its protocols collection
249-
public_servers[] = server # and the server exists in the public_servers collection
246+
violations[server] :- # a server exists in the violations set if:
247+
server = servers[_], # the server exists in the servers collection
248+
server.protocols[_] = "http", # and the server has http in its protocols collection
249+
public_servers[server] # and the server exists in the public_servers set
250250
251-
public_servers[] = server :- # a server exists in the public_servers set if:
252-
server = servers[] # the server exists in the servers collection
253-
server.ports[] = ports[i].id # and the server is connected to a port in the ports collection
254-
ports[i].networks[] = networks[j].id # and the port is connected to a network in the networks collection
251+
public_servers[server] :- # a server exists in the public_servers set if:
252+
server = servers[_], # the server exists in the servers collection
253+
server.ports[_] = ports[i].id, # and the server is connected to a port in the ports collection
254+
ports[i].networks[_] = networks[j].id, # and the port is connected to a network in the networks collection
255255
networks[j].public = true # and the network is public
256256
```
257257

0 commit comments

Comments
 (0)