On Sun, 21 Aug 2011 23:49:10 +0400 Arkady Rost <arkr...@gmail.com> wrote: > Hi! I'm looking for a more elegant solution of the following task. > > for i in rangeA { > for j in rangeB { > foo(param, i, j); > } > bar(); > } > > I need to translate this to factor. > > foo(param, y, x) <=> x y param foo > > I have a solution: > rangeA rangeB param [ foo ] curry [ swapd [ call ] 2curry each bar ] > 2curry each > > For example, > rangeA = { "a" "b" "c" } > rangeB = { "1" "2" "3" } > param = " " > foo = append append write ; > bar = "" print ; > > { "a" "b" "c" } { "1" "2" "3" } " " [ append append write ] curry > [ swapd [ call ] 2curry each "" print ] 2curry each > > Result is : > 1a 2a 3a > 1b 2b 3b > 1c 2c 3c > > I think my solution is bloated with partial applications. Maybe > someone can provide a better way to solve this task. > > Cheers, > Ark. Rost
Hi Arkady This should work: : blob ( ys xs param quot: ( y x param -- ) -- ) '[ _ [ _ _ call ] with each bar ] each ; inline example usage (assuming : bar ( -- ) "abc" print ;) ( scratchpad ) { 1 2 3 } { 4 5 6 } 7 [ 3array . ] blob { 1 4 7 } { 1 5 7 } { 1 6 7 } abc { 2 4 7 } { 2 5 7 } { 2 6 7 } abc { 3 4 7 } { 3 5 7 } { 3 6 7 } abc ------------------------------------------------------------------------------ Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk