Jess71p2 30 - Jess>(modify?id(location dining-room<Fact-2> Jess>(facts f-0(MAIN:initial-fact f-2(MAIN:box(location dining-room(contents

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
5. Working Memory 22 Jess> (facts) f-0 (MAIN::initial-fact) For a total of 1 facts in module MAIN. The fact (initial-fact) is asserted by the reset command. It is used internally by Jess to keep track of its own operations; you should generally not retract it. A given slot in a deftemplate fact can normally hold only one value. If you want a slot that can hold multiple values, use the multislot keyword instead: Jess> (deftemplate box (slot location) (multislot contents)) TRUE Jess> (bind ?id (assert (box (location kitchen) (contents spatula sponge frying-pan)))) <Fact-2> (We're saving the fact returned by (assert) in the variable ?id, for use below.) A multislot has the default value () (the empty list) if no other default is specified. You can change the values in the slots of an unordered fact using the modify command. Building on the immediately preceding example, we can move the box into the dining room:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Jess> (modify ?id (location dining-room)) <Fact-2> Jess> (facts) f-0 (MAIN::initial-fact) f-2 (MAIN::box (location dining-room) (contents spatula sponge frying-pan)) For a total of 2 facts in module MAIN. The optional extends clause of the deftemplate construct lets you define one template in terms of another. For example, you could define a used-auto as a kind of automobile with more data: Jess> (deftemplate used-auto extends automobile (slot mileage) (slot blue-book-value) (multislot owners)) TRUE A used-auto fact would now have all the slots of an automobile, in the same order, plus three more. As we'll see later, this inheritance relationship will let you act on all automobiles (used or not) when you so desire, or only on the used ones. 5.3. Shadow facts: reasoning about Java objects...
View Full Document

This note was uploaded on 03/02/2010 for the course COMP 102 taught by Professor Smith during the Spring '10 term at California State University , Monterey Bay.

Ask a homework question - tutors are online