GLAPIArgumentConversion.clp: Overloaded message handlers for generating code

The messages are overloaded in the subclasses of the argument builder class to
provide special functionality for "edge" cases.

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; GLAPIArgumentConversion.clp
;
; Written by Joshua Scoggins
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIArgumentBuilder
  (is-a Object)
  (slot clips-type (type SYMBOL))
  (slot gl-type (type SYMBOL))
  (slot clips-function-name (type SYMBOL))
  (slot index (type INTEGER) (range 1 ?VARIABLE))
  (slot argument-name-base (type SYMBOL STRING))
  (slot data-object-argument-name (type SYMBOL STRING))
  (slot variable-argument-name (type SYMBOL STRING))
  (slot variable-declaration (type STRING))
  (slot data-object-declaration (type STRING))
  (message-handler get-type-check-code)
  (message-handler get-conversion-code))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIArgumentBuilder get-type-check-code ()
						  (return (format nil
												"if(EnvArgTypeCheck(theEnv,%s,%d,%s,&%s) == -1) { return; }"
												?self:clips-function-name
												?self:index
												?self:clips-type
												?self:data-object-argument-name)))
;------------------------------------------------------------------------------
(deffunction types::flatten-type (?symbol)
				 (switch ?symbol
							(case Float then FLOAT)
							(case float then FLOAT)
							(case FLOAT then FLOAT)
							(case double then DOUBLE)
							(case Double then DOUBLE)
							(case DOUBLE then DOUBLE)
							(case integer then INTEGER)
							(case Integer then INTEGER)
							(case INTEGER then INTEGER)
							(case LONG then LONG)
							(case long then LONG)
							(case Long then LONG)
							(case symbol then SYMBOL)
							(case Symbol then SYMBOL)
							(case SYMBOL then SYMBOL)
							(case string then STRING)
							(case String then STRING)
							(case STRING then STRING)
							(default ?symbol)))
;------------------------------------------------------------------------------
(deffunction types::get-conversion-function (?symbol)
				 (bind ?fn-float "DOToFloat")
				 (bind ?fn-double "DOToDouble")
				 (bind ?fn-int "DOToInteger")
				 (bind ?fn-long "DOToLong")
				 (bind ?fn-string "DOToString")
				 (switch ?symbol
							(case FLOAT then ?fn-float)
							(case DOUBLE then ?fn-double)
							(case INTEGER then ?fn-int)
							(case LONG then ?fn-long)
							(case SYMBOL then ?fn-string)
							(case STRING then ?fn-string)
							(default "ERROR_NO_CONVERSION_FOUND")))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIArgumentBuilder get-conversion-code ()
						  (return (format nil "%s = %s(%s);"
												?self:variable-argument-name
												(get-conversion-function
												  (flatten-type ?self:clips-type))
												?self:data-object-argument-name)))
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIMultifieldArgumentBuilder
  (is-a CLIPSGLAPIArgumentBuilder)
  (slot multifield-length-variable-declaration)
  (slot multifield-length-variable-name)
  (slot multifield-pointer-argument-name)
  (slot multifield-pointer-declaration)
  (message-handler get-type-check-code)
  (message-handler get-conversion-code))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIMultifieldArgumentBuilder
						  get-type-check-code primary ()
						  (return (format nil
												"if(EnvArgTypeCheck(theEnv,%s,%d,MULTIFIELD,&%s) == -1) { return; }"
												?self:clips-function-name
												?self:index
												?self:data-object-argument-name)))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIMultifieldArgumentBuilder
						  get-conversion-code ()
						  (return (format nil "%s%n%s%n%s%n%s%n"
												;GetLength
												(format nil "%s = GetDOLength(%s);"
														  ?self:multifield-length-variable-name
														  ?self:data-object-argument-name)
												;GetValue
												(format nil "%s = GetValue(%s);"
														  ?self:multifield-pointer-argument-name
														  ?self:data-object-argument-name)
												;Generate malloc
												(format nil "%s = (%s*)calloc(%s,sizeof(%s));"
														  ?self:variable-argument-name
														  ?self:gl-type
														  ?self:multifield-length-variable-name
														  ?self:gl-type)
												;Conversion
												(format nil "%s%n%s%n%s%n"
														  (format nil "int i, end;%nend = GetDOEnd(%s);"
																	 ?self:data-object-argument-name)
														  (format nil "for(i = GetDOBegin(%s); i<=end; i++) {",
																	 ?self:data-object-argument-name)
														  ;TODO: Continue
														  ))))
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIFixedSizeMultifieldArgumentBuilder
  (is-a CLIPSGLAPIMultifieldArgumentBuilder)
  (slot multifield-size))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (index ?index)
					  (is-pointer FALSE))
			=>
			(make-instance ?name of CLIPSGLAPIArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder-multifield
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (index ?index)
					  (is-pointer TRUE))
			=>
			(make-instance ?name of CLIPSGLAPIMultifieldArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-multifield-conversion-code))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder-multifield-fixed
			(declare (salience 1))
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIFixedArrayArgument)
					  (id ?arg)
					  (index ?index)
					  (size ?size))
			=>
			(make-instance ?name of CLIPSGLAPIFixedMultifieldArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(multifield-size ?size)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-multifield-conversion-code))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-multifield-conversion-code
			?f <- (message (to grouping-update)
								(action make-multifield-conversion-code)
								(arguments ?arg => ?name))
			?o <- (object (is-a CLIPSGLAPIMultifieldArgumentBuilder)
							  (id ?name)
							  (argument-name-base ?anb))
			=>
			(modify ?f (action completed-make-multifield-conversion-code))
			(bind ?baseName (sym-cat (format nil "%s_MF" ?anb)))
			(modify-instance ?o
								  (multifield-pointer-argument-name ?baseName)
								  (multifield-pointer-declaration (format nil "void* %s;" ?baseName))))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-data-object-declaration
			?f <- (message (to grouping-update)
								(action make-data-object-declaration)
								(arguments ?arg => ?name))
			?ab <- (object (is-a CLIPSGLAPIArgumentBuilder)
								(id ?name)
								(argument-name-base ?anb))
			=>
			(modify ?f (action completed-data-object-declaration))
			(bind ?doArg (sym-cat (format nil "%s_DO" ?anb)))
			(modify-instance ?ab
								  (data-object-argument-name ?doArg)
								  (data-object-declaration
									 (format nil "DATA_OBJECT %s;" ?doArg))))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-type-check-contents
			?fct <- (message (to grouping-update)
								  (action make-type-check-code)
								  (arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (parent ?p)
					  (argument-type ?arg-type)
					  (is-pointer FALSE))
			(object (is-a GLAPIFunction)
					  (id ?p)
					  (function-name ?fname))
			?b <- (object (is-a CLIPSGLAPIArgumentBuilder)
							  (id ?name))
			=>
			)
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; GLAPIArgumentConversion.clp
;
; Written by Joshua Scoggins
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIArgumentBuilder
  (is-a Object)
  (slot clips-type (type SYMBOL))
  (slot gl-type (type SYMBOL))
  (slot clips-function-name (type SYMBOL))
  (slot index (type INTEGER) (range 1 ?VARIABLE))
  (slot argument-name-base (type SYMBOL STRING))
  (slot data-object-argument-name (type SYMBOL STRING))
  (slot variable-argument-name (type SYMBOL STRING))
  (slot variable-declaration (type STRING))
  (slot data-object-declaration (type STRING))
  (message-handler get-type-check-code)
  (message-handler get-conversion-code))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIArgumentBuilder get-type-check-code ()
						  (return (format nil
												"if(EnvArgTypeCheck(theEnv,%s,%d,%s,&%s) == -1) { return; }"
												?self:clips-function-name
												?self:index
												?self:clips-type
												?self:data-object-argument-name)))
;------------------------------------------------------------------------------
(deffunction get-conversion-function (?symbol)
				 (bind ?fn-float "DOToFloat")
				 (bind ?fn-double "DOToDouble")
				 (bind ?fn-int "DOToInteger")
				 (bind ?fn-long "DOToLong")
				 (bind ?fn-string "DOToString")
				 (switch ?symbol
							(case float then ?fn-float)
							(case FLOAT then ?fn-float)
							(case Float then ?fn-float)
							(case double then ?fn-double)
							(case DOUBLE then ?fn-double)
							(case Double then ?fn-double)
							(case integer then ?fn-int)
							(case INTEGER then ?fn-int)
							(case Integer then ?fn-int)
							(case long then ?fn-long)
							(case LONG then ?fn-long)
							(case Long then ?fn-long)
							(case symbol then ?fn-string)
							(case Symbol then ?fn-string)
							(case SYMBOL then ?fn-string)
							(case string then ?fn-string)
							(case String then ?fn-string)
							(case STRING then ?fn-string)
							(default "ERROR_NO_CONVERSION_FOUND")))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIArgumentBuilder get-conversion-code ()
                    (return (format nil "%s = %s(%s);"
									  ?self:variable-argument-name
									  (get-conversion-function ?self:clips-type)
									  ?self:data-object-argument-name)))
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIMultifieldArgumentBuilder
  (is-a CLIPSGLAPIArgumentBuilder)
  (slot multifield-length-variable-declaration)
  (slot multifield-length-variable-name)
  (slot multifield-pointer-argument-name)
  (slot multifield-pointer-declaration)
  (message-handler get-type-check-code)
  (message-handler get-conversion-code))
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIMultifieldArgumentBuilder
 get-type-check-code primary ()
						  (return (format nil
												"if(EnvArgTypeCheck(theEnv,%s,%d,MULTIFIELD,&%s) == -1) { return; }"
												?self:clips-function-name
												?self:index
												?self:data-object-argument-name)))
 (
;------------------------------------------------------------------------------
(defmessage-handler types::CLIPSGLAPIMultifieldArgumentBuilder
 get-conversion-code ()
 (return (format nil "%s%n%s%n%s%n%s%n"
			 ;GetLength
			 (format nil "%s = GetDOLength(%s);"
			  				?self:multifield-length-variable-name
							?self:data-object-argument-name)
			 ;GetValue
			 (format nil "%s = GetValue(%s);"
			  ?self:multifield-pointer-argument-name
			  ?self:data-object-argument-name)
			 ;Conversion
			 ;(format nil "%
			 ;get the multifield pointer out
			)))
;------------------------------------------------------------------------------
(defclass types::CLIPSGLAPIFixedSizeMultifieldArgumentBuilder
  (is-a CLIPSGLAPIMultifieldArgumentBuilder)
  (slot multifield-size))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (index ?index)
					  (is-pointer FALSE))
			=>
			(make-instance ?name of CLIPSGLAPIArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder-multifield
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (index ?index)
					  (is-pointer TRUE))
			=>
			(make-instance ?name of CLIPSGLAPIMultifieldArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-multifield-conversion-code))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-function-argument-builder-multifield-fixed
			(declare (salience 1))
			?f <- (message (to grouping-update)
								(action construct-entry)
								(arguments ?arg => ?name))
			(object (is-a GLAPIFixedArrayArgument)
					  (id ?arg)
					  (index ?index)
					  (size ?size))
			=>
			(make-instance ?name of CLIPSGLAPIFixedMultifieldArgumentBuilder
								(index (+ 1 ?index))
								(parent ?arg)
								(multifield-size ?size)
								(argument-name-base (sym-cat (format nil "arg%d" ?index))))
			(modify ?f (action make-variable-declaration))
			(duplicate ?f (action make-type-check-code))
			(duplicate ?f (action make-data-object-declaration))
			(duplicate ?f (action make-multifield-conversion-code))
			(duplicate ?f (action make-conversion-code)))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-multifield-conversion-code
			?f <- (message (to grouping-update)
								(action make-multifield-conversion-code)
								(arguments ?arg => ?name))
			?o <- (object (is-a CLIPSGLAPIMultifieldArgumentBuilder)
							  (id ?name)
							  (argument-name-base ?anb))
			=>
			(modify ?f (action completed-make-multifield-conversion-code))
			(bind ?baseName (sym-cat (format nil "%s_MF" ?anb)))
			(modify-instance ?o
								  (multifield-pointer-argument-name ?baseName)
								  (multifield-pointer-declaration (format nil "void* %s;" ?baseName))))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-data-object-declaration
			?f <- (message (to grouping-update)
								(action make-data-object-declaration)
								(arguments ?arg => ?name))
			?ab <- (object (is-a CLIPSGLAPIArgumentBuilder)
								(id ?name)
								(argument-name-base ?anb))
			=>
			(modify ?f (action completed-data-object-declaration))
			(bind ?doArg (sym-cat (format nil "%s_DO" ?anb)))
			(modify-instance ?ab
								  (data-object-argument-name ?doArg)
								  (data-object-declaration
									 (format nil "DATA_OBJECT %s;" ?doArg))))
;------------------------------------------------------------------------------
(defrule grouping-update::construct-type-check-contents
			?fct <- (message (to grouping-update)
								  (action make-type-check-code)
								  (arguments ?arg => ?name))
			(object (is-a GLAPIArgument)
					  (id ?arg)
					  (parent ?p)
					  (argument-type ?arg-type)
					  (is-pointer FALSE))
			(object (is-a GLAPIFunction)
					  (id ?p)
					  (function-name ?fname))
			?b <- (object (is-a CLIPSGLAPIArgumentBuilder)
							  (id ?name))
			=>
			)
;------------------------------------------------------------------------------


Added Interactable.clp

Added Interactable.clp

The two objects within this file describe actions to be taken based on the
user's input. It is generic enough so that you can have a wide range of verbs
or virtual theatre look and use.

;Copyright (c) 2012, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
(defclass InteractableObject (is-a Object)
 (slot name (type SYMBOL STRING))
 (multislot valid-stimuli (type SYMBOL)))

(defclass Interaction (is-a Object)
 "Links to a given object and provides an easy way to describe responses to a
 given stimuli"
 (slot stimuli (type SYMBOL))
 (slot count (type NUMBER) (range 0 ?VARIABLE))
 ; by making this a multislot it's possible to define encoding schemes to
 ; perform actions
 (multislot reaction))

error: pathspec 'src/adventure/Interactable.clp' did not match any file(s) known to git


Added the import commands

Added the import commands

;------------------------------------------------------------------------------
;electron-filesystem
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of electron-filesystem nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; import.clp - Defines the import method, a wrapper over load, load*, batch,
; and batch* that makes it possible to do relative includes without having to
; worry about absolute paths
;------------------------------------------------------------------------------
; Assume that etc/sys.clp has already been loaded
(defglobal MAIN
           ?*valid-import-actions* = (create$ load load* batch batch*))
(defgeneric import)

(defmethod import
  ((?action SYMBOL (neq ?action (expand$ ?*valid-import-actions*)))
   (?local-path LEXEME))
  (printout t
            (format nil "Provided action %s is not valid for import" ?action) crlf
            "Valid actions are: " ?*valid-import-actions* crlf)
  (return FALSE))

(defmethod import
  ((?action SYMBOL (not (neq ?action (expand$ ?*valid-import-actions*))))
   (?local-path LEXEME))
  (progn$ (?front ?*path*)
          (if (funcall ?action
                       (format nil "%s/%s" ?front ?local-path)) then
            (return TRUE)))
  (return FALSE))

error: pathspec 'lib/import/import.clp' did not match any file(s) known to git


the single pixel rect is now in definstances

This should make it possible to reset the system and still have this
class.

(defgeneric defrectangle)
(defgeneric quickrect)
(defgeneric defpixel)
(defgeneric pixel:nxn)
(defgeneric pixel:1x1)

(defclass Rectangle
  (is-a Pointer)
  (slot pointer-class
        (source composite)
        (default Rectangle))
  (slot x
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot y
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot bx
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot by
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (message-handler get-points primary))

(defmessage-handler Rectangle get-points ()
                    (create$ ?self:x ?self:y ?self:bx ?self:by))

(defmethod defrectangle
  "Creates a new rectangle object and corresponding pointer"
  ((?name SYMBOL INSTANCE-NAME)
   (?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (make-instance ?name of Rectangle
                 (x ?x)
                 (y ?y)
                 (bx ?bx)
                 (by ?by)
                 (pointer (quickrect ?x ?y ?bx ?by))))
(defmethod defrectangle
  ((?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (defrectangle (gensym*) ?x ?y ?bx ?by))

(defmethod quickrect
  ((?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (new Rectangle ?x ?y ?bx ?by))

(defmethod quickrect
  ((?mf MULTIFIELD INTEGER (>= (length$ ?mf) 4)))
  (quickrect (expand$ (subseq$ ?mf 1 4))))

(defmethod quickrect
  (($?mf MULTIFIELD INTEGER (>= (length$ ?mf) 4)))
  (quickrect ?mf))

(defmethod defpixel
  ((?name SYMBOL INSTANCE-NAME)
   (?x INTEGER)
   (?y INTEGER)
   (?factor INTEGER))
  (defrectangle ?name ?x ?y (+ ?x ?factor) (+ ?y ?factor)))

(defmethod pixel:nxn
  ((?x INTEGER)
   (?y INTEGER)
   (?n INTEGER))
  (quickrect ?x ?y (+ ?x ?n) (+ ?y ?n)))

(defmethod pixel:nxn
  ((?n INTEGER))
  (pixel:nxn 0 0 ?n))

(defmethod pixel:1x1
  ((?x INTEGER)
   (?y INTEGER))
  (pixel:nxn ?x ?y 1))

(defmethod pixel:1x1 ()
  (pixel:1x1 0 0))

(definstances default-rect-classes
              (rect:single-pixel of Rectangle
                (x 0)
                (y 0)
                (bx 1)
                (by 1)
                (pointer (quickrect 0 0 1 1))))

(defgeneric defrectangle)
(defgeneric quickrect)
(defgeneric defpixel)
(defgeneric pixel:nxn)
(defgeneric pixel:1x1)

(defclass Rectangle
  (is-a Pointer)
  (slot pointer-class
        (source composite)
        (default Rectangle))
  (slot x
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot y
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot bx
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot by
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (message-handler get-points primary))

(defmessage-handler Rectangle get-points ()
                    (create$ ?self:x ?self:y ?self:bx ?self:by))

(defmethod defrectangle
  "Creates a new rectangle object and corresponding pointer"
  ((?name SYMBOL INSTANCE-NAME)
   (?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (make-instance ?name of Rectangle
                 (x ?x)
                 (y ?y)
                 (bx ?bx)
                 (by ?by)
                 (pointer (quickrect ?x ?y ?bx ?by))))
(defmethod defrectangle
  ((?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (defrectangle (gensym*) ?x ?y ?bx ?by))

(defmethod quickrect
  ((?x INTEGER)
   (?y INTEGER)
   (?bx INTEGER)
   (?by INTEGER))
  (new Rectangle ?x ?y ?bx ?by))

(defmethod quickrect
  ((?mf MULTIFIELD INTEGER (>= (length$ ?mf) 4)))
  (quickrect (expand$ (subseq$ ?mf 1 4))))

(defmethod quickrect
  (($?mf MULTIFIELD INTEGER (>= (length$ ?mf) 4)))
  (quickrect ?mf))

(defmethod defpixel
  ((?name SYMBOL INSTANCE-NAME)
   (?x INTEGER)
   (?y INTEGER)
   (?factor INTEGER))
  (defrectangle ?name ?x ?y (+ ?x ?factor) (+ ?y ?factor)))

(defmethod pixel:nxn
  ((?x INTEGER)
   (?y INTEGER)
   (?n INTEGER))
  (quickrect ?x ?y (+ ?x ?n) (+ ?y ?n)))

(defmethod pixel:nxn
  ((?n INTEGER))
  (pixel:nxn 0 0 ?n))

(defmethod pixel:1x1
  ((?x INTEGER)
   (?y INTEGER))
  (pixel:nxn ?x ?y 1))

(defmethod pixel:1x1 ()
  (pixel:1x1 0 0))

(defglobal MAIN
           ?*rect:single-pixel* = (send (defrectangle rect:single-pixel 0 0 1 1) get-pointer))


Create task7.clp

Create task7.clp

error: pathspec 'ssu-ai-level-2/chapter6/task7.clp' did not match any file(s) known to git


Start chapter4 for ai

Start chapter4 for ai

(deffacts employees
    (employee Lelyakin 10 2 100000)
    (employee Lelyakina 11 2 100000)
    (employee Timkaev 12 3 110000)
    (employee Timkaeva 13 3 110000)
    (employee Kisurin 13 3 111000)
)

(defrule prem
    (employee ?name ?expierence ?children ?salary)

    (test (or (?children > 2)
              (?expierence >= 5)
          )
    )
      =>
    (assert (premia ?name (* ?salary 0.2)))
)

error: pathspec 'ssu-ai-level-2/chapter4/task1.clp' did not match any file(s) known to git


Removed commented out rules in MergeRules.clp and optimized the inject rules

I modified the rules that inject consumers to just store the set of consumers
in the target instruction if the instruction didn't have any consumers already
defined.

;Copyright (c) 2012, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; MergeRules.clp - Contains all of the merge rules used in the analysis stages
; Written by Joshua Scoggins (11/18/2012)
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::generate-initial-consumer-list
			?f0 <- (message (to dependency-analysis)
								 (action instruction-consumes)
								 (arguments ?a => ?id))
			(not (exists (message (to dependency-analysis)
										 (action instruction-consume-list)
										 (arguments ?id => $?))))
			=>
			(modify ?f0 (action instruction-consume-list)
					  (arguments ?id => ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::generate-initial-producer-list
			?f0 <- (message (to dependency-analysis)
								 (action instruction-produces)
								 (arguments ?a => ?id))
			(not (exists (message (to dependency-analysis)
										 (action instruction-produce-list)
										 (arguments ?id => $?))))
			=>
			(modify ?f0 (action instruction-produce-list)
					  (arguments ?id => ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::add-to-consumer-list
			(declare (salience 1))
			?f0 <- (message (to dependency-analysis)
								 (action instruction-consumes)
								 (arguments ?a => ?id))
			?f1 <- (message (to dependency-analysis)
								 (action instruction-consume-list)
								 (arguments ?id => $?elements))
			=>
			(retract ?f0)
			(modify ?f1 (arguments ?id => $?elements ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::add-to-producer-list
			(declare (salience 1))
			?f0 <- (message (to dependency-analysis)
								 (action instruction-produces)
								 (arguments ?a => ?id))
			?f1 <- (message (to dependency-analysis)
								 (action instruction-produce-list)
								 (arguments ?id => $?elements))
			=>
			(retract ?f0)
			(modify ?f1 (arguments ?id => $?elements ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectConsumers-Producers-And-LocalDependencies
			"Performs the actions of InjectConsumers and
			InjectProducersAndLocalDependencies in a single rule fire."
			(declare (salience 1))
			?f0 <- (message (to dependency-analysis)
								 (action instruction-produce-list)
								 (arguments ?id => $?t0))
			?f1 <- (message (to dependency-analysis)
								 (action instruction-consume-list)
								 (arguments ?id => $?t1))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Consumers $?c)
								  (Producers $?p)
								  (LocalDependencies $?ld))
			=>
			(retract ?f0 ?f1)
			(bind ?cs $?c)
			(bind ?ps $?p)
			(bind ?lds $?ld)
			(object-pattern-match-delay
			  (if (= 0 (length$ ?cs)) then
				 (bind ?cs ?t1)
				 else
				 (progn$ (?target ?t1)
							(if (not (member$ ?target ?cs)) then
							  (bind ?cs (insert$ ?cs 1 ?target)))))
			  (progn$ (?target ?t0)
						 (if (not (member$ ?target ?lds)) then
							(bind ?lds (insert$ ?lds 1 ?target)))
						 (if (not (member$ ?target ?ps)) then
							(bind ?ps (insert$ ?ps 1 ?target))))
			  (modify-instance ?inst (Consumers ?cs) (Producers ?ps)
									 (LocalDependencies ?lds))))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectConsumers
			"Adds a given consumer to the target instruction"
			?fct <- (message (to dependency-analysis)
								  (action instruction-consume-list)
								  (arguments ?id => $?targets))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Consumers $?cs))
			=>
			(retract ?fct)
			(bind ?cons $?cs)
			(object-pattern-match-delay
			  (if (= 0 (length$ ?cons)) then
				 (bind ?cons ?targets)
				 else
				 (progn$ (?target ?targets)
							(if (not (member$ ?target ?cons)) then
							  (bind ?cons (insert$ ?cons 1 ?target))))))
			(modify-instance ?inst (Consumers ?cons)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectProducersAndLocalDependencies
			"Adds a given producer to the target instruction."
			?fct <- (message (to dependency-analysis)
								  (action instruction-produce-list)
								  (arguments ?id => $?targets))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Producers $?ps)
								  (LocalDependencies $?ld))
			=>
			(retract ?fct)
			(bind ?prods $?ps)
			(bind ?lds $?ld)
			(object-pattern-match-delay
			  (progn$ (?target ?targets)
						 (if (not (member$ ?target ?lds)) then
							(bind ?lds (create$ ?lds ?target)))
						 (if (not (member$ ?target ?prods)) then
							(bind ?prods (create$ ?prods ?target)))))
			(modify-instance ?inst (Producers ?prods) (LocalDependencies ?lds)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyInstructionProducers
			?inst <- (object (is-a Instruction)
								  (Producers $?a ?b $?c ?b $?d))
			=>
			;if we find one duplicate instance then just convert the whole thing
			;into a list
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
					  (if (not (member$ ?t ?mid)) then
						 (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (Producers ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyInstructionConsumers
			?inst <- (object (is-a Instruction)
								  (Consumers $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
					  (if (not (member$ ?t ?mid)) then
						 (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (Consumers ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyLocalDependencies
			?inst <- (object (is-a Instruction)
								  (LocalDependencies $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
					  (if (not (member$ ?t ?mid)) then
						 (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (LocalDependencies ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyNonLocalDependencies
			?inst <- (object (is-a Instruction)
								  (NonLocalDependencies $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
					  (if (not (member$ ?t ?mid)) then
						 (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (NonLocalDependencies ?mid)))
;------------------------------------------------------------------------------

;Copyright (c) 2012, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; MergeRules.clp - Contains all of the merge rules used in the analysis stages
; Written by Joshua Scoggins (11/18/2012)
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::generate-initial-consumer-list
         ?f0 <- (message (to dependency-analysis)
				             (action instruction-consumes)
								 (arguments ?a => ?id))
			(not (exists (message (to dependency-analysis)
							          (action instruction-consume-list)
										 (arguments ?id => $?))))
			=>
			(modify ?f0 (action instruction-consume-list)
			            (arguments ?id => ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::generate-initial-producer-list
         ?f0 <- (message (to dependency-analysis)
				             (action instruction-produces)
								 (arguments ?a => ?id))
			(not (exists (message (to dependency-analysis)
							          (action instruction-produce-list)
										 (arguments ?id => $?))))
			=>
			(modify ?f0 (action instruction-produce-list)
			            (arguments ?id => ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::add-to-consumer-list
 (declare (salience 1))
         ?f0 <- (message (to dependency-analysis)
				             (action instruction-consumes)
								 (arguments ?a => ?id))
			?f1 <- (message (to dependency-analysis)
				             (action instruction-consume-list)
								 (arguments ?id => $?elements))
			=>
			(retract ?f0)
			(modify ?f1 (arguments ?id => $?elements ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-merge::add-to-producer-list
 (declare (salience 1))
         ?f0 <- (message (to dependency-analysis)
				             (action instruction-produces)
								 (arguments ?a => ?id))
			?f1 <- (message (to dependency-analysis)
				             (action instruction-produce-list)
								 (arguments ?id => $?elements))
			=>
			(retract ?f0)
			(modify ?f1 (arguments ?id => $?elements ?a)))
;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeConsumers
;			?f0 <- (message (to dependency-analysis)
;								 (action instruction-consumes)
;								 (arguments ?a => ?id))
;			?f1 <- (message (to dependency-analysis)
;								 (action instruction-consumes)
;								 (arguments ?b&~?a => ?id))
;			=>
;			(retract ?f0)
;			(modify ?f1 (action instruction-consume-list)
;					  (arguments ?id => ?a ?b)))
;;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeProducers
;			?f0 <- (message (to dependency-analysis)
;								 (action instruction-produces)
;								 (arguments ?a => ?id))
;			?f1 <- (message (to dependency-analysis)
;								 (action instruction-produces)
;								 (arguments ?b&~?a => ?id))
;			=>
;			(retract ?f0)
;			(modify ?f1 (action instruction-produce-list)
;					  (arguments ?id => ?a ?b)))
;;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeConsumers-Multi
;			?f0 <- (message (to dependency-analysis)
;								 (action instruction-consume-list)
;								 (arguments ?id => $?a))
;			?f1 <- (message (to dependency-analysis)
;								 (action instruction-consume-list)
;								 (arguments ?id => $?b))
;			(test (neq ?f0 ?f1))
;			=>
;			(retract ?f0)
;			(modify ?f1 (arguments ?id => $?a $?b)))
;;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeProducers-Multi
;			?f0 <- (message (to dependency-analysis)
;								 (action instruction-produce-list)
;								 (arguments ?id => $?a))
;			?f1 <- (message (to dependency-analysis)
;								 (action instruction-produce-list)
;								 (arguments ?id => $?b))
;			(test (neq ?f0 ?f1))
;			=>
;			(retract ?f0)
;			(modify ?f1 (arguments ?id => $?a $?b)))
;;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeConsumers-Only
;			(declare (salience -2))
;			?f <- (message (to dependency-analysis)
;								(action instruction-consumes)
;								(arguments ?a => ?b))
;			=>
;			(modify ?f (action instruction-consume-list)
;					  (arguments ?b => ?a)))
;;------------------------------------------------------------------------------
;(defrule dependency-analysis-extended-memory-analysis-merge::MergeProducers-Only
;			(declare (salience -2))
;			?f <- (message (to dependency-analysis)
;								(action instruction-produces)
;								(arguments ?a => ?b))
;			=>
;			(modify ?f (action instruction-produce-list)
;					  (arguments ?b => ?a)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectConsumers-Producers-And-LocalDependencies
			"Performs the actions of InjectConsumers and
			InjectProducersAndLocalDependencies in a single rule fire."
			(declare (salience 1))
			?f0 <- (message (to dependency-analysis)
								 (action instruction-produce-list)
								 (arguments ?id => $?t0))
			?f1 <- (message (to dependency-analysis)
								 (action instruction-consume-list)
								 (arguments ?id => $?t1))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Consumers $?c)
								  (Producers $?p)
								  (LocalDependencies $?ld))
			=>
			(retract ?f0 ?f1)
			(bind ?cs $?c)
			(bind ?ps $?p)
			(bind ?lds $?ld)
			(object-pattern-match-delay
			  (progn$ (?target ?t1)
						 (if (not (member$ ?target ?cs)) then
							(bind ?cs (insert$ ?cs 1 ?target))))
			  (progn$ (?target ?t0)
						 (if (not (member$ ?target ?lds)) then
							(bind ?lds (insert$ ?lds 1 ?target)))
						 (if (not (member$ ?target ?ps)) then
							(bind ?ps (insert$ ?ps 1 ?target))))
			  (modify-instance ?inst (Consumers ?cs) (Producers ?ps)
									 (LocalDependencies ?lds))))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectConsumers
			"Adds a given consumer to the target instruction"
			?fct <- (message (to dependency-analysis)
								  (action instruction-consume-list)
								  (arguments ?id => $?targets))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Consumers $?cs))
			=>
			(retract ?fct)
			(bind ?cons $?cs)
			(object-pattern-match-delay
			  (progn$ (?target ?targets)
						 (if (not (member$ ?target ?cons)) then
							(bind ?cons (insert$ ?cons 1 ?target)))))
			  (modify-instance ?inst (Consumers ?cons)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-inject::InjectProducersAndLocalDependencies
			"Adds a given producer to the target instruction."
			?fct <- (message (to dependency-analysis)
								  (action instruction-produce-list)
								  (arguments ?id => $?targets))
			?inst <- (object (is-a Instruction)
								  (id ?id)
								  (Producers $?ps)
								  (LocalDependencies $?ld))
			=>
			(retract ?fct)
			(bind ?prods $?ps)
			(bind ?lds $?ld)
			(object-pattern-match-delay
			  (progn$ (?target ?targets)
						 (if (not (member$ ?target ?lds)) then
						   (bind ?lds (create$ ?lds ?target)))
						 (if (not (member$ ?target ?prods)) then
						  (bind ?prods (create$ ?prods ?target)))))
			  (modify-instance ?inst (Producers ?prods) (LocalDependencies ?lds)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyInstructionProducers
			?inst <- (object (is-a Instruction)
								  (Producers $?a ?b $?c ?b $?d))
			=>
			;if we find one duplicate instance then just convert the whole thing
			;into a list
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
			        (if (not (member$ ?t ?mid)) then
						   (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (Producers ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyInstructionConsumers
			?inst <- (object (is-a Instruction)
								  (Consumers $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
			        (if (not (member$ ?t ?mid)) then
						   (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (Consumers ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyLocalDependencies
			?inst <- (object (is-a Instruction)
								  (LocalDependencies $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
			        (if (not (member$ ?t ?mid)) then
						   (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (LocalDependencies ?mid)))
;------------------------------------------------------------------------------
(defrule dependency-analysis-extended-memory-analysis-make-set::SetifyNonLocalDependencies
			?inst <- (object (is-a Instruction)
								  (NonLocalDependencies $?a ?b $?c ?b $?d))
			=>
			(bind ?mid (create$ ?b))
			(bind ?all (create$ ?a ?c ?d))
			(progn$ (?t ?all)
			        (if (not (member$ ?t ?mid)) then
						   (bind ?mid (insert$ ?mid (+ ?t-index 1) ?t))))
			(modify-instance ?inst (NonLocalDependencies ?mid)))
;------------------------------------------------------------------------------


Fixed a bug where dendrite was not importing cortex

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; Library.clp - Defines the dendrite module and loads all corresponding files.
;
; Written by Joshua Scoggins
; Started on 3/6/2013
;------------------------------------------------------------------------------
; Define the module
;------------------------------------------------------------------------------
(defmodule dendrite
			  (import cortex ?ALL)
			  (export ?ALL))
;------------------------------------------------------------------------------
; Load the corresponding types and functions
;------------------------------------------------------------------------------
(batch* "lib/dendrite/Interactable.clp")
(batch* "lib/dendrite/Interaction.clp")
(batch* "lib/dendrite/Event.clp")
(batch* "lib/dendrite/Item.clp")
(batch* "lib/dendrite/Entity.clp")
(batch* "lib/dendrite/Player.clp")
(batch* "lib/dendrite/Room.clp")

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; Library.clp - Defines the dendrite module and loads all corresponding files.
;
; Written by Joshua Scoggins
; Started on 3/6/2013
;------------------------------------------------------------------------------
; Define the module
;------------------------------------------------------------------------------
(defmodule dendrite (export ?ALL))
;------------------------------------------------------------------------------
; Load the corresponding types and functions
;------------------------------------------------------------------------------
(batch* "lib/dendrite/Interactable.clp")
(batch* "lib/dendrite/Interaction.clp")
(batch* "lib/dendrite/Event.clp")
(batch* "lib/dendrite/Item.clp")
(batch* "lib/dendrite/Entity.clp")
(batch* "lib/dendrite/Player.clp")
(batch* "lib/dendrite/Room.clp")


LoadEngine.clp: Modified the file to use initialize-adventure-engine

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; LoadEngine.clp - Runs the GLConstantConversion expert system
; Written by Joshua Scoggins
;------------------------------------------------------------------------------
(initialize-adventure-engine)
;------------------------------------------------------------------------------
(load-library cortex)
(load-library dendrite)
(load-library lobe)

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; LoadEngine.clp - Runs the GLConstantConversion expert system
; Written by Joshua Scoggins
;------------------------------------------------------------------------------
(clear)
;relative to the root of the source directory
(batch* "init/Library.clp")
;------------------------------------------------------------------------------
(load-library cortex)
(load-library dendrite)
(load-library lobe)


Added wrappers for the Point native type

; point.clp - classes and methods to wrap around the Point native type

(defgeneric quickpoint)
(defgeneric defpoint)
(defgeneric to-point)
(defclass Point
  (is-a Pointer)
  (slot pointer-class
        (source composite)
        (default Point))
  (slot x
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (slot y
        (type INTEGER)
        (access initialize-only)
        (storage local)
        (default ?NONE))
  (message-handler get-points primary))

(defmessage-handler Point get-points ()
                    (create$ ?self:x ?self:y))

(defmethod defpoint
  "Creates a new point object and corresponding pointer"
  ((?name SYMBOL INSTANCE-NAME)
   (?x INTEGER)
   (?y INTEGER))
  (make-instance ?name of Point
                 (x ?x)
                 (y ?y)
                 (pointer (quickpoint ?x ?y))))

(defmethod defpoint
  ((?x INTEGER)
   (?y INTEGER))
  (defpoint (gensym*) ?x ?y))

(defmethod quickpoint
  ((?x INTEGER)
   (?y INTEGER))
  (new Point ?x ?y))

(defmethod to-point
  ((?mf INTEGER MULTIFIELD (= (length$ ?mf) 2)))
  (quickpoint (expand$ ?mf)))

(defmethod to-point
  ((?mf INTEGER MULTIFIELD (> (length$ ?mf) 2)))
  (quickpoint (nth$ 1 ?mf)
              (nth$ 2 ?mf)))
(defmethod to-point
  (($?mf INTEGER (>= (length$ ?mf) 2)))
  (to-point ?mf))

(definstances default-point-classes
              (ZP of Point
                  (x 0)
                  (y 0)
                  (pointer (quickpoint 0 0))))

error: pathspec 'lib/chicanery/point.clp' did not match any file(s) known to git


Added shell.clp - used for accessing the electron shell

;------------------------------------------------------------------------------
;electron-filesystem
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of electron-filesystem nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; shell.clp - Logic used to startup the electron shell with all of the electron
;             settings activated.
;------------------------------------------------------------------------------
(defglobal MAIN
           ; Change the value of this global to change the name of the
           ; corresponding shell variable.
           ?*electron-fs-root* = ElectronFSRoot
           ; Use this to make sure that we fail out if we can't bootstrap
           ?*fsys* = (progn (bind ?result (get-shell-variable ?*electron-fs-root*))
                            (if (not ?result) then
                              (printout t "ERROR: " ?*electron-fs-root* " not defined - Exiting" crlf)
                              (exit)
                              else
                              ?result)))
; Can't do loads within defglobal calls because it could cause crashes if
; we do a defglobal within a defglobal.

; Load the filesystem base points
(load* (format nil "%s/etc/sys.clp" ?*fsys*))
; Load the system base (import commands)
(load* (format nil "%s/import/import.clp" ?*lib*))
(import load* util/message.clp)
(import load* util/strings.clp)
(import batch* os/os.clp)

error: pathspec 'logic/shell.clp' did not match any file(s) known to git


shorter CASP version

shorter CASP version

% >>> addition to input.lp <<<
ordered(order(O),product(A),number(N)) :- init(object(order,O),   value(line,(A,N))).
onShelf(product(A),shelf(S),number(N)) :- init(object(product,A), value(on,  (S,N))).

#include "/home/torsten/local/lib/clingcon/csp.lp". % CHECK MAX

&dom{N..N} = amountMissing(A,O,0) :- ordered(O,A,number(N)).
&dom{0..N} = amountMissing(A,O,T) :- ordered(O,A,number(N)), time(T).
&dom{N..N} = amountOnShelf(A,S,0) :- onShelf(A,S,number(N)).
&dom{0..N} = amountOnShelf(A,S,T) :- onShelf(A,S,number(N)), time(T).

&dom{0..N} =  pick(A,O,S,T) :- ordered(O,A,number(N)), onShelf(A,S), time(T).

{ pick(A,O,S,T) : ordered(O,A), onShelf(A,S) } 1 :- time(T). % pick one article at a time at one picking station (via order)

:- pick(_,O,_,T), target(O,P), not serves(_,P,T).
:- pick(A,O,S,T), target(O,P),     serves(R,P,T), not carries(R,S,T).
:- pick(A,O,S,T), &sum{ amountOnShelf(A,S,T-1); -pick(A,O,S,T) } < 0.

:-     pick(A,O,S,T), onShelf(A,S),               &sum{ amountOnShelf(A,S,T-1); -amountOnShelf(A,S,T); -pick(A,O,S,T) } != 0.
:-     pick(A,O,S,T),               ordered(O,A), &sum{ amountMissing(A,O,T-1); -amountMissing(A,O,T); -pick(A,O,S,T) } != 0.
:-     pick(A,O,S,T),                             &sum{                                                 pick(A,O,S,T) }  = 0.

:- not pick(A,_,S,T), onShelf(A,S),               &sum{ amountOnShelf(A,S,T-1); -amountOnShelf(A,S,T)                         } != 0, time(T).
:- not pick(A,O,_,T),               ordered(O,A), &sum{ amountMissing(A,O,T-1); -amountMissing(A,O,T)                         } != 0, time(T). % >>> REPORT MAX!!! <<<
:- not pick(A,O,S,T), onShelf(A,S), ordered(O,A), &sum{                                                 pick(A,O,S,T) } != 0, time(T).
%*
:-                    onShelf(A,S),               &sum{ amountOnShelf(A,S,T-1); -amountOnShelf(A,S,T)                         }  < 0, time(T).
:-                                  ordered(O,A), &sum{ amountMissing(A,O,T-1); -amountMissing(A,O,T)                         }  < 0, time(T).
*%

error: pathspec 'quantitiesS.clp' did not match any file(s) known to git


added the knowledge template

added the knowledge template

This template is meant to allow me to pass extra information between passes so
that we can control execution.

;------------------------------------------------------------------------------
;Copyright (c) 2012, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; Templates.clp - Contains the deftemplates used to by LibIndirect
;------------------------------------------------------------------------------
(deftemplate indirect::run-passes
 (slot on (type SYMBOL INSTANCE-NAME INTEGER)
          (allowed-classes InteropObject))
 (multislot passes (type SYMBOL STRING)))
;------------------------------------------------------------------------------
(deftemplate indirect::knowledge
 "Used to pass extra knowledge to allow selective invocation to occur"
 (slot about (type SYMBOL INSTANCE-NAME))
 (multislot is))
;------------------------------------------------------------------------------


fixed bug converting from input

fixed bug converting from input

#include <csp>.

&dom{N..N} =   ordered(order(O),product(A),0) :- init(object(order,O),   value(line,(A,N))).
&dom{0..N} =   ordered(order(O),product(A),T) :- init(object(order,O),   value(line,(A,N))), time(T).
&dom{N..N} =   shelved(shelf(S),product(A),0) :- init(object(product,A), value(on,  (S,N))).
&dom{0..N} =   shelved(shelf(S),product(A),T) :- init(object(product,A), value(on,  (S,N))), time(T).

&dom{0..N} = process(product(A),order(O),S,T) :- init(object(order,O),   value(line,(A,N))), shelved(S,product(A)), time(T).

{ process(A,O,S,T) : ordered(O,A), shelved(S,A) } 1 :- time(T). % process one article at a time at one processing station (via order)

:- process(_,O,_,T), target(O,P), not serves(_,P,T).
:- process(A,O,S,T), target(O,P),     serves(R,P,T), not carries(R,S,T).
:- process(A,O,S,T), &sum{ shelved(S,A,T-1); -process(A,O,S,T) } < 0.

:-     process(A,O,S,T), shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T); -process(A,O,S,T) } != 0.
:-     process(A,O,S,T),               ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T); -process(A,O,S,T) } != 0.
:-     process(A,O,S,T),                             &sum{                                     process(A,O,S,T) }  = 0.

:- not process(A,_,S,T), shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T)                    } != 0, time(T).
:- not process(A,O,_,T),               ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T)                    } != 0, time(T).
:- not process(A,O,S,T), shelved(S,A), ordered(O,A), &sum{                                     process(A,O,S,T) } != 0, time(T).

%*
:-                    shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T)                         }  < 0, time(T).
:-                                  ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T)                         }  < 0, time(T).
*%

#include <csp>.

&dom{N..N} =   ordered(order(O),product(A),0) :- init(object(order,O),   value(line,(A,N))).
&dom{0..N} =   ordered(order(O),product(A),T) :- init(object(order,O),   value(line,(A,N))), time(T).
&dom{N..N} =   shelved(shelf(S),product(A),0) :- init(object(product,A), value(on,  (S,N))).
&dom{0..N} =   shelved(shelf(S),product(A),T) :- init(object(product,A), value(on,  (S,N))), time(T).

&dom{0..N} = process(A,O,S,T) :- init(object(order,O),   value(line,(A,N))), shelved(S,A), time(T).

{ process(A,O,S,T) : ordered(O,A), shelved(S,A) } 1 :- time(T). % process one article at a time at one processing station (via order)

:- process(_,O,_,T), target(O,P), not serves(_,P,T).
:- process(A,O,S,T), target(O,P),     serves(R,P,T), not carries(R,S,T).
:- process(A,O,S,T), &sum{ shelved(S,A,T-1); -process(A,O,S,T) } < 0.

:-     process(A,O,S,T), shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T); -process(A,O,S,T) } != 0.
:-     process(A,O,S,T),               ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T); -process(A,O,S,T) } != 0.
:-     process(A,O,S,T),                             &sum{                                     process(A,O,S,T) }  = 0.

:- not process(A,_,S,T), shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T)                    } != 0, time(T).
:- not process(A,O,_,T),               ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T)                    } != 0, time(T). % >>> REPORT MAX!!! <<<
:- not process(A,O,S,T), shelved(S,A), ordered(O,A), &sum{                                     process(A,O,S,T) } != 0, time(T).

%*
:-                    shelved(S,A),               &sum{ shelved(S,A,T-1); -shelved(S,A,T)                         }  < 0, time(T).
:-                                  ordered(O,A), &sum{ ordered(O,A,T-1); -ordered(O,A,T)                         }  < 0, time(T).
*%


WidgetEvent.clp: Added a description to the raise event message-handler

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; WidgetEvent.clp - Base class of all events to cause widgets to do things
;
; Written by Joshua Scoggins
; Started on 3/11/2013
;------------------------------------------------------------------------------
(defclass widget::WidgetEvent
 "Base class of all events in the widget library"
 (is-a Object)
 (slot event-name (type SYMBOL))
 (slot function-to-call (type SYMBOL))
 (message-handler raise-event primary))
;------------------------------------------------------------------------------
(defmessage-handler widget::WidgetEvent raise-event primary
 "Fires the given event"
 ($?args)
 (funcall ?self:function-to-call $?args))
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;Copyright (c) 2013, Joshua Scoggins
;All rights reserved.
;
;Redistribution and use in source and binary forms, with or without
;modification, are permitted provided that the following conditions are met:
;    * Redistributions of source code must retain the above copyright
;      notice, this list of conditions and the following disclaimer.
;    * Redistributions in binary form must reproduce the above copyright
;      notice, this list of conditions and the following disclaimer in the
;      documentation and/or other materials provided with the distribution.
;    * Neither the name of Joshua Scoggins nor the
;      names of its contributors may be used to endorse or promote products
;      derived from this software without specific prior written permission.
;
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
;ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;DISCLAIMED. IN NO EVENT SHALL Joshua Scoggins BE LIABLE FOR ANY
;DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
;ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;------------------------------------------------------------------------------
; WidgetEvent.clp - Base class of all events to cause widgets to do things
;
; Written by Joshua Scoggins
; Started on 3/11/2013
;------------------------------------------------------------------------------
(defclass widget::WidgetEvent
 "Base class of all events in the widget library"
 (is-a Object)
 (slot event-name (type SYMBOL))
 (slot function-to-call (type SYMBOL))
 (message-handler raise-event primary))
;------------------------------------------------------------------------------
(defmessage-handler widget::WidgetEvent raise-event primary ($?args)
 (funcall ?self:function-to-call $?args))
;------------------------------------------------------------------------------