[comp.lang.scheme] collect special form for streams

schw@gt-eedsp.UUCP (Dave Schwartz) (05/31/88)

Any help you can provide would be appreciated ...

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.

   __                     ()
  /  )              /     /\       /                 _/_
 /  / __. , __o  __/     /  )  _. /_  , , , __.  __  /  __.
/__/_(_/|_\/ <__(_/_    /__/__(__/ /_(_(_/_(_/|_/ (_<__/  |_
                                                         (|
-------------------------------------------------------------
uucp:                         schw@gt-eedsp.uucp
domainizing internet mailers: schw@gteedsp.gatech.edu
dumb internet mailers:        schw%gteedsp@gatech.gatech.edu

gateley@mips.csc.ti.com (John Gateley) (05/31/88)

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

matthias@leto.rice.edu (Matthias Felleisen) (06/02/88)

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 <result> ((<v1> <set1>) ...) <restriction>)
 (map (lambda (tuple)
	(help-res (<v1> ...) <result>))
      (filter (lambda (tuple)
		(help-res (<v1> ...) <restirction>))
	      (flat-help ((<v1> <set1>) ...) (list <v1> ...)))))

(extend-syntax (help-res)
  [(help-res (<v1> <v2> ...) <res>)
   (let ((<v1> (car tuple)) (tuple (cdr tuple)))
     (help-res (<v2> ...) <res>))]
  [(help-res () <res>) <res>])

(extend-syntax (flat-help)
  [(flat-help ((<v1> <set1>) (<v2> <set2>) (<v3> <set3>) ...) last)
   (flatmap (lambda (<v1>)
	      (flat-help ((<v2> <set2>) (<v3> <set3>) ...) last))
	    <set1>)]
  [(flat-help ((<v1> <set1>)) last)
   (map (lambda (<v1>) last) <set1>)])

-- Matthias 

P.S. Eugene Kohlbecker invented extend-syntax.

gateley@mips.csc.ti.com (John Gateley) (06/04/88)

In article <748@thalia.rice.edu> matthias@rice.edu (Matthias Felleisen) writes:
>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
>>>[...]
>>Extend-syntax's pattern matching is not powerful enough to do this.
>>[...]
>John, what do you think of this one?  
>[Matthias's code deleted]
>
>P.S. Eugene Kohlbecker invented extend-syntax.

Hi Matthias,

As usual you are right and I am wrong. Let me rephrase it a bit:
Extend-syntax is not powerful enough to do it without using help
macros. I can generate the (car (cdr (... tuple))) pattern without
using 'with' or your rebinding of tuple, but I dont think that it
can be done as part of the collect macro without actually changing
the definition of collect. I dont want to rebind tuple because it
changes the pattern matching part of the problem. If you change the
definition, then I think you can do it. Can you prove me wrong this
time?

John