recursive iterators

alexc@world.std.com (Alex Colvin)
9 Mar 2002 03:05:09 -0500

          From comp.compilers

Related articles
recursive iterators alexc@world.std.com (2002-03-09)
Re: recursive iterators rhyde@cs.ucr.edu (Randall Hyde) (2002-03-19)
Re: recursive iterators bear@sonic.net (Ray Dillinger) (2002-03-21)
Re: recursive iterators sarah@telergy.com (2002-03-31)
Re: recursive iterators rhyde@cs.ucr.edu (Randall Hyde) (2002-04-06)
| List of all articles for this month |

From: alexc@world.std.com (Alex Colvin)
Newsgroups: comp.compilers
Date: 9 Mar 2002 03:05:09 -0500
Organization: The World Public Access UNIX, Brookline, MA
Keywords: design, question
Posted-Date: 09 Mar 2002 03:05:08 EST

Smalltalk appears to let you pass blocks (unevaluated expressions) to a
subroutine, allowing you to define your own control structures. Ruby seems
to have this to a very limited (one, anonymous, block) extent. CLU had
something similar.


Are there any languages, especially C derivatives, with extensible control
structures. C++ seems to have gone overboard with data-structure
extensions, but (aside from exceptions, to which I take,) left control
alone.


To be (lightly) more specific, I have a program where I walk tree
structures recursively, generating elements of a sequence. The program
does several of these walks at once, doing different things with the
elements.


I'd like to express this as loops over tree nodes, but the recursion in
the iterator doesn't easily fit into C++-style iterators. It works as
recursive functions, but then the loop bodies become closure-like
parameters.


I can force this in C and C++, but it's clumsy.


What I'd like is something more like Smalltalk, where the loop iterator
calls the loop body (or better, one of several alternative bodies).


Any thoughts? Is this straightforward in some popular language? Am I just
thinking incorrectly?


--
mac the naf
[If you consider perl to be popular, it also lets you pass anonymous code
blocks around, making this kind of trick straightforward. Icon isn't
all that well known, but let you build all sorts of fancy iterators as a
followon to Snobol4's pattern tree walk. If you want languages that compile
into machine code, Lisp and Scheme have done this for decades. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.