Paste: Merge
Author: | pheuter |
Mode: | factor |
Date: | Wed, 1 Dec 2010 22:42:26 |
Plain Text |
: merge ( x y z -- z )
[| a b | a length 0 > b length 0 > and ]
[| a b c | a b c 0 a nth 0 b nth over over <
[| a b c x y | 0 a remove-nth b x c push ]
[| a b c x y | a 0 b remove-nth y c push ]
if
] while
[| x y z | x y z y 0 = [| x y z | x z append ] [| x y z | y z append ] if ] call
;
--- Data Stack:
V{ 1 3 5 7 9 }
V{ 2 4 6 }
V{ }
(scratchpad) : merge
--- Data Stack:
V{ 1 2 3 4 5 6 7 9 }
Author: | pheuter |
Mode: | factor |
Date: | Wed, 1 Dec 2010 22:45:37 |
Plain Text |
: merge ( x y z -- z )
[| a b c | a b c a length 0 > b length 0 > and ]
[| a b c | a b c 0 a nth 0 b nth over over <
[| a b c x y | 0 a remove-nth b x c push ]
[| a b c x y | a 0 b remove-nth y c push ]
if
] while
[| x y z | x y z y 0 = [| x y z | x z append ] [| x y z | y z append ] if ] call
;
New Annotation