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
					    this-node)
			     ;; handle special characters
			     ((data-char) (case (node-property 'char
							       this-node)
				...))
			     ;; handle processing instructions
			     ((pi) (case (node-property 'system-data
							this-node)
				...))
			     ;; handle sdata entities
			     ((sdata) (case (node-property 'system-data
							   this-node)
				...)))
		       (if (node-list-empty? other-nodes)
			   (empty-sosofo)
			   (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.

-Chris
-- 
<!NOTATION SGML.Geek PUBLIC "-//Anonymous//NOTATION SGML Geek//EN">
<!ENTITY crism PUBLIC "-//O'Reilly//NONSGML Christopher R. Maden//EN"
"<URL>http://www.oreilly.com/people/staff/crism/ <TEL>+1.617.499.7487
<USMAIL>90 Sherman Street, Cambridge, MA 02140 USA" NDATA SGML.Geek>

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread