### View LispWorks Example Source File Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-introduction-2 This Lisp snippet demonstrates how to open and view a specific example source file from the LispWorks library. Evaluating this form in the LispWorks IDE will open the designated file, which is typically read-only and located in the `lib/8-1-0-0/examples/` directory of your LispWorks installation. ```Lisp (example-edit-file "kw/animal/defsystem") ``` -------------------------------- ### start-kw Function Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index This function is used to initialize and start the KnowledgeWorks system. It serves as the entry point for beginning a KnowledgeWorks session. ```APIDOC start-kw ``` -------------------------------- ### Load KnowledgeWorks Module in LispWorks Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-tutorial-1 This Lisp snippet demonstrates how to load the KnowledgeWorks module by adding a `(require "kw")` form to the LispWorks initialization file. This step is essential to enable access to KnowledgeWorks tools and functionalities within the LispWorks environment. ```Lisp (require "kw") ``` -------------------------------- ### Lisp `logic` Function Usage Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-6 Practical examples demonstrating various uses of the `logic` function to call Prolog goals. These examples illustrate the effects of different `:return-type` and `:all` options on the output, showing how to retrieve solutions as display output, filled expressions, association lists, or lists of all solutions. ```Lisp (logic '(color ?x) :return-type :display) ``` ```Lisp (logic '(color ?x) :return-type :fill) ``` ```Lisp (logic '(color ?x) :return-type :alist) ``` ```Lisp (logic '(color ?x) :all :list) ``` ```Lisp (logic '(color ?x) :return-type :bag :bag-exp '(?x is a color) :all :values) ``` -------------------------------- ### make-instance Generic Function API and Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-38 Detailed API documentation and practical usage examples for the `make-instance` generic function, demonstrating how to create new instances of CLOS or KnowledgeWorks structure classes with and without initialization arguments. ```APIDOC Package: common-lisp Signature: make-instance class &rest initargs => object Arguments: class: A class object or a symbol. initargs: Initialization arguments for the object. Values: object: A new instance of class. Description: The generic function `make-instance` makes a new instance of the class class. If class is a CLOS class then the behavior is as specified by make-instance in the Common Lisp standard. If class is a KnowledgeWorks structure class, then initargs are the same as those for the automatically defined constructor function of the structure. The object is added to the object base of the current inferencing state. ``` ```Lisp (make-instance 'start) (make-instance 'driver :location 'London :kb-name 'fred) ``` -------------------------------- ### Example Usage of instantiation Goal in Lisp Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-28 A simple Lisp code example demonstrating how to call the `instantiation` goal, binding the found instantiation to the `?instantiation` variable. ```Lisp (instantiation ?instantiation) ``` -------------------------------- ### APIDOC: start-kw Function Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Reference for the `start-kw` function in LispWorks KnowledgeWorks. This function is presumably used to initialize or start the KnowledgeWorks environment or a specific component. ```APIDOC start-kw: function ``` -------------------------------- ### Examples of KnowledgeWorks Backward Chaining Interpreter Usage Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-rules-2 Demonstrates practical usage of the `any` and `findall` functions with the KnowledgeWorks backward chaining interpreter. These examples illustrate how to retrieve a single solution or all possible solutions for a membership proof, showing the instantiation of variables. ```Lisp (any '(?x is in (1 2 3)) '(member ?x (1 2 3))) ``` ```Lisp (findall '(?x is in (1 2 3)) '(member ?x (1 2 3))) ``` -------------------------------- ### KnowledgeWorks def-kb-class Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation references for the KnowledgeWorks `def-kb-class` macro, covering its use for defining unnamed and named classes, reasoning with certainty factors, and various examples. ```APIDOC `def-kb-class` (macro) References: - 4.1.1 : Unnamed Classes - 4.1.2 : Named Classes - 6.1.1.4 : Reasoning with Certainty Factors - 6.3.1 : Example - 6.4.1 : Example ``` -------------------------------- ### Demonstrate `any` Function Usage in Lisp Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-2 Illustrates how to use the `any` function in Lisp with practical examples, showing how it finds bindings and instantiates patterns based on a goal. The examples demonstrate successful inference and the resulting instantiated pattern and success flag. ```Lisp (any '(?x is in (1 2 3)) '(member ?x (1 2 3))) ``` ```Lisp (any '(?truck is a truck) '(truck ?truck)) ``` -------------------------------- ### Common Prolog Debugger: Display and Creep Example Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-7 This example demonstrates how to use the 'd' (display) command to view the compiled procedure of the current goal (MEMBER) and then the 'c' (creep) command to continue tracing exhaustively. ```Prolog |d <- user selects display | |Compiled procedure: | |(DEFREL MEMBER | ((MEMBER ?X (?X . ?))) | ((MEMBER ?X (? . ?Y)) (MEMBER ?X ?Y))) ? c | ...user selects creep ``` -------------------------------- ### Lisp: Example Usage of inst-bindings Function Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-29 Illustrative Lisp code examples demonstrating a rule's precondition and the expected output from calling `inst-bindings` on an instantiation. This shows how variable bindings are represented. ```Lisp (object ? color ?color-value size ?size) ``` ```Lisp (inst-bindings inst) ``` ```Lisp ((?color-value . :red) (?size . 20)) ``` -------------------------------- ### Lisp Example: Calling fire-rule Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-22 A simple Lisp example demonstrating how to invoke the `fire-rule` backward chaining goal with a symbolic instantiation variable. ```Lisp (fire-rule ?instantiation) ``` -------------------------------- ### KnowledgeWorks defrule Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation references for the KnowledgeWorks `defrule` macro, detailing rule definition, examples, meta rule protocol, certainty factors, pattern matching, tail recursion, and inferencing state management. ```APIDOC `defrule` (macro) References: - 3 : Rules - 3.1.2.1 : Example - 3.2.2.1 : Example - 6.1.1 : Meta Rule Protocol - 6.1.1.4 : Reasoning with Certainty Factors - 6.2.3.1 : Pattern Matching - 6.2.3.2 : Tail Recursion - 6.3.1 : Example - 6.4.1 : Example - 6.5.2 : The Current Inferencing State ``` -------------------------------- ### Example Rules for Car Maintenance Diagnosis Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-appb-3 These Lisp rules demonstrate the application of the uncertain reasoning facility to a simplified car maintenance diagnostic problem. It defines knowledge base structures for `start`, `symptom`, `fault`, and `remedy`, and establishes a `diagnose` context. Various forward-chaining rules are provided to assert initial conditions and to update the certainty factors of potential faults based on observed symptoms, using the `implication-strength` and `add-evidence` functions. ```Lisp ;;; ---------------- SOME EXAMPLE RULES --------------- ;;; to run: (run-diagnose) (def-kb-struct start) (def-kb-class symptom (uncertain-kb-object) ((type :initarg :type))) (def-kb-class fault (uncertain-kb-object) ((type :initarg :type))) (def-kb-class remedy (uncertain-kb-object) ((type :initarg :type))) ;;; this context sets up the initial hypotheses and ;;; gathers evidence this does not need the meta ;;; -interpreter as that's only necessary for ;;; transparent assignment of certainty factors to new ;;; objects (defcontext diagnose :strategy ()) (defrule start-rule :forward :context diagnose (start ?s) --> (assert (symptom ? type over-heat c-factor 1)) (assert (symptom ? type power-loss c-factor 1)) (assert (fault ? type lack-of-oil c-factor 0.5)) (assert (fault ? type lack-of-water c-factor 0)) (assert (fault ? type battery c-factor 0)) (assert (fault ? type unknown c-factor 0)) (context (cure))) ; next context onto agenda (defrule diagnose1 :forward :context diagnose (symptom ?s type over-heat) (fault ?f type lack-of-water) --> ((implication-strength 0.9)) ((add-evidence ?f ?s))) (defrule diagnose2 :forward :context diagnose (symptom ?s type overheat) (fault ?f type unknown) --> ((implication-strength 0.1)) ((add-evidence ?f ?s))) (defrule diagnose3 :forward :context diagnose (symptom ?s type wont-start) (fault ?f type battery) --> ((implication-strength 0.9)) ((add-evidence ?f ?s))) (defrule diagnose4 :forward :context diagnose (symptom ?s type wont-start) (fault ?f type unknown) --> ((implication-strength 0.1)) ((add-evidence ?f ?s))) (defrule diagnose5 :forward :context diagnose (symptom ?s type power-loss) (fault ?f type lack-of-oil) --> ((implication-strength 0.9)) ((add-evidence ?f ?s))) (defrule diagnose6 :forward :context diagnose (symptom ?s type power-loss) (fault ?f type unknown) --> ``` -------------------------------- ### Example Usage of defcontext Macro Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-11 Illustrates how to use the `defcontext` macro to define contexts with different conflict resolution strategies and optional meta-interpreters in Lisp. The examples show basic context definition and a more complex one with a custom meta-interpreter. ```Lisp (defcontext my-context :strategy (priority recency)) (defcontext another-context :strategy (order) :meta ((start-cycle) (instantiation ?inst) (fire-rule) (cut) (another-context))) ``` -------------------------------- ### LispWorks KW: Example Rule with Explanation Integration Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-appb-2 This Lisp code provides an example `defrule` (`mb7`) from the Monkey and Banana problem. It demonstrates how to use the `defexplain` macro to attach 'why', 'what', and 'because' explanations to a rule. This snippet illustrates the practical application of the explanation facility within a rule-based system. ```Lisp (defrule mb7 :forward :context mab (goal ?g status active type holds object ?w) (object ?o1 kb-name ?w at ?p on floor) (monkey ?m at ?p holds nil) --> ((format t "~%Grab ~s" ?w)) (assert (monkey ?m holds ?w)) (assert (goal ?g status satisfied))) (defexplain mb7 :why ("Monkey is at the ~s which is on the floor" ?w) :what ("Monkey grabs the ~s" ?w) :because ("Monkey needs the ~s somewhere else" ?w)) ``` -------------------------------- ### Lisp Example: Get Inferencing State Name Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-26 A practical Lisp code example demonstrating how to call the `inferencing-state-name` function using the global `*inferencing-state*` variable to retrieve its name. ```Lisp (inferencing-state-name *inferencing-state*) ``` -------------------------------- ### Lisp Examples for assert Backward Chaining Goal Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-3 Illustrative Lisp code examples demonstrating the usage of the `assert` backward chaining goal to create or modify objects in the KnowledgeWorks object base. ```Lisp (assert (truck ?truck driver ?driver)) (assert (possible-trucks ? trucks (?truck . ?trucks)) ``` -------------------------------- ### Lisp `any`, `findall`, and `findallset` Function Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-6 Examples showcasing the `any`, `findall`, and `findallset` interface functions, which are simpler wrappers around `logic`. These demonstrate retrieving the first solution, all solutions, and all unique solutions respectively, highlighting their behavior with duplicate results. ```Lisp (any '(?x is the factorial of 5) '(fact 5 ?x)) ``` ```Lisp (findall '(?x is a color) '(color ?x)) ``` ```Lisp (findall '?y '(or (= ?y 5) (= ?y 5))) ``` ```Lisp (findallset '?y '(or (= ?y 5) (= ?y 5))) ``` -------------------------------- ### Extended Conversion Example: Monkey and Banana Problem Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-appd-1 This comprehensive example demonstrates the full conversion of an OPS5 rulebase for the Monkey and Banana problem into its KnowledgeWorks equivalent. It includes the transformation of `strategy`, `literalize`, and multiple `p` rules, showcasing how an entire system can be migrated while leveraging KnowledgeWorks' advanced features like named classes and contexts. ```OPS5 (strategy mea) (literalize monkey name at on holds) (literalize object name at weight on) (literalize goal status type object to) (literalize start) (p mb1 (goal ^status active ^type holds ^object ) (object ^name ^at

^on ceiling) --> (make goal ^status active ^type move ^object ladder ^to

)) (p mb4 {(goal ^status active ^type holds ^object ) } (object ^name ^at

^on ceiling) (object ^name ladder ^at

) {(monkey ^on ladder ^holds nil) } --> (write (crlf) Grab ) (modify ^status satisfied) (modify ^holds )) (p mb8 (goal ^status active ^type move ^object ^to

) (object ^name ^weight light ^at <>

) --> (make goal ^status active ^type holds ^object )) ``` ```KnowledgeWorks Lisp (defcontext ops5 :strategy (mea lex specificity)) (def-named-kb-class monkey () ((at :initform nil) (on :initform nil) (holds :initform nil))) (def-named-kb-class object () ((at :initform nil) (weight :initform nil) (on :initform nil))) (def-kb-struct goal status type object to) (def-kb-struct start) (defrule mb1 :forward :context ops5 (goal ? status active type holds object ?w) (object ? name ?w at ?p on ceiling) --> (assert (goal ? status active type move object ladder to ?p))) (defrule mb4 :forward :context ops5 (goal ?g status active type holds object ?w) (object ? name ?w at ?p on ceiling) (object ? name ladder at ?p) (monkey ?m on ladder holds nil) --> ((format t "~%Grab ~S" ?w)) (assert (goal ?g status satisfied)) (assert (monkey ?m holds ?w))) (defrule mb8 :forward :context ops5 (goal ? status active type move object ?o to ?p) (object ? name ?o weight light at ?q) (test (not (eq ?q ?p))) --> (assert (goal ? status active type holds object ?o))) ``` -------------------------------- ### Lisp: Example Usage of infer Function Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-24 An example demonstrating how to call the `infer` function in Lisp, specifying a list of contexts (`my-context` and `another-context`) for the inference engine to use. ```Lisp (infer :contexts '(my-context another-context)) ``` -------------------------------- ### KnowledgeWorks with-rule-actions Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `with-rule-actions` macro. ```APIDOC `with-rule-actions` (macro) ``` -------------------------------- ### Example: Defining a Custom Context Using `standard-context` Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-56 This Lisp example demonstrates how to define a custom context, `my-context1`, and integrate `standard-context` as its meta-interpreter. The `:meta` option allows specifying a list of goals to be executed when the context is entered, here including a `format` call for debugging and the `standard-context` goal to handle the default inference behavior. ```Lisp (defcontext my-context1 :meta (((format t "~%Entering context MY-CONTEXT1")) (standard-context))) ``` -------------------------------- ### Lisp Example: Retrieving Object Name with kb-name Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-32 An example demonstrating how to use the `kb-name` function to retrieve the name of a KnowledgeWorks object obtained via `get-kb-object`. ```Lisp (kb-name (get-kb-object 'fred)) ; returns FRED ``` -------------------------------- ### Lisp Examples: Using the `context` Backward Chaining Goal Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-7 Practical examples demonstrating the invocation of the `context` backward chaining goal in Lisp. Shows usage with a literal context list and with variables that are expected to be bound to context names. ```Lisp (context (my-context)) (context (?x ?y)) ; if ?x ?y bound to context names ``` -------------------------------- ### Lisp: Example Usage of find-inferencing-state Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-21 A simple Lisp example demonstrating how to call the `find-inferencing-state` function to retrieve or create an inferencing state named 'my-state'. ```Lisp (find-inferencing-state 'my-state) ``` -------------------------------- ### Lisp findall Example: Member Check Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-20 Demonstrates using `findall` to find all elements `?x` that are members of the list `(1 2 3)`, returning a list of instantiated patterns. This example shows how `findall` can be used for simple list membership queries. ```Lisp (findall '(?x is in (1 2 3)) '(member ?x (1 2 3))) ``` -------------------------------- ### Lisp Example: Binding conflict-set Variable Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-6 This Lisp example demonstrates how to use the `conflict-set` goal. It binds the `?conflict-set` variable to the list of all existing rule instantiations in the current execution context, as ordered by the conflict resolution strategy. ```Lisp (conflict-set ?conflict-set) ``` -------------------------------- ### KnowledgeWorks: defexplain Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index References to `defexplain`, likely a mechanism for defining explanation facilities within KnowledgeWorks. ```APIDOC defexplain References: - 6.1.1.3 : A Simple Explanation Facility (kw-advanced-topics-1.htm#advanced-topics_marker-line-218) - 6.1.1.3 : A Simple Explanation Facility (kw-advanced-topics-1.htm#advanced-topics_marker-line-244) ``` -------------------------------- ### API Reference: return (syntax) Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents the `return` keyword used within Forward Chaining Syntax and Contexts. ```APIDOC return Type: Keyword/Syntax Context: 3.1.2 : Forward Chaining Syntax, 3.1.5.2 : Contexts ``` -------------------------------- ### API Reference: return (backward chaining goal) Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents the `return` concept specifically as a backward chaining goal. ```APIDOC return backward chaining goal Type: Backward Chaining Goal ``` -------------------------------- ### KnowledgeWorks: Defining Contexts Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index General reference to the process of defining contexts within the KnowledgeWorks rule system. ```APIDOC Defining Contexts References: - 3.1.6.1 : Defining Contexts (kw-rules-1.htm#rules_marker-line-416) ``` -------------------------------- ### Lisp Examples: Using -specificity in defcontext Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-55 Illustrative Lisp code snippets demonstrating how to integrate the `-specificity` tactic into context definitions using `defcontext` for conflict resolution strategies. These examples show both direct application and combination with other strategies like `priority`. ```Lisp (defcontext my-context1 :strategy (-specificity)) (defcontext my-context2 :strategy (priority -specificity)) ``` -------------------------------- ### KnowledgeWorks Menu Item: Classes Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the 'Classes' menu item, which provides access to the Class Browser. ```APIDOC Menu Item: Classes Reference: 2.4.3 : Class Browser ``` -------------------------------- ### API Reference: recorda Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents the `recorda` built-in predicate. ```APIDOC recorda Type: Built-in Predicate Context: A.12 : Built-in Predicates ``` -------------------------------- ### Load Tutorial System Definition Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-tutorial-2 Loads the 'defsystem' file, which defines the structure and components of the tutorial system. This prepares the environment for compiling and loading the main tutorial components. ```Lisp (load "defsystem") ``` -------------------------------- ### API Reference: recordz Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents the `recordz` built-in predicate. ```APIDOC recordz Type: Built-in Predicate Context: A.12 : Built-in Predicates ``` -------------------------------- ### Lisp Example: Retrieve All Inferencing States Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-36 Illustrates a simple call to the `list-all-inferencing-states` function in Lisp to retrieve a list of all currently known inferencing states. ```Lisp (list-all-inferencing-states) ``` -------------------------------- ### KnowledgeWorks def-kb-struct Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `def-kb-struct` macro, specifically for defining KnowledgeWorks structures. ```APIDOC `def-kb-struct` (macro) Reference: 6.2.1.1 : KnowledgeWorks Structures ``` -------------------------------- ### KnowledgeWorks def-named-kb-class Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `def-named-kb-class` macro, focusing on its application for defining named classes. ```APIDOC `def-named-kb-class` (macro) Reference: 4.1.2 : Named Classes ``` -------------------------------- ### Lisp defrule Macro Usage Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-15 Illustrative examples demonstrating the use of the `defrule` macro in LispWorks KnowledgeWorks. The first example shows a forward-chaining rule (`move-train`) for updating train positions based on signal status. The second example shows a backward-chaining rule (`link-exists`) for determining if a link exists between two towns, either directly or via a route. ```Lisp (defrule move-train :forward :context trains (train ?train position ?train-pos) (signal ?signal position ?signal-pos color green) (test (= ?signal-pos (1+ ?train-pos))) --> ((format t "~%Train moving to ~S" ?signal-pos)) (assert (signal ?signal color red)) (assert (train ?train position ?signal-pos))) (defrule link-exists :backward ((link-exists ?town1 ?town2) <-- (or (link ?link town1 ?town1 town2 ?town2) (link ?link town2 ?town1 town1 ?town2)) (cut)) ((link-exists ?town1 ?town2) <-- (route-exists ?town1 ?town2))) ``` -------------------------------- ### Compile and Load ANIMAL System Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-tutorial-2 Compiles and loads the 'ANIMAL' system, which includes rules and CLOS objects for the tutorial. The ':load t' argument ensures immediate loading, and ':target-directory (get-temp-directory)' specifies a temporary location for compiled files. ```Lisp (compile-system "ANIMAL" :load t :target-directory (get-temp-directory)) ``` -------------------------------- ### KnowledgeWorks make-inferencing-state Function Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `make-inferencing-state` function, used for creating and managing inferencing states. ```APIDOC `make-inferencing-state` (function) Reference: 6.5.1 : Creating and Maintaining Inferencing States ``` -------------------------------- ### Example: Calling DCGs with Extra Arguments and Observing Results Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-9 Illustrates the execution of Definite Clause Grammars (DCGs) defined with extra arguments using `clog:any`. This example demonstrates a successful match where the extra argument guides the parsing, and also shows cases where the grammar fails to match due to incorrect input patterns. ```Lisp (clog:any '?x '(two-of (start start foo bar) ?x start)) (clog:any '?x '(two-of (not-start start foo bar) ?x start)) (clog:any '?x '(two-of (start not-start foo bar) ?x start)) ``` -------------------------------- ### start-kw Function API Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-59 Detailed API documentation for the `start-kw` function, including its signature, arguments, and behavior within the LispWorks KnowledgeWorks environment. This function initializes the KnowledgeWorks programming environment. ```APIDOC Function: start-kw Package: kw Signature: start-kw &key host Arguments: host: A string. Specifies the machine where the environment is displayed (GTK+ and Motif only). Description: The function `start-kw` starts the KnowledgeWorks programming environment from the initial prompt when the KnowledgeWorks image is started. If the LispWorks IDE is already running, `start-kw` integrates the KnowledgeWorks menu, transforming the podium into the KnowledgeWorks Podium. On GTK+ and Motif, the environment is displayed on the machine specified by the `host` argument, defaulting to the machine where the KnowledgeWorks image is running. Other platforms ignore the `host` argument. ``` -------------------------------- ### KnowledgeWorks Menu Item: context Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the 'context' menu item, related to the Rule Browser functionality. ```APIDOC Menu Item: context Reference: 5.7 : The Rule Browser ``` -------------------------------- ### KnowledgeWorks Menu Item: browse Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the 'browse' menu item, specifically its function within the Class Browser. ```APIDOC Menu Item: browse Reference: 2.4.3 : Class Browser ``` -------------------------------- ### KnowledgeWorks Rule Preconditions Example Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-environment-9 This Lisp-like code snippet illustrates a set of preconditions for a KnowledgeWorks forward chaining rule. It demonstrates how variables ("?person1", "?person2", "?person") are used to match patterns in the object base, and how a 'test' condition can be applied to further constrain the matches. This specific example checks for relationships between people and ensures a non-nil value for "?person". ```Lisp (person ?person1 father ?person) (person ?person2 son ?person) (test (not (eq ?person nil))) ``` -------------------------------- ### Start KnowledgeWorks Forward Chaining Engine (Lisp) Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-tutorial-3 Initiates the KnowledgeWorks forward chaining engine, typically used in the animal guessing game tutorial. This function call prompts the user with questions to infer an animal, and allows for the addition of new animals and distinguishing questions to the system's knowledge base. ```Lisp (infer) ``` -------------------------------- ### Lisp Class: standard-db-object Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents 'standard-db-object', a class likely used for representing objects stored in or interacting with relational databases within KnowledgeWorks. An example of its use is provided. ```Lisp standard-db-object ``` -------------------------------- ### Prolog Macro 'M' Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the 'M' macro as it pertains to Prolog within the KnowledgeWorks system. ```APIDOC macro (in Prolog) Reference: A.8 : Common Prolog Macros ``` -------------------------------- ### Change Directory to KnowledgeWorks Animal Demo Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-tutorial-2 Changes the current working directory of the Lisp environment to the location of the 'animal' demo files within the KnowledgeWorks examples. This is necessary to correctly locate and load the tutorial files. ```Lisp (cd (lispworks:example-file "kw/animal/")) ``` -------------------------------- ### Lisp Class: standard-kb-object Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index References 'standard-kb-object', a core class in KnowledgeWorks, used in examples, the class browser, and discussions on meta-classes and knowledge base class definitions. Multiple references are provided for its various contexts. ```Lisp standard-kb-object ``` -------------------------------- ### Basic Usage of start-kw Function in Lisp Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-59 An example demonstrating how to call the `start-kw` function without any arguments to initiate the KnowledgeWorks programming environment. ```Lisp (start-kw) ``` -------------------------------- ### KnowledgeWorks undefcontext Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `undefcontext` macro, used to undefine previously defined contexts. ```APIDOC `undefcontext` (macro) Reference: 3.1.6.1 : Defining Contexts ``` -------------------------------- ### Define KnowledgeWorks Structure Classes with def-kb-struct Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-13 Examples demonstrating the use of `def-kb-struct` to define KnowledgeWorks structure classes. The first example shows a basic definition and one with a custom print function and initial slot value. The second example illustrates defining a structure that inherits from another KnowledgeWorks structure class. ```Lisp (def-kb-struct start) (def-kb-struct (named-kb-struct (:print-function print-named-kb-struct)) (name (gensym 'named-kb-struct))) ``` ```Lisp (def-kb-struct (possible-trucks-for-load (:include named-kb-struct)) load trucks) ``` -------------------------------- ### Example Usage of get-kb-object in Lisp Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-23 A simple Lisp example demonstrating how to call the `get-kb-object` function to retrieve an object named 'fred' from the KnowledgeWorks object base. ```Lisp (get-kb-object 'fred) ``` -------------------------------- ### Example: Undefining a Specific Forward Chaining Rule Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-rules-1 An example demonstrating the use of the `undefrule` function to remove a specific rule named `move-train` from the rulebase. ```Lisp (undefrule move-train) ``` -------------------------------- ### Reference for add-explanation facility Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documents the `add-explanation` facility. This entry provides a direct reference to its detailed explanation within the manual, specifically concerning its role as a simple explanation facility. ```APIDOC add-explanation ``` -------------------------------- ### KnowledgeWorks make-instance Generic Function Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation references for the KnowledgeWorks extension of the `make-instance` generic function, covering its use with CLOS objects, unnamed/named classes, KnowledgeWorks structures, and logical dependencies. ```APIDOC `make-instance` (generic function extension in KnowledgeWorks) References: - 4.1 : CLOS objects - 4.1.1 : Unnamed Classes - 4.1.2 : Named Classes - 6.2.1.1 : KnowledgeWorks Structures - 6.4 : Logical Dependencies and Truth Maintenance ``` -------------------------------- ### KnowledgeWorks deftactic Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation reference for the KnowledgeWorks `deftactic` macro, used for defining user-definable conflict resolution tactics. ```APIDOC `deftactic` (macro) Reference: 6.1.2 : User-definable Conflict Resolution ``` -------------------------------- ### Common Prolog Debugger: Unleash and Trace Commands Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-7 This snippet demonstrates how to enable full tracing in Common Prolog using the `unleash` and `trace` commands, preparing the environment for detailed observation of predicate execution. ```Prolog |==> (unleash) | |YES. |OK. | |==> (trace) | |YES. |OK. ``` -------------------------------- ### Lisp Example: Create a New Inferencing State Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-37 This Lisp code example demonstrates how to create a new inferencing state named 'my-state' using the `make-inferencing-state` function. ```Lisp (make-inferencing-state 'my-state) ``` -------------------------------- ### Example Usage of with-rule-actions Macro in Lisp Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-63 Demonstrates how to use the `with-rule-actions` macro within a Lisp function. This example finds all pairs of lists that append to a given list `?x` and prints them, then returns NIL. ```Lisp (defun my-fn (?x) "prints all the lists which append to give ?x and then returns NIL" (with-rule-actions (?x) (append ?a ?b ?x) ((format t "~%~S and ~S append to give ~S" ?a ?b ?x)) (fail))) ``` -------------------------------- ### Common Prolog Debugger: Redo, Break, and Session Control Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-prolog-7 This example shows how to use 'c' (creep) during a REDO port, 'b' (break) to enter a recursive interpreter loop for further queries, and finally, how to use `nospy` to clear spy points and `halt` to return to the original execution flow. ```Prolog |?X = (3 . ?0); <- more solutions | |[1] REDO: (MEMBER 3 (3 . ?0))? c <- creep | |[2] CALL: (MEMBER 3 ?0)? b <- break | | |==> (nospy) | |NIL <- current spylist |YES. |OK. | |==> (halt) <- return to original execution |? l <- leap | |?X = (?0 3 . ?1) | |OK. ``` -------------------------------- ### KnowledgeWorks defcontext Macro Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Documentation references for the KnowledgeWorks `defcontext` macro, detailing its role in defining contexts, conflict resolution, and meta rule protocols. ```APIDOC `defcontext` (macro) References: - 3.1.5.2 : Contexts - 3.1.5.3 : Conflict Resolution - 3.1.6 : Examples - 6.1.1 : Meta Rule Protocol ``` -------------------------------- ### Example KnowledgeWorks Structure Definition and Instantiation Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-advanced-topics-2 Demonstrates the definition and instantiation of KnowledgeWorks structures for 'train' and 'signal' entities. These structures, created with `def-kb-struct` and `make-instance`, function as working memory elements for the forward chaining inference engine, analogous to OPS5. ```Lisp (def-kb-struct train position speed) (def-kb-struct signal position color) (make-instance 'train :position 0 :speed 80) (make-instance 'signal :position 10 :color 'red) ``` -------------------------------- ### LispWorks: Define Context with Specificity Strategy Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-54 Illustrative LispWorks code snippets showing how to define new contexts using `defcontext`. These examples demonstrate how to set the conflict resolution strategy to use `specificity` alone or in combination with `priority`. ```Lisp (defcontext my-context1 :strategy (specificity)) ``` ```Lisp (defcontext my-context2 :strategy (priority specificity)) ``` -------------------------------- ### KnowledgeWorks `context` Backward Chaining Goal API Reference Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-7 Formal documentation for the `context` backward chaining goal in KnowledgeWorks, outlining its package, signature, arguments, and detailed behavior for adding contexts to the agenda. ```APIDOC Goal: context Package: kw Signature: context context-list Arguments: context-list: A list of context names. (Required, must be bound if variables) Description: The backward chaining goal `context` adds new contexts `context-list` on top of the agenda (the context stack). The current context is not changed. It is an error if the named contexts do not exist. If `context-list` contains variables, then they must be already bound. ``` -------------------------------- ### Lisp def-kb-class Macro Usage Examples Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-12 Illustrates how to use the `def-kb-class` macro in Lisp to define new CLOS classes for the object base. Examples include defining a base `vehicle` class with a slot and a `truck` class that inherits from `vehicle` and adds its own slot. ```Lisp (def-kb-class vehicle () ((driver :initarg :driver))) (def-kb-class truck (vehicle) ((load :accessor truck-load))) ``` -------------------------------- ### API Documentation for get-kb-object Function Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-ref-23 Comprehensive API documentation for the `get-kb-object` function, detailing its package, signature, arguments, return values, and a description of its behavior and error conditions. ```APIDOC Function: get-kb-object Package: kw Signature: get-kb-object object-name => object Arguments: object-name: A symbol. Values: object: A KnowledgeWorks CLOS object. Description: The function `get-kb-object` returns the KnowledgeWorks object named object-name in the object base of the current inferencing state. If there is no such object an error results. Classes of named objects can be defined using the macro def-named-kb-class. ``` -------------------------------- ### APIDOC: start-cycle Backward Chaining Goal Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-index Reference for the `start-cycle` backward chaining goal in LispWorks KnowledgeWorks. This goal is likely involved in initiating or managing cycles within the backward chaining process. ```APIDOC start-cycle: backward chaining goal ``` -------------------------------- ### Calculated Certainty Factor for New Object Example Source: https://www.lispworks.com/documentation/lw81/kw-m/kw.htm/kw-advanced-topics-1 Illustrates the final calculation of the certainty factor for a newly asserted object, `?obj3`, from the `my-rule` example. It shows how the certainty factors of the source objects (`?obj1`, `?obj2`) are multiplied by the rule's `implication-strength` (0.6). ```Lisp (* (object-c-factor ?obj1) (object-c-factor ?obj2) 0.6) ```