====== pick ====== In ANS ist ''0 PICK'' aquivalent zu ''DUP'' (gforth). ''PICK'' wird gewöhnlich low level codiert. Das Beispiel in high level forth zeigt das Verhalten des Stack. \ pick nth item from stack. top of stack is x0 befor n was placed there. : pick ( n -- xn ) 1+ cells sp@ + @ ; In gforth wächst der Stack nach unten in Richtung absteigender Adressen um je eine cell pro item. Die älteren items haben daher die höhere Adresse. screenshot: 66 55 44 33 22 11 00 ok drop sp@ . .s 21028840 <6> 66 55 44 33 22 11 ok drop sp@ . .s 21028844 <5> 66 55 44 33 22 ok drop sp@ . .s 21028848 <4> 66 55 44 33 ok drop sp@ . .s 21028852 <3> 66 55 44 ok drop sp@ . .s 21028856 <2> 66 55 ok drop sp@ . .s 21028860 <1> 66 ok drop sp@ . .s 21028864 <0> ok drop sp@ . .s *the terminal*:63: Stack underflow drop sp@ . .s ^^^^ Backtrace: In Forth79 war ''1 PICK'' aquivalent zu ''DUP'' (MVP-Forth). Es waren 8-bit Maschinen, das Forthwort war 16 Bit breit, daher genügte immer ''2*'' statt ''cells''. \ pick nth item from stack. top of stack is x1 befor n was placed there. : pick ( n -- xn ) dup 1 < abort" PICK ARGUMENT < 1" 2* sp@ + @ ; ---- Zum ausprobieren: : dup ( x0-- x0 x0 ) 0 pick ; : 2dup ( x1 x0 -- x1 x0 x1 x0 ) 1 pick 1 pick ; : 3dup ( x2 x1 x0 -- x2 x1 x0 x2 x1 x0 ) 2 pick 2 pick 2 pick ; \ usw.