From 5ecb754cc863eca4f52e2d8a19edb20c78a8b85f Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Tue, 1 Apr 2008 18:18:18 -0600 Subject: [PATCH] newfx: mutators --- extra/newfx/newfx.factor | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/extra/newfx/newfx.factor b/extra/newfx/newfx.factor index a5db87ca37..53cda66dfc 100644 --- a/extra/newfx/newfx.factor +++ b/extra/newfx/newfx.factor @@ -17,9 +17,16 @@ IN: newfx ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -: nth-is ( seq i val -- seq ) swap pick set-nth ; +: nth-is ( seq i val -- seq ) swap pick set-nth ; +: is-nth ( seq val i -- seq ) pick set-nth ; -: is-nth ( seq val i -- seq ) pick set-nth ; +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: mutate-nth ( seq i val -- ) swap rot set-nth ; +: mutate-at-nth ( seq val i -- ) rot set-nth ; + +: mutate-nth-of ( i val seq -- ) swapd set-nth ; +: mutate-at-nth-of ( val i seq -- ) set-nth ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -33,6 +40,14 @@ IN: newfx ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +: mutate-key ( tbl key val -- ) swap rot set-at ; +: mutate-at-key ( tbl val key -- ) rot set-at ; + +: mutate-key-of ( key val tbl -- ) swapd set-at ; +: mutate-at-key-of ( val key tbl -- ) set-at ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + : push ( seq obj -- seq ) over sequences:push ; : push-on ( obj seq -- seq ) tuck sequences:push ; @@ -48,3 +63,6 @@ IN: newfx ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +! A note about the 'mutate' qualifier. Other words also technically mutate +! their primary object. However, the 'mutate' qualifier is supposed to +! indicate that this is the main objective of the word, as a side effect. \ No newline at end of file