Last active
September 11, 2015 19:41
-
-
Save lutter/77883db5c76f780619a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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