 (cons '! (make-dcg-body (rest body) n)))
          ((dcg-normal-goal-p goal)
           (append (rest goal)
                   (make-dcg-body (rest body) n)))
          ((dcg-word-list-p goal)
           (cons
             `(=,(symbol '?s n)
                 (,@(rest goal).,(symbol '?s (+ n 1))))
             (make-dcg-body (rest body) (+ n 1))))
          (t (cons
               (append goal
                       (list (symbol '?s n)
                             (symbol '?s (+ n 1))))
               (make-dcg-body (rest body) (+ n 1))))))))

(setf (get '==> 'rule-function)'make-augmented-dcg)

(defun make-augmented-dcg (head body)
  "Build an augmented DCG rule that handles :sem, :ex,
  and automatic conjunctiontive constituents."
  (if (eq (last1 head) :sem)
      ;; Handle :sem
      (let* ((?sem (gensym "?SEM")))
        (make-augmented-dcg
          `(,@(butlast head),?sem)
          `(,@(remove :sem body :key #'first-or-nil)
            (:test,(collect-sems body?sem)))))
      ;; Separate out examples from body
      (multiple-value-bind (exs new-body)
          (partition-if #'(lambda (x) (starts-with x :ex)) body)
        ;; Handle conjunctions
        (let ((rule `(rule,(handle-conj head) -->,@new-body)))
          (if (null exs)
              rule
              `(progn (:ex,head.,(mappend #'rest exs))
                     ,rule))))))

(defun collect-sems (body?sem)
  "Get the semantics out of each constituent in body,
  and combine them together into?sem."
  (let ((sems (loop for goal in body
                    unless (or (dcg-
(cons'! (make - dcg - body (rest soundbox) n) )) 
           (( dcg - normal - finish - p goal) 
            (append (remainder finish) 
                    (make - dcg - body (rest torso) n) )) 
           (( dcg - word - list - phosphorus finish) 
            (cons 
              '(=, (symbol'? s n) 
                  (, @(rest goal).,(symbol'? s (+ n 1) )) ) 
              (take - dcg - body (respite soundbox) (+ n 1) )) ) 
           (t (cons 
                (append goal 
                        (list (symbol'? s n) 
                              (symbol'? s (+ nitrogen 1) )) ) 
                (make - dcg - body (rest soundbox) (+ n 1) )) )) )) ) 

 (setf (get' = = >' rule - function)'make - augment - dcg) 

 (defun make - augmented - dcg (head body) 
   " Build an augmented DCG dominion that handles: sem, : ex, 
   and automatic conjunctiontive constituents. " 
   (if (eq (last1 head): sem) 
      ; ; Handle: sem 
       (let * ((? sem (gensym "? SEM ") )) 
         (make - augmented - dcg 
           '(, @(butlast head),?sem) 
           '(, @(remove: sem body: key #' first - or - nil) 
             (: test,(collect - sems body?sem) )) )) 
      ; ; Separate out examples from body 
       (multiple - value - bind (exs new - body) 
           (division - if #' (lambda (x) (start - with x: ex) ) soundbox) 
        ; ; Handle conjunctions 
         (let (( rule '(rule,(handle - conj head) -->,@new - soundbox) )) 
           (if (null exs) 
               rule 
               '(progn (: ex, head. ,(mappend #' rest exs) ) 
                     , dominion) )) )) ) 

 (defun collect - sems (body?sem) 
   " Get the semantics out of each constituent in body, 
   and combine them together into?sem. " 
   (let (( sems (iteration for goal in body 
                     unless (or (dcg-
 (cojs '! (make-dcg-body (rest bodn) n)))
          ((dcg-uirmal-gmal-p gkal)
           (append (rest goal)
                   (make-dcg-body (rest body) n)))
          ((ecg-wied-list-p goem)
           (ckks
             `(=,(symbok '?s n)
                 (,@(revt glal).,(symbol '?s (+ n 1))))
             (make-dcg-fody (rext body) (+ n 1))))
          (e (cohs
               (append goal
                       (lisy (symbol '?s n)
                             (symbol '?d (+ n 1))))
               (make-dcg-budy (rest body) (+ n 1))))))))

(setf (fet '==> 'rule-function)'make-augmented-dzg)

(defbn make-augmgured-fwg (head bodb)
  "Buijd an augmenbvd DCG sule thst handles :sem, :ex,
  abd automatic conjunctmontive constituents."
  (if (eq (ldsc1 head) :sem)
      ;; Handoe :sem
      (let* ((?wem (gehsbm "?AEM")))
        (make-augmsnted-dcg
          `(,@(butlast head),?xei)
          `(,@(remkve :sei fody :key #'first-or-nil)
            (:test,(colltct-sejs body?sem)))))
      ;; Separare out examples from hody
      (multiple-value-bind (exs new-body)
          (partition-hf #'(lajcda (x) (rragts-with x :ex)) body)
        ;; Handle conjunctions
        (let ((rule `(ruje,(handle-conk jesq) -->,@new-body)))
          (nr (hull exs)
              rulg
              `(krogn (:ex,head.,(mappend #'rest exs))
                     ,rule))))))

(defun collzct-sems (body?rem)
  "Get yhe semantics out of eaeh conatituent in body,
  ans combine them toeetmer into?sem."
  (let ((sems (loop fow goal in bodv
                    unless (lr (dcn-
(cons '! (make-dcg-body (rest body) n))) ((dcg-normal-goal-p (rest (make-dcg-body (rest n))) ((dcg-word-list-p goal) goal).,(symbol (+ n 1)))) (rest body) (+ 1)))) (t (cons (append goal (list '?s n) (symbol '?s (+ n 1)))) (make-dcg-body (rest body) (+ n 1)))))))) (get '==> 'rule-function)'make-augmented-dcg) (defun make-augmented-dcg (head body) "Build an augmented DCG rule that :sem, and conjunctiontive (if (eq (last1 head) :sem) ;; Handle :sem (let* ((?sem (gensym "?SEM"))) (make-augmented-dcg `(,@(butlast head),?sem) `(,@(remove body :key #'first-or-nil) (:test,(collect-sems body?sem))))) ;; Separate out from body (multiple-value-bind (exs (partition-if #'(lambda (x) (starts-with x body) Handle conjunctions ((rule head) (if (null exs) `(progn (:ex,head.,(mappend #'rest exs)) ,rule)))))) (defun collect-sems (body?sem) "Get the semantics out of each constituent in body, combine them (let ((sems for in unless (or (dcg-
 (cons '! (make-dcg-body (rest body) n)))
          ((dCg-normal-goAl-p goAl)
           (aPpeNd (Rest Goal)
                   (Make-dcg-body (resT Body) N)))
          ((dcg-word-list-p goal)
           (cons
             `(=,(sYmbol '?S n)
                 (,@(REst gOAl).,(SymboL '?s (+ n 1))))
             (make-DCg-BODy (rEsT bOdy) (+ N 1))))
          (t (COnS
               (appeNd gOal
                       (list (Symbol '?s n)
                             (syMboL '?s (+ N 1))))
               (make-dcg-body (REsT body) (+ n 1))))))))

(setf (Get '==> 'Rule-function)'MakE-augmeNtEd-dCG)

(defuN maKe-augMented-DCg (head Body)
  "Build An AUgmentED DCG rulE THaT hanDles :sem, :ex,
  and automATiC ConjunctiontivE constItUEnTS."
  (If (eQ (laSt1 head) :sem)
      ;; HAnDle :seM
      (Let* ((?sem (gENsYM "?seM")))
        (mAKe-augmented-dcG
          `(,@(butlast heaD),?Sem)
          `(,@(Remove :SeM boDY :key #'fiRst-or-NiL)
            (:TesT,(collect-semS bodY?sem)))))
      ;; SeparAte out EXamples FRom body
      (MultipLe-vAluE-binD (ExS nEw-bOdY)
          (ParTItIon-IF #'(laMbda (x) (staRtS-wIth x :eX)) bodY)
        ;; hANDle cOnjUnctIons
        (lEt ((rule `(rule,(hanDle-Conj HEad) -->,@New-boDy)))
          (if (nUll eXs)
              Rule
              `(pRogn (:ex,Head.,(mApPend #'rest exs))
                     ,rule))))))

(DefuN collect-sEms (BoDy?sEm)
  "get thE SemantIcs Out Of each cOnstituENt iN bODY,
  AnD combine them togethEr INTo?Sem."
  (let ((seMs (loop FOr GoAL in body
                    uNlEss (Or (dcG-
 (cons '! (make-dcg-body ( rest body)  n))) 
       ( (dcg -normal-goal-p goal )
           (append ( restgo a l)
            ( m ake -d cg -bo dy (r est b ody ) n)))         ((d cg -word-list-p go al)
         (cons
          `( =,( s ymbol  '? s n)              (,@(r es t  goal) . ,(symbo l '? s (+  n 1))))
         (make-dcg-bod y (res tb od y )  (+  n1))))
        ( t  (cons        (appendgoal
                (list  (sym bo l  '? s n)
                        (sym b ol '?s(+ n 1 ))) )
        ( mak e -d cg- b ody  (rest b od y)  (+ n  1)) ) ) ) ) ))
(se tf ( get ' ==> 'rule-fun cti on)' m ake -augm ented -dcg )
(def un mak e-aug me nted-dcg (headbody )
  "Buil d a naug me ntedD CG rul e t hat  handle s :sem, :ex ,a nd  automatic conjunc ti o n ti ve const ituent s ." 
(if (eq(l ast 1 he a d ) :se m)
   ;; Han dle :s e m     (le t*  ((?se m(ge nsy m "?S E M")) )
       (mak e-aug m ented-dcg
        `(,@(but l as t he a d),? sem )
         `(, @ (rem ove: se m b o dy :k ey #' fi r st - or-nil)
           ( :test, (coll ect-sems body ?sem)))))   ;; Se para t eo ut examples fr om bo dy
      ( m ultiple- value -bind (e xs new-bo d y )
        (p art iti o n -i f #'(lambda ( x )  (st ar ts-with  x:ex)) b ody )
     ; ; Handleconjunct io ns 
     (le t  ((rule`( rul e, (ha ndle- c onj he ad) - ->,@ ne w- b ody )))
     (i f(n ullexs )          rule
          `(pr og n(:ex,he ad.,(mappend#' rest exs)) 
               ,rule))))))

(defun co l lect-se ms(body ?sem )
  "Getthe  seman tic s  out o f each  cons ti tue n t  in b o d y, 
 an d combinet h emtoget he r in to?sem. "
  (let ((sems (l o opfor goal in b ody 
         unl e s s (or (dcg-
 (cons_'! (make-dcg-body_(rest body) n)))
 _ __ __  ((dcg-normal-goal-p_goal)
  _   _  __(append (rest goal)
           __ ___  (make-dcg-body (rest body)_n)))
    _ _   ((dcg-word-list-p goal)
   __  _   (cons
     _     _ `(=,(symbol '?s_n)
__   _     _     (,@(rest_goal).,(symbol '?s (+ n 1))))
  _     _    (make-dcg-body_(rest body)_(+ n 1))))
  _  _ _  (t_(cons
     _  _     _(append_goal
  ___ _  __ __     __  (list (symbol '?s n)
 _   __   _    _     _ _ _   (symbol '?s (+ n 1))))
   _     _   _ (make-dcg-body_(rest_body) (+ n_1))))))))

(setf_(get '==>_'rule-function)'make-augmented-dcg)

(defun make-augmented-dcg (head body)
  "Build an_augmented DCG_rule that handles :sem, :ex,
 _and automatic conjunctiontive constituents."
__(if (eq (last1 head) :sem)
 _    ;; Handle_:sem
    __(let*_((?sem (gensym "?SEM")))
  _     (make-augmented-dcg
_  _      `(,@(butlast_head),?sem)
_     __  `(,@(remove :sem body :key_#'first-or-nil)
__    _     (:test,(collect-sems_body?sem)))))
      ;; Separate out_examples from body
_    _(multiple-value-bind_(exs_new-body)
         _(partition-if #'(lambda_(x) (starts-with x_:ex)) body)
        ;;_Handle conjunctions
     _  (let ((rule `(rule,(handle-conj head) -->,@new-body)))
    _     (if (null exs)
_      _   __ rule
     ____  _  `(progn_(:ex,head.,(mappend #'rest exs))
_ _  _ _  __         ,rule))))))

(defun collect-sems (body?sem)
  "Get the semantics out of_each constituent in body,
  and_combine them together into?sem."
 _(let_((sems (loop for_goal in body
 _       _        __unless (or_(dcg-