Skip to content

Instantly share code, notes, and snippets.

@frenchy64
Created January 3, 2012 22:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frenchy64/1557417 to your computer and use it in GitHub Desktop.
Save frenchy64/1557417 to your computer and use it in GitHub Desktop.
;; As a goal
;; Non-relational
;; Accepts these patterns of arguments:
;; IOO
;; III
;; IOI
;; IIO
;; I=input (ground), O=output (not ground)
(defn items-colors-for-country [country item-name item-color]
(fresh [not-country]
(items item-name item-color)
(!= country not-country)
(conda
[(restricted-to country item-name)
(conda
[(not-allowed-in country item-name)
fail]
[succeed])]
[(restricted-to not-country item-name)
fail]
;; No entry in restricted-to for item-name
[(not-allowed-in country item-name)
fail]
[succeed])))
(run* [q]
(fresh [country item-name item-color]
(== q [country item-name item-color])
(conde
[(== 'US country)]
[(== 'UK country)]
[(== 'France country)]
[(== 'Australia country)])
(items-colors-for-country country item-name item-color)))
;=> ([US Purse Blue] [UK Purse Blue] [US Banana Yellow] [US Car Red] [Australia Purse Blue] [Australia Banana Yellow] [France Banana Yellow])
(run* [q]
(fresh [country item-name item-color]
(== q [country item-name item-color])
(== item-color 'Blue)
(conde
[(== 'US country)]
[(== 'UK country)]
[(== 'France country)]
[(== 'Australia country)])
(items-colors-for-country country item-name item-color)))
;=> ([US Purse Blue] [UK Purse Blue] [Australia Purse Blue])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment