X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=if.lisp;h=447f69787db91d9ae9364c3290072654903bc4ec;hb=9c86499fa997e562b8a2434bf2a978f85969eda1;hp=6a0a3c22027967c87508b4a5f921265c80c8487a;hpb=9356b489df2d529f843e4143e8b9528b4d64e186;p=lifp.git diff --git a/if.lisp b/if.lisp index 6a0a3c2..447f697 100644 --- a/if.lisp +++ b/if.lisp @@ -40,9 +40,9 @@ :read-property :rp :read-property- :exec :exec* :abstractobject :name :names :parent :children :flags - :initflags :add-flags :has :hasnt :-> :give + :initflags :add-flags :has :hasnt :-> :give :child :ifclass :object :defaction :*meta* - :move :rmv :ofclass :among + :move :rmv :ofclass :among :below :verb :extend-verb :extend-verb-first :extend-verb-only :extend-verb-only-first :deftoken :string== :matchp :!last! @@ -369,6 +369,10 @@ word in dictionary, add it." (not (intersection flags (flags obj)))) ;(not (subsetp flags (flags obj)))) +(defun child (obj) + "Returns the first child of the object" + (car (children obj))) + (defmethod parser ((obj abstractobject) words) "Default parser. Really bad one." (when (zerop (length words)) (return-from parser 0)) @@ -479,14 +483,14 @@ word in dictionary, add it." (defun read-property- (method self property &rest args) "read-property using specific method. method is one of keywords: - :string :number :object :integer :" + :string :number :object :integer :execute :list" (case method (:string (apply #'read-property-string (slot-value self property) args)) - (:number (apply #'read-property-string (slot-value self property) args)) - (:integer (apply #'read-property-string (slot-value self property) args)) - (:object (apply #'read-property-string (slot-value self property) args)) - (:execute (apply #'read-property-string (slot-value self property) args)) - (:list (apply #'read-property-string (slot-value self property) args)) + (:number (apply #'read-property-number (slot-value self property) args)) + (:integer (apply #'read-property-integer (slot-value self property) args)) + (:object (apply #'read-property-object (slot-value self property) args)) + (:execute (apply #'read-property-execute (slot-value self property) args)) + (:list (apply #'read-property-list (slot-value self property) args)) (t (slot-value self property)))) ;;SECTION 7: IfClass macro and its hairy surroundings @@ -740,7 +744,14 @@ word in dictionary, add it." (defun notin (obj &rest what) "Test whether the object is not in any of other arguments" (notany (lambda (x) (eql (parent obj) x)) what)) - + +(defun below (obj1 obj2) + "Tests whether obj1 is strictly below obj2 in object structure" + (loop for x = obj1 then (parent x) + while x + when (eql x obj2) do (return t) + finally (return nil))) + ;;SECTION 9: Verb functions (defstruct patternlist value) @@ -947,14 +958,15 @@ word in dictionary, add it." ;;React after? t) -(defun run-action (action args &key (time 0)) +(defun run-action (action args &key (time 0) no-output) "Run an action with a given args" (unless (listp args) (setf args (list args))) (setf *after* nil) (let ((*action* action) (*args* args) (*noun* (first args)) - (*second* (second args))) + (*second* (second args)) + (*no-output* no-output)) (when *debug* (format t "[running action: ~a ~a]~%" *action* *args*)) (when *meta* ;;Just do the darn thing!