

                                                                  gathering

    MACRO
GATHERING ({(VAR FN)}*) {FORM}*                                     [Macro]

    Package
    series

    DESCRIPTION

The first subform must be a list of pairs.  The first element of each pair,
VAR, must be a variable name.  The second element of each pair, FN, must be
a form that when wrapped in (FUNCTION ...) is acceptable as an argument to
GATHERER.  Each symbol is bound to a gatherer constructed from the
corresponding collector.  The body (consisting of the FORMS) is evaluated
in the scope of these bindings.  When this evaluation is complete,
GATHERING returns the RESULT-OF each gatherer.  If there are N pairs in the
binding list, GATHERING returns N values.  For example:

(DEFUN EXAMP (DATA) 
  (GATHERING ((X COLLECT) (Y COLLECT-SUM)) 
    (ITERATE ((I (SCAN DATA))) 
      (CASE (FIRST I) 
        (:SLOT (NEXT-OUT X (SECOND I))) 
        (:PART (DOLIST (J (SECOND I)) (NEXT-OUT X J)))) 
      (NEXT-OUT Y (THIRD I))))) 

(EXAMP '((:SLOT A 10) (:PART (C D) 40))) => (A C D) and 50

As a further illustration of gatherers, consider the following definition
for a simplified version of GATHERING that handles only one binding pair.

(DEFMACRO SIMPLE-GATHERING (((VAR COLLECTOR)) &BODY BODY) 
  `(LET ((,VAR (GATHERER (FUNCTION ,COLLECTOR)))) 
     ,@BODY 
     (RESULT-OF ,VAR)))

The full capabilities of GATHERING can be supported in much the same way.

     SEE ALSO
     about-series
     about-generators

;Copyright 1989 by the Massachusetts Institute of Technology,
;Cambridge, Massachusetts.

;Permission to use, copy, modify, and distribute this software and its
;documentation for any purpose and without fee is hereby granted,
;provided that this copyright and permission notice appear in all
;copies and supporting documentation, and that the name of M.I.T. not
;be used in advertising or publicity pertaining to distribution of the
;software without specific, written prior permission. M.I.T. makes no
;representations about the suitability of this software for any
;purpose.  It is provided "as is" without express or implied warranty.

;    M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
;    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
;    M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
;    ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
;    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
;    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
;    SOFTWARE.



