Re: [Factor-talk] Beginner question about style and stack shuffling

2012-03-12 Thread nicolas.o...@gmail.com
Thank you very much for both answers. They both are very instructive. This one is really amazing though: > > ``` > TUPLE: array-ref index array ; > C: array-ref > : >array-ref< ( array-ref -- index array ) >    [ index>> ] [ array>> ] bi ; > : get-ref ( array-ref -- elt ) >    >array-ref< nth ;

Re: [Factor-talk] Beginner question about style and stack shuffling

2012-03-12 Thread Joe Groff
On Mon, Mar 12, 2012 at 6:00 AM, nicolas.o...@gmail.com wrote: > 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.

Re: [Factor-talk] Beginner question about style and stack shuffling

2012-03-12 Thread Jon Harper
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)"

[Factor-talk] Beginner question about style and stack shuffling

2012-03-12 Thread nicolas.o...@gmail.com
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 arra