• .Re: SETF and variable issues in Self Similar program.

    From Robert L.@21:1/5 to Ken Tilton on Wed Mar 16 23:40:00 2022
    Ken Tilton wrote:

    Say I want to create a function that fills a list of length n with a sequence that counts from 1 to n, at a given interval r and returns
    the list. And this process being generalized for any given length or interval. Of course the length and interval have to be relatively
    prime.

    For example: If the interval is 3 and the length is 17, the list
    returned would be...
    (1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 6 12)
    You can see that, since the interval is 3, if you read every 3 in the
    final list you will see 1 2 3 4...etc.

    I have done this several different ways, but ran into some
    limitations, and am now back to work on a better way. Any
    suggestions? I have a feeling it is much simpler than I am making it.

    Maybe?:

    (let ((n 17)(i 3))
    (loop with a = (make-array n)
    for x below n
    do (setf (svref a (mod (* i x) n)) (1+ x))
    finally (return (coerce a 'list))))
    Gauche Scheme:

    (define (foo top interval)
    (define len (ceiling (/ top interval)))
    (take
    (apply append-map list
    (map (lambda (i) (iota len (+ 1 (* i len)))) (iota interval)))
    top))

    (foo 17 3)
    ===>
    (1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 6 12)

    (foo 18 3)
    ===>
    (1 7 13 2 8 14 3 9 15 4 10 16 5 11 17 6 12 18)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)