Path: utzoo!attcan!uunet!husc6!rice!leto!matthias
From: matthias@leto.rice.edu (Matthias Felleisen)
Newsgroups: comp.lang.scheme
Subject: Re: collect special form for streams
Message-ID: <748@thalia.rice.edu>
Date: 1 Jun 88 19:09:26 GMT
References: <294@gt-eedsp.UUCP> <50472@ti-csl.CSNET>
Sender: usenet@rice.edu
Reply-To: matthias@rice.edu (Matthias Felleisen)
Distribution: na
Organization: Rice University, Houston
Lines: 43

In article <50472@ti-csl.CSNET> gateley@mips.UUCP (John Gateley) writes:
>In article <294@gt-eedsp.UUCP> schw@gt-eedsp.UUCP (Dave Schwartz) writes:
>>How can the "collect" special form for streams (from Chap. 3 of
>>Structure and Interpretation of Computer Programs) be implemented for
>>TI PC-Scheme? I have Kent Dybvig's "extend-syntax," but this does not
>>appear to be powerful enough for this special form.
>
>Extend-syntax's pattern matching is not powerful enough to do this.
>You have to use the "with" feature to generate the v functions. (by calling
>a function which builds them, i.e. you do them by hand). I also used a
>help macro to make the flatmap parts of the expression (watch out for
>keywords). If this is not enough help, email me and I will send you my code.
>
>John Gateley
>gateley@tilde.csc.ti.com

John, what do you think of this one?  

(syntax
 (collect  (( ) ...) )
 (map (lambda (tuple)
	(help-res ( ...) ))
      (filter (lambda (tuple)
		(help-res ( ...) ))
	      (flat-help (( ) ...) (list  ...)))))

(extend-syntax (help-res)
  [(help-res (  ...) )
   (let (( (car tuple)) (tuple (cdr tuple)))
     (help-res ( ...) ))]
  [(help-res () ) ])

(extend-syntax (flat-help)
  [(flat-help (( ) ( ) ( ) ...) last)
   (flatmap (lambda ()
	      (flat-help (( ) ( ) ...) last))
	    )]
  [(flat-help (( )) last)
   (map (lambda () last) )])

-- Matthias 

P.S. Eugene Kohlbecker invented extend-syntax.