newLISP Fan Club

Forum => newLISP in the real world => Topic started by: cameyo on December 19, 2023, 05:23:26 AM

Title: rotate bug?
Post by: cameyo on December 19, 2023, 05:23:26 AM
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")

Title: Re: rotate bug?
Post by: vashushpanov on January 09, 2024, 01:50:57 AM
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
Title: Re: rotate bug?
Post by: cameyo on January 09, 2024, 09:47:22 AM
Thanks!!