;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; ACT-R 4.0 model of simple counting
;;
;; to run the model set *start-count* and *end-count* to the
;; numbers you want ACT-R to count over (must be from 0 - 10)
;; Then call:
;; (reset)
;; (run)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; This section contains the interface for the WWW using the
;;; ACT-R on the Web application by Elmar Schwarz

(defvar *start-count* 2)
(defvar *end-count* 5)

(defvar *WWW-interface*)

(setf  *WWW-interface* 
      '((:heading "Counting Example" 2)
        (:table)
        "Start (0-10): "    (:string :sy *start-count*           2)  (:new-row)
        "End (0-10): "     (:string :sy *end-count*   5)  

        (:table-end)
        (:new-para)
        
        (:button "Run model" "(progn 
                              (reset)
                              (run))
                              ")

        (:button "Production Rules" "(let ((prods (no-output (pp))))
                                       (dolist (x prods)
                                         (pp-fct (list x))
                                         (spp-fct (list x))
                                         (format *standard-output* \"~%\")))")
        (:button "Chunk types" "(chunk-type)")
        (:button "Chunks" "(dm)")
        ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(clear-all)

(chunk-type count-order first second)
(chunk-type count-from start end)

(add-dm
   (a ISA count-order first 1 second 2)
   (b ISA count-order first 2 second 3)
   (c ISA count-order first 3 second 4)
   (d ISA count-order first 4 second 5)
   (e ISA count-order first 5 second 6)
   (f ISA count-order first 6 second 7)
   (g ISA count-order first 7 second 8)
   (h ISA count-order first 8 second 9)
   (i ISA count-order first 9 second 10)
   (j ISA count-order first 0 second 1)
   (first-goal ISA count-from start 2 end 5))

(mod-chunk-fct 'first-goal (list 'start (max (min 10 *start-count*) 0) 'end (min (max 0 *end-count* *start-count*) 10)))

(P increment
   =goal>
      ISA         count-from
      start       =num1
   =count>
      ISA         count-order
      first       =num1
      second      =num2
==>
   !output!       (=num1)
   =goal>
      start       =num2
)

(P stop
   =goal>
      ISA         count-from
      start       =num
      end         =num
==>
   !output!       (=num)
   !pop!
)

(spp STOP :Q 1.0 :R 1.0 :A 0.05 :B 0 :STRENGTH 0.0 :VALUE 1)
(goal-focus first-goal)