🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by tuvie!brock@rela Sat, 30 Sep 1989 17:36
Recursive iterator in CLU?
#17
Author: tuvie!brock@rela
Date: Sat, 30 Sep 1989 17:36
14 lines
682 bytes
CLU's explicit concept of iterators seems at the first glance preferable
to the rather ad hoc way iterators are defined in oo -languages. (As
a method of an object, or as a friend-class.) Instead of handling
the whole state of the iterator explicitely, one can imagine the yield
statement as yust a "print" statement which will pe "piped" to the caller.
But this works for simple examples only. If you want to traverse e.g. a binary
tree you have to call within the iterator the same iterator for both left and
right subtree. In my opinion it would be more intuitive to use the "print"
methapher for all kinds of calls.

Has there anybody extended iterators in such a way?

Ulrich
Re: Recursive iterator in CLU?
#18
Author: scc@cl.cam.ac.uk
Date: Tue, 03 Oct 1989 22:53
48 lines
1480 bytes
Ulrich Neumerkel writes:
> CLU's explicit concept of iterators seems at the first glance preferable
> to the rather ad hoc way iterators are defined in oo -languages. (As
> a method of an object, or as a friend-class.) Instead of handling
> the whole state of the iterator explicitely, one can imagine the yield
> statement as yust a "print" statement which will pe "piped" to the caller.
> But this works for simple examples only. If you want to traverse e.g. a
> binary tree you have to call within the iterator the same iterator for
> both left and right subtree. In my opinion it would be more intuitive
> to use the "print" methapher for all kinds of calls.

Recursive iterators are no problem in CLU.  For example:

tree_node = cluster [T: type] is tree_walk ...

rep = struct [
  left:		node_or_leaf,
  right:	node_or_leaf]

node_or_leaf = oneof [
  a_node:	tree_node,
  a_leaf:	T]

tree_walk = iter (node: cvt) yields (T)
  tagcase node.left
    tag a_node (n: tree_node):
      for leaf: T in tree_walk(n) do yield (leaf) end
    tag a_leaf (leaf: T):
      yield (leaf)
    end
  tagcase node.right
    tag a_node (n: tree_node):
      for leaf: T in tree_walk(n) do yield (leaf) end
    tag a_leaf (leaf: T):
      yield (leaf)
    end
  end

..

end tree_node

Frankly, I don't see what is non-intuitive about this use of recursion.
The CLU compiler may do a poor job of optimising recursive iterators ...
but that is a different issue entirely.

-- Steve
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads