Skip to content

Instantly share code, notes, and snippets.

@lutter
Last active September 11, 2015 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lutter/77883db5c76f780619a1 to your computer and use it in GitHub Desktop.
Save lutter/77883db5c76f780619a1 to your computer and use it in GitHub Desktop.
(defn is-in-env?
"Return true if node N is in the desired environment according to the
subtree rooted at G. The following helpers are used:
(good? g) - true if g sets the environment to the desired one
(bad? g) - (not (good? g)) Note that this includes groups that do
not set the environment at all
(matches? n g) - true if the node N matches G's rule
(children g) - a list of G's child groups
Ignores environment trumps/override"
[n g]
(and
(matches? n g)
(cond
(good? g) (and
(for [c (children g)]
(or (not (matches? n c)) (is-in-env? n c))))
(bad? g) (or
(for [c (children g)]
(and (matches? n c) (is-in-env? n c)))))))
(defn is-in-env-by-trump?
"Return true if node N is in the desired environment according to the
subtree rooted at G because of the environment_trumps flag. The following
helpers are used:
(good? g) - true if g sets the environment to the desired one
(bad? g) - (not (good? g)) Note that this includes groups that do
not set the environment at all
(trump? g) - true if G sets environment_trumps
(matches? n g) - true if the node N matches G's rule
(children g) - a list of G's child groups"
[n g]
(and
(matches? n g)
(cond
(not (trump? g)) (or
(for [c (children g)]
(and (matches? n c)
(is-in-env-by-trump? n c))))
(and (trump? g) (good? g)) (and
(for [c (children g)]
(or (not (matches? n c))
(is-in-env-by-trump? n c))))
(and (trump? g) (bad? g)) (or
(for [c (children g)]
(and (matches? n c)
(is-in-env-by-trump? n c)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment