Re: searching for closest previous element

Subject: Re: searching for closest previous element
From: stephenng@xxxxxxxxxxxx
Date: Wed, 18 Mar 1998 13:25:36 +0000
Norm writes:
>>(define (node-list-last nl)
>>(node-list-ref nl
>>(- (node-list-length nl) 1)))

I saw node-list-ref in the spec, but it claims that it "could be 
defined" as and gives a definition that basically walks down the 
list.  I guess "could be defined" isn't the same as "is defined"; 
maybe node-list-ref is actually fast.  I'll try re-writing my code 
and see if it works better.

>From the spec:

(node-list-ref nl k)

Returns a node-list containing the kth member of nl (zero-based), if
there is such a member, and otherwise returns the empty node-list.
This could be defined as follows:
(define (node-list-ref nl i) 
(cond
    ((< i 0) 
       (empty-node-list))
     ((zero? i)
       (node-list-first nl)) 
     (else
         (node-list-ref (node-list-rest nl) (- i 1)))))


--Steve


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread
  • searching for closest previous element
    • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id MAA29235Wed, 18 Mar 1998 12:00:36 -0500 (EST)
      • Norman Walsh - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id MAA00392Wed, 18 Mar 1998 12:40:40 -0500 (EST)
      • Paul Prescod - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id KAA20931Thu, 19 Mar 1998 10:32:32 -0500 (EST)
      • <Possible follow-ups>
      • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id NAA01051Wed, 18 Mar 1998 13:28:07 -0500 (EST) <=
        • stephenng - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id OAA17663Thu, 26 Mar 1998 14:25:03 -0500 (EST)
      • Reynolds, Gregg - from mail1.ability.netby web4.ability.net (8.8.5/8.6.12) with ESMTP id SAA04606Wed, 18 Mar 1998 18:19:21 -0500 (EST)