[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: collect special form for streams
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.