Code Examples
Code examples:
; is a comment (bind ?x 100) ; x = 100 (deffunction max (?a ?b) (if (> ?a ?b) then ?a else ?b)) (deffacts myroom (furniture chair) (furniture table) (furniture bed) ) (deftemplate car (slot color) (slot mileage) (slot value) ) (assert (car (color red) (mileage 10000) (value 400)))Sample code:
(clear) (deftemplate blood-donor (slot name) (slot type)) (deffacts blood-bank ; put names & their types into working memory (blood-donor (name "Alice")(type "A")) (blood-donor (name "Agatha")(type "A")) (blood-donor (name "Bob")(type "B")) (blood-donor (name "Barbara")(type "B")) (blood-donor (name "Jess")(type "AB")) (blood-donor (name "Karen")(type "AB")) (blood-donor (name "Onan")(type "O")) (blood-donor (name "Osbert")(type "O")) ) (defrule can-give-to-same-type-but-not-self ; handles A > A, B > B, O > O, AB > AB, but not N1 > N1 (blood-donor (name ?name)(type ?type)) (blood-donor (name ?name2)(type ?type2 &:(eq ?type ?type2) &: (neq ?name ?name2) )) => (printout t ?name " can give blood to " ?name2 crlf) ) (defrule O-gives-to-others-but-not-itself ; O to O cover in above rule (blood-donor (name ?name)(type ?type &:(eq ?type "O"))) (blood-donor (name ?name2)(type ?type2 &: (neq ?type ?type2) &: (neq ?name ?name2) )) => (printout t ?name " can give blood to " ?name2 crlf) ) (defrule A-or-B-gives-to-AB ; case O gives to AB and AB gives to AB already dealt with (blood-donor (name ?name)(type ?type &:(or (eq ?type "A") (eq ?type "B" )))) (blood-donor (name ?name2)(type ?type2 &: (eq ?type2 "AB") &: (neq ?name ?name2) )) => (printout t ?name " can give blood to " ?name2 crlf) ) ;(watch all) (reset) (run)Read more about this topic: Jess (programming Language)
Famous quotes containing the words code and/or examples:
“Many people will say to working mothers, in effect, I dont think you can have it all. The phrase for have it all is code for have your cake and eat it too. What these people really mean is that achievement in the workplace has always come at a priceusually a significant personal price; conversely, women who stayed home with their children were seen as having sacrificed a great deal of their own ambition for their families.”
—Anne C. Weisberg (20th century)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)