• Re: every-other revisited (with series)

    From B. Pym@21:1/5 to Fred Gilham on Wed Sep 18 21:15:55 2024
    XPost: comp.lang.scheme

    Fred Gilham wrote:

    For those who are interested, here are two versions of the
    `every-other' function we were discussing a couple months ago, done
    for amusement value with the SERIES package that was mentioned
    recently:


    (defun every-other (list &key (start 0))
    (collect
    (choose (series t nil)
    (scan (nthcdr start list)))))


    This one uses SERIES to create a series of (t nil t nil ...); CHOOSE
    uses this series to determine whether or not to take the current item
    from the series created from the original list by SCAN. This was the

    Gauche Scheme

    (use srfi-1) ; circular-list

    (define (every-other lst)
    (filter-map
    (cut and <> <>)
    (circular-list #t #f)
    lst))

    (every-other (iota 22))
    ===>
    (0 2 4 6 8 10 12 14 16 18 20)

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