Re: How to Collect Sosofos?

Subject: Re: How to Collect Sosofos?
From: Chris Maden <crism@xxxxxxx>
Date: Tue, 9 Sep 1997 11:19:27 -0400
[Eliot asks about iterating over a node-list]

With tail-recursion (I think that's what this is - I didn't major in
CS) you need to give a final alternative to recursing again, causing
the whole thing to unwind.  In DSSSL, the thing you want to return is
the empty-sosofo.

>From my MIF generator (which is going quite well, and I'll post the
main functions when I'm done):

(define (process-text) (let p-t-loop
	((this-node (node-list-first (children (current-node))))
	 (other-nodes (node-list-rest (children (current-node)))))
	(sosofo-append (case (node-property 'class-name
			     ;; handle special characters
			     ((data-char) (case (node-property 'char
			     ;; handle processing instructions
			     ((pi) (case (node-property 'system-data
			     ;; handle sdata entities
			     ((sdata) (case (node-property 'system-data
		       (if (node-list-empty? other-nodes)
			   (p-t-loop (node-list-first other-nodes)
			             (node-list-rest other-nodes)))))))

For each node, the loop returns something for the node, with another
iteration appended.  The final node returns something for itself, with
the empty-sosofo appended; that gets appended to the next-to-last
node, etc.  The first node ends up returning its own sosofo followed
by those of all the other nodes, and then the empty-sosofo.

<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL> <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>

 DSSSList info and archive:

Current Thread