Re: `position' in rep...?
- From: Jeremy Hankins <nowan nowan org>
- To: sawfish-list gnome org
- Subject: Re: `position' in rep...?
- Date: Sun, 29 May 2011 09:46:20 -0500
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))
i
(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]