Hi Mike,
> Works as circular list and after reset can count again from the beginning.
> Used in Threefish implementation.
> ...
> https://bitbucket.org/mihailp/tankfeeder/src/d38de78a9609d31a917ca73f8b8d9fe302afc5b8/circR.l?fileviewer=file-view-default
>
> Code comments are welcome.
I think you could make it a lot simpler. Instead of keeping a count and
the length, you can keep the whole list:
(de circR ("Var" Lst)
(set "Var" (cons (apply circ Lst) Lst)) )
This works because neither (apply circ Lst) nor the later 'pop's are
destructive.
Then 'resetR' is also much simpler:
(de resetR ("Var")
(set "Var" (cdr (val "Var"))) )
and 'popR' (and in fact also 'resetR') is not needed at all:
: (circR 'L (range 1 5))
-> ((1 2 3 4 5 .) 1 2 3 4 5)
: L
-> ((1 2 3 4 5 .) 1 2 3 4 5)
: (pop L)
-> 1
: (pop L)
-> 2
: L
-> ((3 4 5 1 2 .) 1 2 3 4 5)
: (set L (cdr L)) # This can be used instead of 'resetR'
-> (1 2 3 4 5)
: L
-> ((1 2 3 4 5) 1 2 3 4 5)
: (pop L)
-> 1
♪♫ Alex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe