[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do lisp gurus truncate?
From: |
Lennart Borgman |
Subject: |
Re: How do lisp gurus truncate? |
Date: |
Thu, 23 Jul 2009 20:11:01 +0200 |
On Thu, Jul 23, 2009 at 7:05 PM, Giorgos
Keramidas<keramida@ceid.upatras.gr> wrote:
> On Thu, 23 Jul 2009 08:32:56 +0200, Lennart Borgman
> <lennart.borgman@gmail.com> wrote:
>> I want to truncate an ordered list if the rest of the values are
>> bigger than some limit. I just wrote some code like this one to do
>> that, but there must be some more standard way of doing that, or?
>>
>> (when nxml-where-first-change-pos
>> (setq nxml-where-path 'dummy nxml-where-path)
>> (let ((path nxml-where-path))
>> (while (cdr path)
>> (when (> (nth 1 (nth 1 path)) nxml-where-first-change-pos)
>> (setcdr path nil))
>> (setq path (cdr path))))
>> (setq nxml-where-path (cdr nxml-where-path)))
>
> I'd probably use `every' to perform the test and start iterating over
> the list at the first location returned by `member' or `find', i.e. from
> a CLISP session:
>
> [9]> (every (lambda (number)
> (> number 3))
> (list 4 5 6))
> T
>
> [10]> (member 3 (list 1 2 3 4 5 6 7))
> (3 4 5 6 7)
>
> [11]> (every (lambda (number)
> (> number 3))
> (rest (member 3 (list 1 2 3 4 5 6 7 8 9))))
> T
>
> Locating the first item that is probably easier to do with `find' than
> with `member', because it lets you find the first number *larger* than
> the value you are looking for, i.e.:
Thanks, but I do not know the elements in the list, just that it is
sorted so using find or member does not work as far as I can see.
(Otherwise would of course "member" do the job.)