std-nxtcyc | ![]() |
STD-NXTCYC
returns the next element in an integer ringbuffer of length n.
The name means "next cyclic element". This function is to be used if you cycle through elements and want to start at the beginning again, because it needs no explicit if condition.
The incr-func gives the sort order of the ringbuffer. It can be function accepting and returning numbers or strings. normally just 1+
or 1-
, but thinkable are also ABS
, (LAMBDA (s) (CHR (1+ (ASCII s))))
or such.
(std-nxtcyc 0 3 '1+) => 1 (std-nxtcyc 1 3 '1+) => 2 (std-nxtcyc 2 3 '1+) => 0 (std-nxtcyc 3 3 '1+) => 1
Usage:
We use std-nxtcyc to retrieve the actual and the next element from the polygon. The point after the last point is the first.
(defun STD-POLYEDGE (i poly len) (list (nth (std-nxtcyc i len 'abs) poly) ;p1 (nth (std-nxtcyc i len '1+) poly))) ;p0 ;; dummy 'abs function to avoid errors with i=-1 or len+1 ;; only if you're absolutely sure that 0 <= i < len then ;; use (nth i poly) without std-nxtcyc
i: 0 or a positive integer. The position of the next element, normally i MOD n
n: a positive integer. The length of the ringbuffer (0 1 ... n-1)
incr-func: increment function, normally just 1+ or 1-. 1+ for a list of increasing numbers, 1- for a list of decreasing numbers. It can be any function which takes one argument and is suitable for < and >=, i.e. numbers or strings.
An integer number between 0 and n-1.
None.
(std-require 'STDLIST)
Defined in STDLIST