Skip to content

Instantly share code, notes, and snippets.

@MarcoPolo
Created March 19, 2014 07:11
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 MarcoPolo/9636822 to your computer and use it in GitHub Desktop.
Save MarcoPolo/9636822 to your computer and use it in GitHub Desktop.
How to find the smallest number in a set of facts
(assert
(foo 3)
(foo 4)
(foo 6)
(foo 9)
(foo 2)
(foo 5))
(defrule init-lowest
(not (lowest-foo ?))
(foo ?a)
=> (assert (lowest-foo ?a)))
(defrule lowest
(declare (salience 1100))
?foo <- (foo ?a)
?lowest <- (lowest-foo ?b)
(test (< ?a ?b))
=>
(retract ?lowest)
(assert (lowest-foo ?a)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment