Re: `position' in rep...?

Jeremy Hankins <nowan nowan org> writes:
> Christopher Roy Bratusek <nano tuxfamily org> writes:
>> You would need it for every GtkComboBox in SawfishConfig, to set the
>> initial value, to what the user previously selected (or to what the
>> default value is).
> Ah, ok.  Then yeah, I think you are supposed to loop through. ;)  I'm
> not sure that rep really needs a position function -- in most cases it's
> just going to encourage non-lispy lisp programming, I think.  In those
> situations where you need one just include something like this:
> (define (position item l)
>   (let loop ((rest l)
>              (i 0))
>        (if (equal item (car rest))
>            i
>          (loop (cdr rest) (1+ i)))))
> Perhaps equal should be eq, depending on how you're using it...?

Uh, make that:

(define (position item l)
  (let loop ((rest l)
             (i 0))
       (if (equal item (car rest))
         (if rest
             (loop (cdr rest) (1+ i))))))

So as to avoid those nasty infinite loops.... :P

Jeremy Hankins <nowan nowan org>

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