Article View: comp.lang.misc
Article #5296Re: From Modula to Oberon
From: Eddie Wyatt
Date: Wed, 16 Mar 1988 17:40
Date: Wed, 16 Mar 1988 17:40
36 lines
1717 bytes
1717 bytes
>
> The debate about CLU iterators misses an important point: CLU iterators are
> coroutines, which C does not have. The implication is that per-iteration state
> is nicely hidden in CLU ("on the stack" in the coroutine local variables), and
> has to be explicitly managed in C (or any other coroutine-free language) by
> putting the state into globals or making the user hang on to the state.
>
But do you need coroutines to implimented generlized iteration.
I think not. The optional solution I posted should allow you
to perform the same task.
The optional solution was to provided the iteration function a function
to invoke on each member of the enumerated list. A single call would be
made to iterate through the list.
Example:
void iterate_inorder(root,func)
TREE *root;
void (*func)();
{
if (root != NULLPTR(TREE))
{
iterate_inorder(root->left,func);
func(root->val);
iterate_inorder(root->right,func);
}
}
I do see one problem though, which is dealing with variable
referenced inside the loop. They would have to become
global. Comments as to why this method might not work in general?
--
Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu
Technical Details
Message-ID:
<1139@PT.CS.CMU.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edwReferences:
<2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <22162@bbn.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mit-eddie!bbn!rochester!PT.CS.CMU.EDU!IUS1.CS.CMU.EDU!edw From: edw@IUS1.CS.CMU.EDU (Eddie Wyatt) Newsgroups: comp.lang.misc Subject: Re: From Modula to Oberon Message-ID: <1139@PT.CS.CMU.EDU> Date: 16 Mar 88 17:40:23 GMT References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <22162@bbn.COM> Sender: netnews@PT.CS.CMU.EDU Organization: Carnegie-Mellon University, CS/RI Lines: 36