Jump to content

Featured Replies

Posted

same with gen-integer-step

 

(defun gen-integer-step* (n intervals &key (offset 0) (every-x 1) (reverse nil))
  (let ((n (* n every-x)) (seq)) 
      (setf seq (find-everyother every-x (subseq (gen-integer-step 0 (+ n offset) intervals) offset (+ n offset))))
      (if (equal reverse nil)
        seq
        (reverse seq))))


(gen-integer-step* 20 '(1 -2 3 1))
=> (0 1 -1 2 3 4 2 5 6 7 5 8 9 10 8 11 12 13 11 14)

(gen-integer-step* 20 '(1 -2 3 1) :every-x 2)
=> (0 -1 3 2 6 5 9 8 12 11 15 14 18 17 21 20 24 23 27 26)

(gen-integer-step* 20 '(1 -2 3 1) :offset 6 :every-x 4 :reverse t)
 => (59 56 53 50 47 44 41 38 35 32 29 26 23 20 17 14 11 8 5 2)


;;;; in combination with "reading-list-by-steps"

(defun reading-list-by-steps (&key steps values (start (car values)))
  (let ((pos (car (position-item start values))))
    (append (list (nth pos values))
            (loop for i in steps
              do (setf pos (+ pos i))
              when (> pos (length values))
              do (setf pos (+ 0 i))
              collect (nth pos values)))))

(list-plot
 (reading-list-by-steps :steps (gen-repeat 5 '(1 2 -1 3 4 -1))
                        :values (gen-integer-step* 100 '(1 2 3 1) :offset 4 :reverse t))
 :join-points t)

 

Create an account or sign in to comment


Copyright © 2014-2025 Opusmodus™ Ltd. All rights reserved.
Product features, specifications, system requirements and availability are subject to change without notice.
Opusmodus, the Opusmodus logo, and other Opusmodus trademarks are either registered trademarks or trademarks of Opusmodus Ltd.
All other trademarks contained herein are the property of their respective owners.

Powered by Invision Community

Important Information

Terms of Use Privacy Policy