Search code examples
clipsexpert-system

Clips: Matching (or not matching an empty string)


I'm try to translate a string piece by piece, so I know when the originating one is empty, then we're done. Question is, how will CLIPS know when there's nothing in the "input" string?

(defrule check-if-empty
    ?phase <- (phase CONVERT)
    (input "code here possibly")
    =>
    (retract ?phase ?input)
    (assert (phase PRINT))
    (return))

Solution

  • The empty string in CLIPS is "", so just replace "code here possibly" with "". There's also no need to place a return at the end of a rule unless you're using modules and want to end execution of rules in the module with the current focus.

    (defrule check-if-empty
        ?phase <- (phase CONVERT)
        ?input <- (input "")
        =>
        (retract ?phase ?input)
        (assert (phase PRINT)))