|
Subject: Re: Desperate Questions: [1]Absolute-Child-Number From: David Megginson <dmeggins@xxxxxxxxxx> Date: Tue, 24 Jun 1997 14:14:09 -0400 |
W. Eliot Kimber writes:
> I need the ordinal position of %element%'s parent within the children
> property of its parent.
If you have an implementation of ipreced already, this is quite easy
to do:
(define (absolute-child-number snl)
(if (absolute-first-sibling? snl)
1
(+ 1 (absolute-child-number (ipreced snl)))))
Love that tail recursion! Jade does not yet have ipreced, but I seem
to remember seeing an implementation posted to this list before. If
not, here's the sample definition from the DSSSL standard:
(define (ipreced nl)
(node-list-map (lambda (snl)
(let loop ((prev (empty-node-list))
(rest (siblings snl)))
(cond ((node-list-empty? rest)
(empty-node-list))
((node-list=? (node-list-first rest) snl)
prev)
(else
(loop (node-list-first rest)
(node-list-rest rest))))))
nl))
Now, however, you're missing an implementation of siblings. Here's a
semi-broken one -- the result of over two seconds' though and perhaps
twice as long spent typing -- that will work only with elements (and
not the root element, at that):
(define (siblings snl)
(children (parent snl)))
All the best,
David
--
David Megginson ak117@xxxxxxxxxxxxxxxxxxx
Microstar Software Ltd. dmeggins@xxxxxxxxxxxxx
University of Ottawa dmeggins@xxxxxxxxxx
http://www.uottawa.ca/~dmeggins
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: Desperate Questions: [1]Absolut, David Megginson | Thread | Re: Desperate Questions: [1]Absolut, Paul Prescod |
| Re: Desperate Questions: [1]Absolut, Paul Prescod | Date | Re: Desperate Questions: [1]Absolut, W. Eliot Kimber |
| Month |