That's a cool concept, Ed. One thing you might want to do to make it
more flexible is dispatch on the difference between the in and out
effects, rather than their exact values, so something like reduce
would work.

Why don't you get a blog to write all of these ideas in, so they can
reach a wider audience than the mailing list? It seems many things you
post are to share your ideas, not necessarily as part of a big
discussion, and a blog is the perfect medium for that.

On 7/17/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote:
> Hello,
>
> For these combinators: map each map-with each-with
>
> it's possible to write a single "smart" combinator which figures out which one
> of those to call. Each of those combinators takes a quotation. The effect of
> the quotation is different for each of those combinators. So all the "super
> combinator" has to do is infer the effect and call the appropriate one. The
> implementation is below. I called it 'for'. Examples:
>
>         { 1 2 3 4 } [ 1+ ] for          ! map
>
>         10 { 1 2 3 4 } [ + ] for        ! map-with
>
>         { 1 2 3 4 } [ drop ] for        ! each
>
>         10 { 1 2 3 4 } [ 2drop ] for    ! each-with
>
> The quotation has to be inferable in order for 'for' to work.
>
> Ed
>
> USING: kernel effects inference combinators sequences inference.transforms ;
>
> IN: for
>
> : do-map? ( quot -- quot ? ) dup infer nip T{ effect f 1 1 f } equal? ;
>
> : do-each? ( quot -- quot ? ) dup infer nip T{ effect f 1 0 f } equal? ;
>
> : do-map-with? ( quot -- quot ? ) dup infer nip T{ effect f 2 1 f } equal? ;
>
> : do-each-with? ( quot -- quot ? ) dup infer nip T{ effect f 2 0 f } equal? ;
>
> : [for] ( seq quot -- quot )
> { { [ do-map? ] [ [ map ] ] }
>   { [ do-each? ] [ [ each ] ] }
>   { [ do-map-with? ] [ [ map-with ] ] }
>   { [ do-each-with? ] [ [ each-with ] ] } }
> cond ;
>
> : for ( seq quot -- ) [for] call ;
>
> \ for 1 [ [for] ] define-transform
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to