Subject: RE: Filtering nodes From: "Maltby, David G" <david.g.maltby@xxxxxxxx> Date: Fri, 10 Nov 2000 11:10:41 -0500 |
I suppose it justifies my use of the bandwidth that the solution was not obvious to me on first (or second) read. To make sure I got it now, Brandon's (first-ns) returns a two member list, the first member a boolean and the second member a node-list consisting of the Ns or empty. To get the node-list I can take the (cadr (first-ns)). Or I can put the (cadr) in (first-ns) by taking the (cadr (n-l-r ...)). I am still working combining (first-ns) with (last-ns) but I'll get it. Thanks Brandon. David > -----Original Message----- > From: Brandon Ibach [mailto:bibach@xxxxxxxxxxxxxx] > Sent: Thursday, November 09, 2000 5:08 PM > To: dssslist@xxxxxxxxxxxxxxxx > Subject: Re: Filtering nodes > > Well, I'd go with an approach using (node-list-reduce), which is a > more general tool than (node-list-filter). In fact, you may have > noticed that the standard defines (n-l-f) in terms of (n-l-r). > The benefit of (n-l-r) in this case is that it allows us to carry > an arbitrary object through the processing of the node list. The goal > of (first-ns) could be stated as "return all of the N nodes until we > see an S node": > > (define (first-ns nl) > (node-list-reduce nl (lambda (o n) > (let ((s (or (car o) (string=? (gi n) "S")))) > (list s (if (and (not s) (string=? > (gi n) "N")) > (node-list (cadr o) n) > (cadr o))))) > (list #f (empty-node-list)))) > > Here, we carry a list object containing a boolean and a node list. > The node list is, of course, the result which we are building. The > boolean tracks whether we have seen an S node yet. The definition is > similar for (last-ns), whose goal is "return all of the N nodes after > we see an S node": > > (define (last-ns nl) > (node-list-reduce nl (lambda (o n) > (let ((s (or (car o) (string=? (gi n) "S")))) > (list s (if (and s (string=? (gi n) "N")) > (node-list (cadr o) n) > (cadr o))))) > (list #f (empty-node-list)))) > > In fact, the definitions are identical except for the (not) in > (first-ns), right before the check to see if the current node is an N. > It wouldn't take much to create a single definition, called by both of > these functions, which takes an extra boolean argument to specify > which set of N nodes you want. Here's a hint: > > (define (xor a b) (if (and a b) #f (or a b))) > > -Brandon :) > > > DSSSList info and archive: > http://www.mulberrytech.com/dsssl/dssslist > DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Filtering nodes, ptyso | Thread | Re: Filtering nodes, Brandon Ibach |
Re: Filtering nodes, ptyso | Date | Re: Filtering nodes, Brandon Ibach |
Month |