Path: utzoo!mnetor!uunet!husc6!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!athos.rutgers.edu!gaynor From: gaynor@athos.rutgers.edu (Silver) Newsgroups: comp.lang.misc Subject: iteration/traversion Message-ID: Date: 20 Mar 88 19:47:03 GMT References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <1130@PT.CS.CMU.EDU> <3864@bloom-beacon.MIT.EDU> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 31 F(Type) - The desired function to apply to elements of type. iterator(Type) - a function that returns the next valid element of Type according to some rule, if one exists; null otherwise traverser(Type) - a function that, for every iteration T of Type, F(T) is evaluated I suppose you can see what I'm getting at. Supplying a function to the traverser is equivalent to: while (T = iterator(Type)) do F(T) This is easy enough to do in most programming languages. Even pascal allows you to pass subprograms to other subprograms. I can't count the number of traversals I've written like this: /****************************************************************\ * preorder: apply F to every subtree of T, ordered by a preorder * * traversal * \****************************************************************/ preorder(tree T, function F(tree)) if T, F(T) preorder(left(T), F) preorder(right(T), F) ___ Cheers, \o/ Silver 201-932-2443 (mostly) V (internet) gaynor@rutgers.edu 201-545-0458 (rarely) _|_ (uucp) ...!rutgers!gaynor