On this page:
3.1 The inference-environment Structure
make-inference-environemnt
default-inference-environment
3.2 Current Inference Environment
current-inference-environment
with-inference-environment
with-new-inference-environment
with-new-child-inference-environment
3.3 Current Inference Environment Fields
current-inference-data-index
current-inference-goal-index
current-inference-rule-nodes
current-inference-exit
current-inference-next-assertion-id
current-inference-assertion-index
current-inference-trace
current-inference-agenda
current-inference-rule
current-inference-strategy
current-inference-parent
current-inference-rules-fired
Version: 4.1.4

3 Inference Environments (Basic)

    3.1 The inference-environment Structure

    3.2 Current Inference Environment

    3.3 Current Inference Environment Fields

An inference environment encapsulates the state of an executing inference system. This state information includes the following:

It is a good practice to create a new inference environment for all of your inference systems. The with-new-inference-environment facilitates this and is used in all of the examples in this document. The primary advantage is to ensure a clean environment for each new execution of the inference system.

The PLT Scheme Inference Collection supports multiple inference environments existing at the same time.

This chapter describes the features of basic simulation environments.

3.1 The inference-environment Structure

The inference-environment structure defines an inference environment.

  (struct inference-environment (data-index
                                 goal-index
                                 rule-nodes
                                 exit
                                 next-assertion-id
                                 assertion-index
                                 trace
                                 agenda
                                 rule
                                 strategy
                                 parent
                                 rules-fired))
  
    data-index : hash-eq?
    goal-index : hash-eq?
    rule-nodes : (listof rule-node?)
    exit : (or/c procedure? false/c)
    next-assertion-id : exact-positive-integer?
    assertion-index : hash-eq?
    trace : boolean?
    agenda : (mlistof rule-instance?)
    rule : (or/c rule-instance? false/c)
    strategy : (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random)
    parent : (or/c inference-environment? false/c)
    rules-fired : exact-nonnegative-integer?

See Section 3.3 Current Inference Environment Fields for more information on accessing the fields of the current inference environment.

(make-inference-environemnt [parent])  inference-environment?
  parent : (or/c inference-environment false/c) = #f

Returns a new inference environment with the given parent inference environment. The newly created inference environment is empty. That is, there are no rule sets activated, no facts are asserted, user specifiable fields have their default values, and no inference is running in the environment.

default-inference-environment

Contains the inference environment that is used as the default value for the current inference environment (see Section 3.2).

3.2 Current Inference Environment

The current inference environment is the inference environment that is the current focus for most of the inference calls. It is both thread and continuation specific.

(current-inference-environment)  inference-environment?
(current-inference-environment env)  void?
  env : inference-environment?

Gets or sets the current inference environment. A guard procedure ensures that the value of current-inference-environment is indeed an inference environment, as determined by inference-environment?, otherwise a type error is raised.

(with-inference-environment env
   body ...+)

Evaluates its body with the current inference environment bound to the value of env.

(with-new-inference-environment
   body ...+)

Evaluates its body with the current inference environment bound to a newly created inference environment. This is the most common way to create and use a new inference environment.

(with-new-child-inference-environment
   body ...+)

Evaluates its body with the current inference environment bound to a newly created inference environment that is a child of the current inference environement.

3.3 Current Inference Environment Fields

The most common way of accessing the current inference environment fields is using the following procedures.

(current-inference-data-index data-index)  void?
  data-index : hash-eq?
(current-inference-data-index)  hash-eq?

Sets or gets the data-index field of the current inference environment.

(current-inference-goal-index data-index)  void?
  data-index : hash-eq?
(current-inference-goal-index)  hash-eq?

Sets or gets the goal-index field of the current inference environment.

(current-inference-rule-nodes rule-nodes)  void?
  rule-nodes : (listof rule-node?)
(current-inference-rule-nodes)  (listof rule-node?)

Sets or gets the rule-nodes field of the current inference environment.

(current-inference-exit exit)  void?
  exit : (or/c procedure? false/c)
(current-inference-exit)  (one-of/c procedure? false/c)

Sets or gets the exit field of the current inference environment.

(current-inference-next-assertion-id next-assertion-id)  void?
  next-assertion-id : exact-positive-integer?
(current-inference-next-assertion-id)
  exact-positive-integer?

Sets or gets the next-assertion-id field of the current inference environment.

(current-inference-assertion-index assertion-index)  void?
  assertion-index : hash-eq?
(current-inference-assertion-index)  hash-eq?

Sets or gets the assertion-index field of the current inference environment.

(current-inference-trace trace)  void?
  trace : boolean?
(current-inference-trace)  boolean?

Sets or gets the trace field of the current inference environment.

(current-inference-agenda agenda)  void?
  agenda : (mlistof rule-instance?)
(current-inference-agenda)  (mlistof rule-instance?)

Sets or gets the agenda field of the current inference environment.

(current-inference-rule rule)  void?
  rule : (or/c rule-instance? false/c)
(current-inference-rule)  (or/c rule-instance? false/c)

Sets or gets the rule field of the current inference environment.

(current-inference-strategy strategy)  void?
  strategy : (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random)
(current-inference-strategy)
  (one-of/c 'depth 'breadth 'order 'simplicity 'complex 'random)

Sets or gets the strategy field of the current inference environment.

(current-inference-parent parent)  void?
  parent : (or/c inference-environment? false/c)
(current-inference-parent)
  (or/c inference-environment? false/c)

Sets or gets the parent field of the current inference environment.

(current-inference-rules-fired trace)  void?
  trace : exact-nonnegative-integer?
(current-inference-rules-fired)  exact-nonnegative-integer?

Sets or gets the rules-fired field of the current inference environment.