David M
David M

Reputation: 5

What is the CLIPS C function equivalent to the CLIPS statement 'find-all-facts'?

Trying to create a rules file that I then load to evaluate in CLIPS from Swift, I am encountering the following error:

[PRNTUTIL1] Unable to find deftemplate 'message'.

The commented part of my code however works correctly.

////// testing.clp
(deftemplate message
    (slot value))

(defrule hello
    =>
    (assert (message (value "Hello world... from Swift!"))))
func test_CLIPS() {
    var cv = CLIPSValue()
    
    /* ////// THIS WORK OK!!!
    Eval(clipsEnv, "(clear)", nil)
    Build(clipsEnv, "(deftemplate message (slot value))")
    Build(clipsEnv, "(defrule hello => (assert (message (value \"\nFact Slot Retrieval... from Swift!\"))))")
    Eval(clipsEnv, "(reset)", nil)
    Eval(clipsEnv, "(run)", nil)
    Eval(clipsEnv, "(find-all-facts ((?f message)) TRUE)", &cv)
    */
    
    Clear(clipsEnv)
    c_load_rules(name: "testing", type: "clp") // Call CLIPS function Load()
    Reset(clipsEnv)
    Run(clipsEnv, -1)
    Eval(clipsEnv, "(find-all-facts ((?f message)) TRUE)", &cv) //?? CLIPS C equivalent exist/necessary??
    
    print(c_eval(cv: cv)) // Call CLIPS function FactSlotValue and return a string from "lexemeValue->contents"
}
Load testing.clp OK...

(deftemplate message
    (slot value))

(defrule hello
    =>
    (assert (message (value "Hello world... from Swift!"))))

I am trying to load a file with CLIPS templates and CLIPS rules and evaluate it inside an iOS application.

Upvotes: 0

Views: 82

Answers (1)

David M
David M

Reputation: 5

The correct code is:

private func test_CLIPS() {        
    var cv = CLIPSValue()
    let fileURL = Bundle.main.path(forResource: "testing", ofType: "clp")
        
    Clear(clipsEnv)
    Reset(clipsEnv)
    Load(clipsEnv, fileURL)
    Run(clipsEnv, -1)
    Eval(clipsEnv, "(find-all-facts ((?f message)) TRUE)", &cv)
        
    self.message = c_eval(cv: cv)
}

Upvotes: 0

Related Questions