From 3fc06f02ece3ec4724d4730a22a78ab1d6309c04 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 13 Apr 2008 00:52:49 -0500 Subject: [PATCH] Clean up circular --- extra/circular/circular.factor | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/extra/circular/circular.factor b/extra/circular/circular.factor index 08deb004e8..b6e350a9e5 100755 --- a/extra/circular/circular.factor +++ b/extra/circular/circular.factor @@ -1,6 +1,7 @@ ! Copyright (C) 2005, 2006 Alex Chapman, Daniel Ehrenberg ! See http;//factorcode.org/license.txt for BSD license -USING: kernel sequences math sequences.private strings ; +USING: kernel sequences math sequences.private strings +accessors ; IN: circular ! a circular sequence wraps another sequence, but begins at an @@ -11,27 +12,27 @@ TUPLE: circular seq start ; 0 circular construct-boa ; : circular-wrap ( n circular -- n circular ) - [ circular-start + ] keep - [ circular-seq length rem ] keep ; inline + [ start>> + ] keep + [ seq>> length rem ] keep ; inline -M: circular length circular-seq length ; +M: circular length seq>> length ; -M: circular virtual@ circular-wrap circular-seq ; +M: circular virtual@ circular-wrap seq>> ; M: circular nth virtual@ nth ; M: circular set-nth virtual@ set-nth ; +M: circular virtual-seq seq>> ; + : change-circular-start ( n circular -- ) #! change start to (start + n) mod length - circular-wrap set-circular-start ; + circular-wrap (>>start) ; : push-circular ( elt circular -- ) - [ set-first ] keep 1 swap change-circular-start ; + [ set-first ] [ 1 swap change-circular-start ] bi ; : ( n -- circular ) 0 ; -M: circular virtual-seq circular-seq ; - INSTANCE: circular virtual-sequence