Hi,
your implementation has 2 errors:
- you forgot to actually call the quotation
- you are calling a quotation that is an input parameter, therefore
you word must be declared inline

Here are various implementations using different language constructs:

:: zip-with ( xs ys quot -- zs )
   xs ys zip [ [ first ] [ second ] bi quot call ] map ; inline

: zip-with1 ( xs ys quot -- zs )
   [ zip ] [ '[ [ first ] [ second ] bi @ ] map ] bi* ; inline

: zip-with2 ( xs ys quot -- zs )
   [ zip ] [ [ [ first ] [ second ] bi ] prepose map ] bi* ; inline


The zip-with word is actually already implemented in the library, it
is called 2map. It's implementation doesn't use locals, if you also
want to look at it.

Cheers,
Jon

On Fri, Nov 11, 2011 at 10:06 AM, missingfaktor
<rahul.phulore....@gmail.com> wrote:
> ( scratchpad ) { { 1 2 } { 3 4 } { 8 9 } }
>                { { 8 9 } { 0 2 } { 1 5 } }
> --- Data stack:
> { ~array~ ~array~ ~array~ }
> { ~array~ ~array~ ~array~ }
> ( scratchpad ) zip [ [ first ] [ second ] bi append ] map
> --- Data stack:
> { ~array~ ~array~ ~array~ }
> ( scratchpad ) [ . ] each
> { 1 2 8 9 }
> { 3 4 0 2 }
> { 8 9 1 5 }
>
> The above code zips the two lists and then maps each pair to an element
> using  some function. This pattern occurs very often while coding, and I'd
> like to abstract it out in as a separate word.
> I tried writing it this way, but the code fails to compile:
>
> :: zip-with ( xs ys quot -- zs )
>    xs ys zip [ [ first ] [ second ] bi quot ] map ;
>
> Q1. How do I make it work?
> Q2. How to write this without locals?
> --
> Cheers,
> missingfaktor.
> When you stand for what you believe in, you can change the world.
>
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to