Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

CLIPS (V6.24 06/15/06) readline problem

Help
2011-12-22
2013-09-15
  • Hi,

    Running the script below does not work as described in the book "Expert
    systems". It appears that (readline) does not work in a script. Running
    it in interactive mode works OK. Is this to be expected? I am using
    CLIPS (V6.24 06/15/06)  on Debian Wheezy  AMD64.

    The script loaded with "clips -f test.clp" (the comments are not part of
    the script but added for readability):
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defrule get-name
            =>
            (printout t  "What is your name")
            (bind ?response (readline t))
            (assert (TheResponse ?response))
            (printout t  "Done entering two words" crlf)
    )      

    (reset)
    (facts)
    (agenda)
    (watch all)
    (run)
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

    The output with a manual (facts), showing the empty response:
             CLIPS (V6.24 06/15/06)
    CLIPS> (defrule get-name
            =>
            (printout t  "What is your name")
            (bind ?response (readline t))
            (assert (TheResponse ?response))
            (printout t  "Done entering two words" crlf)
    )      
    CLIPS>
    (reset)
    CLIPS> (facts)
    f-0     (initial-fact)
    For a total of 1 fact.
    CLIPS> (agenda)
    0      get-name: f-0
    For a total of 1 activation.
    CLIPS> (watch all)
    CLIPS> (run)
    FIRE    1 get-name: f-0
    What is your name
    ==> f-1     (TheResponse "")
    Done entering two words
    <== Focus MAIN
    1 rules fired        Run time is 0.000267982999957894 seconds.
    3731.57998886915 rules per second.
    2 mean number of facts (2 maximum).
    1 mean number of instances (1 maximum).
    1 mean number of activations (1 maximum).
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (TheResponse "")
    For a total of 2 facts.
    CLIPS>

    If I (reset) and (run) after this it works:

    CLIPS> (reset)
    ==> Focus MAIN
    MSG >> delete ED:1 (<Instance-initial-object>)
    HND >> delete primary in class USER
           ED:1 (<Instance-initial-object>)
    <== instance  of INITIAL-OBJECT
    HND << delete primary in class USER
           ED:1 (<Stale Instance-initial-object>)
    MSG << delete ED:1 (<Stale Instance-initial-object>)
    <== f-0     (initial-fact)
    <== f-1     (TheResponse "")
    ==> instance  of INITIAL-OBJECT
    MSG >> create ED:1 (<Instance-initial-object>)
    HND >> create primary in class USER
           ED:1 (<Instance-initial-object>)
    HND << create primary in class USER
           ED:1 (<Instance-initial-object>)
    MSG << create ED:1 (<Instance-initial-object>)
    MSG >> init ED:1 (<Instance-initial-object>)
    HND >> init primary in class USER
           ED:1 (<Instance-initial-object>)
    HND << init primary in class USER
           ED:1 (<Instance-initial-object>)
    MSG << init ED:1 (<Instance-initial-object>)
    ==> f-0     (initial-fact)
    ==> Activation 0      get-name: f-0
    CLIPS> (run)
    FIRE    1 get-name: f-0
    What is your nameJoost Kraaijeveld
    ==> f-1     (TheResponse "Joost Kraaijeveld")
    Done entering two words
    <== Focus MAIN
    1 rules fired        Run time is 15.657996376 seconds.
    0.0638651316545686 rules per second.
    2 mean number of facts (2 maximum).
    1 mean number of instances (1 maximum).
    1 mean number of activations (1 maximum).
    CLIPS>

    TIA

    • Groeten,

    Joost Kraaijeveld
    Askesis B.V.
    Molukkenstraat 14
    6524NB Nijmegen
    tel: 024-3888063 / 06-51855277
    fax: 024-3608416
    web: www.askesis.nl

     
  • Gary Riley
    Gary Riley
    2013-09-15

    An extra carriage return at the bottom of your script could be the issue. There should only be a single carriage return after the end of the last command if you want to have the name manually entered. When you batch a file, if any input needs to be read it will also be pulled from the file.