Re: `position' in rep...?



I wrote a version of the position function that would work with circular
lists, since the other one will start an infinite loop if you give it a
circular list.  I've included the function below, but it turns out that
infinite lists are only semi-supported -- calling length, or even
evaluating them in sawfish-client, causes an infinite loop.  According
to the docs (where I should have looked first) only cons, car, cdr,
rplaca, rplacd, nth, and nthcdr can be used on circular lists.

In short: I don't know that it's worth it to fix it elsewhere, even if
we end up staying with rep, but if it's of any interest here's a version
of position that wont choke on infinite lists.

(define (position item l)
  (let ((start l))
    (let loop ((rest l)
               (i 0))
         (if (equal item (car rest))
             i
           (unless (or (null rest)
                       (and (/= 0 i)
                            (eq rest start)))
             (loop (cdr rest) (1+ i)))))))

-- 
Jeremy Hankins <nowan nowan org>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]