Re: Counting Nodes

Subject: Re: Counting Nodes
From: Matthias Clasen <clasen@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 25 Feb 2000 17:14:25 +0100
> I tested Matthias' elegant procedure:
> (define (text-node-cnt #!optional (cur-text-node (current-node)))
>   (node-list-length
>      (node-list-filter
>        (lambda (snl) (not (attribute-string "type" snl)))
>        (preced cur-text-node))))
> and it works as well as my first attempt (well, it's one off but that is
> minor), however it is too elegant for me and I could not successfully modify
> the filter to get rid of the (not (gi snl)) as well as the (not
> (attribute-string "type" snl)).  It will be a good exercise for me when
> deadlines are not so pressing.  I need to understand mapping a procedure
> over a list better.

Well, I overlooked the issue with unwanted non-element nodes, this version
should filter them away (untested):

(define (text-node-cnt #!optional (cur-text-node (current-node)))
       (lambda (snl) (and 
                       (equal? (gi snl) "TEXT") 
                       (not (attribute-string "type" snl))))
       (preced cur-text-node))))

Matthias Clasen, 
Tel. 0761/203-5606
Email: clasen@xxxxxxxxxxxxxxxxxxxxxxxxxx
Mathematisches Institut, Albert-Ludwigs-Universitaet Freiburg

 DSSSList info and archive:

Current Thread