( 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 <http://twitter.com/#!/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

Reply via email to