#lang scheme
(define-values (struct:inference-environment
inference-environment-constructor
inference-environment?
inference-environment-field-ref
set-inference-environment-field!)
(make-struct-type 'inference-environment #f 12 0))
(define inference-environment-data-index
(make-struct-field-accessor
inference-environment-field-ref 0 'data-index))
(define set-inference-environment-data-index!
(make-struct-field-mutator
set-inference-environment-field! 0 'data-index))
(define inference-environment-goal-index
(make-struct-field-accessor
inference-environment-field-ref 1 'goal-index))
(define set-inference-environment-goal-index!
(make-struct-field-mutator
set-inference-environment-field! 1 'goal-index))
(define inference-environment-rule-nodes
(make-struct-field-accessor
inference-environment-field-ref 2 'rule-nodes))
(define set-inference-environment-rule-nodes!
(make-struct-field-mutator
set-inference-environment-field! 2 'rule-nodes))
(define inference-environment-exit
(make-struct-field-accessor
inference-environment-field-ref 3 'exit))
(define set-inference-environment-exit!
(make-struct-field-mutator
set-inference-environment-field! 3 'exit))
(define inference-environment-next-assertion-id
(make-struct-field-accessor
inference-environment-field-ref 4 'next-assertion-id))
(define set-inference-environment-next-assertion-id!
(make-struct-field-mutator
set-inference-environment-field! 4 'next-assertion-id))
(define inference-environment-assertion-index
(make-struct-field-accessor
inference-environment-field-ref 5 'assertion-index))
(define set-inference-environment-assertion-index!
(make-struct-field-mutator
set-inference-environment-field! 5 'assertion-index))
(define inference-environment-trace
(make-struct-field-accessor
inference-environment-field-ref 6 'trace))
(define set-inference-environment-trace!
(make-struct-field-mutator
set-inference-environment-field! 6 'trace))
(define inference-environment-agenda
(make-struct-field-accessor
inference-environment-field-ref 7 'agenda))
(define set-inference-environment-agenda!
(make-struct-field-mutator
set-inference-environment-field! 7 'agenda))
(define inference-environment-rule
(make-struct-field-accessor
inference-environment-field-ref 8 'rule))
(define set-inference-environment-rule!
(make-struct-field-mutator
set-inference-environment-field! 8 'rule))
(define inference-environment-strategy
(make-struct-field-accessor
inference-environment-field-ref 9 'strategy))
(define set-inference-environment-strategy!
(make-struct-field-mutator
set-inference-environment-field! 9 'strategy))
(define inference-environment-parent
(make-struct-field-accessor
inference-environment-field-ref 10 'parent))
(define set-inference-environment-parent!
(make-struct-field-mutator
set-inference-environment-field! 10 'parent))
(define inference-environment-rules-fired
(make-struct-field-accessor
inference-environment-field-ref 11 'rules-fired))
(define set-inference-environment-rules-fired!
(make-struct-field-mutator
set-inference-environment-field! 11 'rules-fired))
(define (make-inference-environment (parent #f))
(inference-environment-constructor
(make-hasheq) (make-hasheq) '() #f 1 (make-hasheq) #f '() #f 'depth parent 0 ))
(define default-inference-environment
(make-inference-environment))
(define current-inference-environment
(make-parameter
default-inference-environment
(lambda (x)
(when (not (inference-environment? x))
(raise-type-error 'current-inference-environment
"inference-environment" x))
x)))
(define current-inference-data-index
(case-lambda
(()
(inference-environment-data-index
(current-inference-environment)))
((data-index)
(set-inference-environment-data-index!
(current-inference-environment) data-index))))
(define current-inference-goal-index
(case-lambda
(()
(inference-environment-goal-index
(current-inference-environment)))
((goal-index)
(set-inference-environment-goal-index!
(current-inference-environment) goal-index))))
(define current-inference-rule-nodes
(case-lambda
(()
(inference-environment-rule-nodes
(current-inference-environment)))
((rule-nodes)
(set-inference-environment-rule-nodes!
(current-inference-environment) rule-nodes))))
(define current-inference-exit
(case-lambda
(()
(inference-environment-exit
(current-inference-environment)))
((exit)
(set-inference-environment-exit!
(current-inference-environment) exit))))
(define current-inference-next-assertion-id
(case-lambda
(()
(inference-environment-next-assertion-id
(current-inference-environment)))
((next-assertion-id)
(set-inference-environment-next-assertion-id!
(current-inference-environment) next-assertion-id))))
(define current-inference-assertion-index
(case-lambda
(()
(inference-environment-assertion-index
(current-inference-environment)))
((assertion-index)
(set-inference-environment-assertion-index!
(current-inference-environment) assertion-index))))
(define current-inference-trace
(case-lambda
(()
(inference-environment-trace
(current-inference-environment)))
((trace)
(set-inference-environment-trace!
(current-inference-environment) trace))))
(define current-inference-agenda
(case-lambda
(()
(inference-environment-agenda
(current-inference-environment)))
((agenda)
(set-inference-environment-agenda!
(current-inference-environment) agenda))))
(define current-inference-rule
(case-lambda
(()
(inference-environment-rule
(current-inference-environment)))
((rule)
(set-inference-environment-rule!
(current-inference-environment) rule))))
(define current-inference-strategy
(case-lambda
(()
(inference-environment-strategy
(current-inference-environment)))
((strategy)
(set-inference-environment-strategy!
(current-inference-environment) strategy))))
(define current-inference-parent
(case-lambda
(()
(inference-environment-parent
(current-inference-environment)))
((parent)
(set-inference-environment-parent!
(current-inference-environment) parent))))
(define current-inference-rules-fired
(case-lambda
(()
(inference-environment-rules-fired
(current-inference-environment)))
((rules-fired)
(set-inference-environment-rules-fired!
(current-inference-environment) rules-fired))))
(define-syntax with-inference-environment
(syntax-rules ()
((with-inference-environment inference-environment
body ...)
(parameterize ((current-inference-environment
inference-environment))
body ...))))
(define-syntax with-new-inference-environment
(syntax-rules ()
((with-new-inference-environment
body ...)
(parameterize ((current-inference-environment
(make-inference-environment)))
body ...))))
(define-syntax with-new-child-inference-environment
(syntax-rules ()
((with-new-child-inference-environment
body ...)
(parameterize ((current-inference-environment
(make-inference-environment
(current-inference-environment))))
body ...))))
(provide
default-inference-environment
current-inference-environment
with-inference-environment
with-new-inference-environment
with-new-child-inference-environment)
(provide/contract
(inference-environment?
(-> any/c boolean?))
(make-inference-environment
(->* () (inference-environment?) inference-environment?))
(inference-environment-data-index
(-> inference-environment? hash?))
(inference-environment-goal-index
(-> inference-environment? hash?))
(inference-environment-rule-nodes
(-> inference-environment? list?))
(inference-environment-exit
(-> inference-environment? (or/c procedure? false/c)))
(set-inference-environment-exit!
(-> inference-environment? (or/c procedure? false/c) void?))
(inference-environment-next-assertion-id
(-> inference-environment? exact-positive-integer?))
(set-inference-environment-next-assertion-id!
(-> inference-environment? exact-positive-integer? void?))
(inference-environment-assertion-index
(-> inference-environment? hash?))
(inference-environment-trace
(-> inference-environment? boolean?))
(inference-environment-agenda
(-> inference-environment? any))
(set-inference-environment-agenda!
(-> inference-environment? any/c void?))
(inference-environment-rule
(-> inference-environment? any))
(set-inference-environment-rule!
(-> inference-environment? any/c void?))
(inference-environment-strategy
(-> inference-environment? symbol?))
(set-inference-environment-strategy!
(-> inference-environment? symbol? void?))
(inference-environment-parent
(-> inference-environment? (or/c inference-environment? false/c)))
(set-inference-environment-parent!
(-> inference-environment? (or/c inference-environment? false/c) void?))
(inference-environment-rules-fired
(-> inference-environment? exact-nonnegative-integer?))
(current-inference-data-index
(case->
(-> hash?)
(-> hash? void?)))
(current-inference-goal-index
(case->
(-> hash?)
(-> hash? void?)))
(current-inference-rule-nodes
(case->
(-> list?)
(-> list? void?)))
(current-inference-exit
(case->
(-> (or/c procedure? false/c))
(-> (or/c procedure? false/c) void?)))
(current-inference-next-assertion-id
(case->
(-> exact-positive-integer?)
(-> exact-positive-integer? void?)))
(current-inference-assertion-index
(case->
(-> hash?)
(-> hash? void?)))
(current-inference-trace
(case->
(-> boolean?)
(-> boolean? void?)))
(current-inference-agenda
(case->
(-> any)
(-> any/c void?)))
(current-inference-rule
(case->
(-> any)
(-> any/c void?)))
(current-inference-strategy
(case->
(-> symbol?)
(-> symbol? void?)))
(current-inference-parent
(case->
(-> (or/c inference-environment? false/c))
(-> (or/c inference-environment? false/c) void?)))
(current-inference-rules-fired
(case->
(-> exact-nonnegative-integer?)
(-> exact-nonnegative-integer? void?)))
)