🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5333

iteration/traversion

#5333
From: Silver
Date: Sun, 20 Mar 1988 19:47
31 lines
1621 bytes
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
Technical Details
Message-ID: <Mar.20.14.47.03.1988.1079@athos.rutgers.edu>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!tut.cis.ohio-state.edu!rutgers!aramis.rutgers.edu!athos.rutgers.edu!gaynor
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <1130@PT.CS.CMU.EDU> <3864@bloom-beacon.MIT.EDU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <Mar.20.14.47.03.1988.1079@athos.rutgers.edu>
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