rotate bug?

Started by cameyo, December 19, 2023, 05:23:26 AM

Previous topic - Next topic

cameyo

Maybe a bug of "rotate" when negative rotations and absolute rotations multiple of length of list.

(rotate '("1" "A" "B" "2") 8)
;-> ("1" "A" "B" "2")
(rotate '("1" "A" "B" "2") -8)
;-> ("1") ;ERROR
(rotate '("1" "A" "B" "2") 12)
;-> ("1" "A" "B" "2")
(rotate '("1" "A" "B" "2") -12)
;-> ("1") ;ERROR

Workaround:
(rotate lst (- (% r (length lst))))
(rotate '("1" "A" "B" "2") (- (% 12 4)))
;-> ("1" "A" "B" "2")
(rotate '("1" "A" "B" "2") (- (% 8 4)))
;-> ("1" "A" "B" "2")


vashushpanov

in file nl-liststr.c replace string
if (length <= 1 || count == 0 || length == labs(count))
to
if (length <= 1 || count == 0 || length == labs(count) || count % length == 0)

and recompile NewLisp

cameyo