component-list-child-number

Name

component-list-child-number — Find child-number of a list of children within a component

Synopsis

(component-list-child-number inputnd inputlist complist)

Description

Finds the first ancestor of inputnd in complist and then counts all the elements of the types in inputlist from that point on and returns the number of inputnd.

If the node is not found, 0 is returned.

WARNING: this requires walking over *all* the descendants of the ancestor node. This may be *slow*.

Author

Norman Walsh, <ndw@nwalsh.com>

Source Code

(define (component-list-child-number inputnd inputlist complist)
  ;; Find child-number of a list of children within a component
  (let ((nd (ancestor-member inputnd complist)))
    (let loop ((nl (descendants nd)) (num 1))
      (if (node-list-empty? nl)
	  0
	  (if (node-list=? (node-list-first nl) inputnd)
	      num
	      (if (member (gi (node-list-first nl)) inputlist)
		  (loop (node-list-rest nl) (+ num 1))
		  (loop (node-list-rest nl) num)))))))