Menu

#67 Parsing error

1.0
closed
2022-01-06
2021-05-17
E.Leporati
No

This rule fails to parse on 6.40 with the following error:

The single field slot 'elapsed' can only contain a single field value.

ERROR:
E (defrule MAIN::simulation-toggle-running
E (declare (salience 200))
E (status (current-time ?now&~nil))
E ?timer <- (simulation (elapsed ?elapsed))
E (test (neq ?elapsed (timer-elapsed ?timer ?now)))
E =>
E (modify ?timer (elapsed (not ?elapsed))))

The offending line is

(modify ?timer (elapsed (not ?elapsed)))

Changing it to

(bind ?toggled (not ?elapsed))
(modify ?timer (elapsed ?toggled))

fixes the issue.

Discussion

  • Gary Riley

    Gary Riley - 2021-05-27

    I can't reproduce the error with the code you provided. Can you add the code you used for the status and simulation deftemplates as well as the code you're using for the timer-elapsed function?

             CLIPS (6.4 2/9/21)
    CLIPS> 
    (deftemplate status
       (slot current-time))
    CLIPS> 
    (deftemplate simulation
       (slot elapsed))
    CLIPS>    
    (deffunction timer-elapsed ($?args))
    CLIPS>    
    (defrule simulation-toggle-running
       (declare (salience 200))
       (status (current-time ?now&~nil))
       ?timer <- (simulation (elapsed ?elapsed))
       (test (neq ?elapsed (timer-elapsed ?timer ?now)))
       =>
       (modify ?timer (elapsed (not ?elapsed))))
    CLIPS> 
    
     
  • E.Leporati

    E.Leporati - 2021-09-08
    (deftemplate status
        (slot stage
            (allowed-values on-break
                            restarting
                            in-production
                            waiting-effects)
            (default in-production))
        (slot current-time
            (type SYMBOL INTEGER)
            (allowed-symbols nil))
    )
    
    (deftemplate simulation
        (slot feed-back-steam-time
            (allowed-values TRUE FALSE)
            (default FALSE))
        (slot generate-random-process-variable
            (allowed-values TRUE FALSE)
            (default FALSE))
    
        (multislot st-to-pv ; proportion and offset
            (type NUMBER)
            (default 1 0)
            (cardinality 2 2))
    
        (multislot pv-random-fluctuation
            (type NUMBER)
            (default 0 0 1)
            (cardinality 3 3))
    
        (slot elapsed
            (allowed-values TRUE FALSE)
            (default FALSE))
        (slot started-at
            (type SYMBOL INTEGER)
            (allowed-symbols nil))
        (slot duration
            (type INTEGER)
            (default 3600))
        (slot tick
            (type INTEGER)
            (default 10))
    )
    (defgeneric elapsed)
    (defmethod elapsed ((?interval INTEGER) (?since SYMBOL INTEGER) (?now INTEGER))
        (if (eq ?since nil)
         then   FALSE
         else   (>= ?now (+ ?since ?interval)))
    )
    (deffunction timer-elapsed (?timer ?now)
        (elapsed    (fact-slot-value ?timer duration)
                    (fact-slot-value ?timer started-at)
                    ?now)
    )
    
     
    • Gary Riley

      Gary Riley - 2022-01-06

      No issues with this code either.

       
  • Gary Riley

    Gary Riley - 2022-01-06
    • status: new --> closed
    • assigned_to: Gary Riley
     

Log in to post a comment.