I am still working on my first Jess application, and having problems with a deffunction. I have defined a deftemplate to represent a football game, a defquery to get all games involving a team, and a deffunction to calculate a team's record. Then I asserted a fact representing a game, and tried to run. I got an error, shown in the session output below.
Can someone explain what I am doing wrong? Thank you. -- Jim McMaster mailto:[EMAIL PROTECTED] Jess, the Java Expert System Shell Copyright (C) 2001 E.J. Friedman Hill and the Sandia Corporation Jess Version 6.1p4 7/8/2003 Jess> (clear) (deftemplate game "A football Game" (slot home-team) (slot home-score) (slot home-tds) (slot visiting-team) (slot visiting-score) (slot visiting-tds)) (deffacts games (game (visiting-team DEN) (visiting-score 30) (visiting-tds 3) (home-team CIN) (home-score 10) (home-tds 1))) (defquery all-games (declare (variables ?team)) (or (game (home-team ?ht&:(eq ?ht ?team))) (game (visiting-team ?vt&:(eq ?vt ?team))))) (deffunction get-record (?team ?games-it) "Gets a team's record in a set of games" (bind ?wins 0) (bind ?losses 0) (bind ?ties 0) (bind ?net-tds 0) (while (?games-it hasNext) (bind ?token (call ?games-it next)) (bind ?game (call ?token fact 1)) (bind ?ht (fact-slot-value ?game home-team)) (bind ?vt (fact-slot-value ?game visiting-team)) (bind ?hs (fact-slot-value ?game home-score)) (bind ?vs (fact-slot-value ?game visiting-score)) (bind ?htd (fact-slot-value ?game home-tds)) (bind ?vtd (fact-slot-value ?game visiting-tds)) (if (eq ?team ?ht) then ( (+ ?net-tds (- ?htd ?vtd)) (if (> ?hs ?vs) then (+ ?wins 1) else (if (< ?hs ?vs) then (+ ?losses 1) else (+ ?ties 1)))) else ( (if (eq ?team ?vt) then ( (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1)))))))) (return (?wins ?losses ?ties ?net-tds))) (reset) (get-record DEN (run-query all-games DEN)) TRUE Jess> TRUE Jess> TRUE Jess> TRUE Jess> TRUE Jess> TRUE Jess> Jess reported an error in routine Value.externalAddressValue while executing (call (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1)))) while executing (if (eq ?team ?vt) then (call (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1))))) while executing (call (if (eq ?team ?vt) then (call (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1)))))) while executing (if (eq ?team ?ht) then (call (+ ?net-tds (- ?htd ?vtd)) (if (> ?hs ?vs) then (+ ?wins 1) else (if (< ?hs ?vs) then (+ ?losses 1) else (+ ?ties 1)))) else (call (if (eq ?team ?vt) then (call (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1))))))) while executing (while (call ?games-it hasNext) (bind ?token (call ?games-it next)) (bind ?game (call ?token fact 1)) (bind ?ht (fact-slot-value ?game home-team)) (bind ?vt (fact-slot-value ?game visiting-team)) (bind ?hs (fact-slot-value ?game home-score)) (bind ?vs (fact-slot-value ?game visiting-score)) (bind ?htd (fact-slot-value ?game home-tds)) (bind ?vtd (fact-slot-value ?game visiting-tds)) (if (eq ?team ?ht) then (call (+ ?net-tds (- ?htd ?vtd)) (if (> ?hs ?vs) then (+ ?wins 1) else (if (< ?hs ?vs) then (+ ?losses 1) else (+ ?ties 1)))) else (call (if (eq ?team ?vt) then (call (+ ?net-tds (- ?vtd ?htd)) (if (> ?vs ?hs) then (+ ?wins 1) else (if (< ?vs ?hs) then (+ ?losses 1) else (+ ?ties 1)))))))) while executing deffunction get-record while executing (get-record DEN (run-query all-games DEN)). Message: Not an external address: "2" (type = INTEGER). Program text: ( get-record DEN ( run-query all-games DEN ) ) at line 49. at jess.Value.a(Unknown Source) at jess.Value.a(Unknown Source) at jess.Value.externalAddressValue(Unknown Source) at jess.v.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.dw.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.v.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.dw.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.b7.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.FuncallValue.resolveValue(Unknown Source) at jess.Deffunction.call(Unknown Source) at jess.ep.a(Unknown Source) at jess.Funcall.execute(Unknown Source) at jess.Jesp.a(Unknown Source) at jess.Jesp.for(Unknown Source) at jess.Jesp.parse(Unknown Source) at jess.Jesp.parse(Unknown Source) at jess.Main.execute(Unknown Source) at JessWin.jessExecute(JessWin.java:1115) at JessWin$63.run(JessWin.java:1062) at java.lang.Thread.run(Thread.java:534) Jess> -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------
