What about using local only to implement the difficult stack shuffling that you named "????" ? :: ???? ( a b c d e h -- d b c a e h ) d b c a e h ; : swap-element ( i1 array1 i2 array2 -- ) [ [ nth ] 2keep ] 2bi@ ???? [ set-nth ] 2 smart-apply ;
And you could name "????" "(swap-element)" which is the convention for helper words that don't have much sens by themselve. Or "swap-data". Or leave it as "????" because really it's self explaining. Oh and your question reminded me of http://useless-factor.blogspot.com/2007/07/thats-dirtiest-macro-ive-ever-seen.html which was a fun read :) Alternatively, why do you find yourself in need to swap elements between 2 different arrays ? Maybe you could organize the data in a different way ? Jon On Mon, Mar 12, 2012 at 2:00 PM, nicolas.o...@gmail.com <nicolas.o...@gmail.com> wrote: > Dear all, > > I am starting to learn Factor as my first concatenative language (from > a FP background) and enjoy it very much. > > However, when trying to write simple words I get stuck on how to best > express dataflow. > > As a (very very simple) example, I am trying to write a word > > : swap-element ( i1 array1 i2 array2 -- ) > > that swaps two elements with indices i1 and i2 from 2 (aliased or not) arrays. > > It is very easy to write such a word using lexical variables. > > However, I have two problems with that: > - I am not sure it is the right tool to use or just my brain bringing > me back to what I know. > - It does not show the symmetries of the dataflow of this word > > I quite like the style of something along the lines of: > > : swap-element ( i1 array1 i2 array2 -- ) > [ [ nth ] 2keep ] 2bi@ ???? [ set-nth ] 2 smart-apply ; > > because it shows the dataflow better than with lexical variables. > > But I can't find something nice to put instead of ????. > > So, I guess that my question is: how to solve this problem and, more > importantly, how to learn to > solve this kind of problem by myself? > > Thank you very much for your help, > > Best regards, > > Nicolas. > > ------------------------------------------------------------------------------ > Try before you buy = See our experts in action! > The most comprehensive online learning library for Microsoft developers > is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, > Metro Style Apps, more. Free future releases when you subscribe now! > http://p.sf.net/sfu/learndevnow-dev2 > _______________________________________________ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk ------------------------------------------------------------------------------ Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2 _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk