Iteration Abstraction in Sather
started 4/10/2001; 6:32:19 AM - last post 4/12/2001; 6:42:21 AM
|
|
Ehud Lamm - Iteration Abstraction in Sather
4/10/2001; 6:32:19 AM (reads: 1377, responses: 7)
|
|
Iteration Abstraction in Sather |
This paper includes an interesting discussion of iteration mechanisms (like streams and cursors).
Sather iterators were inspired by CLU iterators, but extend their capabilites (e.g., the allow read/write access and are not read-only).
The paper contains a very insightful comparison of various iteration mechanisms and their uses. Coroutines and generators (cf. Icon) are discussed.
Posted to Software-Eng by Ehud Lamm on 4/10/01; 6:33:08 AM
|
|
|
|
John Lawter - Re: Iteration Abstraction in Sather
4/10/2001; 8:46:52 AM (reads: 1419, responses: 0)
|
|
The comments about parallel iterator heirarchies, in the C++ comparison, is pretty interesting. I don't see why (in other languages) iteration is not an ability of a collection but of a separate "helper" class.
Also, I think a comparison with some of the Smalltalk control structures would have been interesting. The Sather upTo iterator seems like Smalltalk's to message, for example.
|
|
Ehud Lamm - Re: Iteration Abstraction in Sather
4/10/2001; 8:59:57 AM (reads: 1402, responses: 0)
|
|
The comments about parallel iterator heirarchies, in the C++ comparison, is pretty interesting. I don't see why (in other languages) iteration is not an ability of a collection but of a separate "helper" class.
Otherwise you have a problem impelmenting different iteration policies. It is also a question of coupling.
This isssue is discussed in the GoF book, IIRC. Also in some of Robert Martin's papers.
|
|
John Lawter - Re: Iteration Abstraction in Sather
4/10/2001; 1:31:14 PM (reads: 1382, responses: 0)
|
|
But, in order to implement an "external" iterator, in most cases the author would need to make assumptions about a collection class' implementation. This breaks encapsulation, and increases coupling.
I'm not sure what you mean by "policy"; I am assuming that you're referring to something like in-order vs. post-order traversals for trees. In this case, one could simply add extra traversal methods, so that a Tree collection would implement, say, "nextElementInPostOrder" in addition to a plain "nextElement."
Also, by having an external iterator class holding on to a collection's element, it could create garbage collection problems, where an item is retained after it is needed.
|
|
Chris Rathman - Re: Iteration Abstraction in Sather
4/11/2001; 12:11:29 AM (reads: 1387, responses: 0)
|
|
This isssue is discussed in the GoF book, IIRC. Also in some of Robert Martin's papers. Beyond the obvious question of internal vs. external iteration, there is the question of coroutines & generators. One aspect of this is iteration - which is built into some languages, while it is a "design patten" in other languages.
Remember that iteration in the normal sense is just one aspect of the concept of coroutines. In my mind, coroutines are more like of sink if data, wherein data can be retrieved in sequential fashion. That sink can be a simple sequence of values within a list (array, collection), or it can be a the next item in a function (an infinite list). The bottom line in coroutines is that you can get late evaluation of terms (lazy evaluation).
Although you can achieve coroutines in a number of languages, it seems to me that the languages with the best implementation are Icon (generators), Sather (coroutines), and Haskell (lazy evaluation.
Perhaps the most interesting aspect is how the concepts of generators, coroutines and lazy evaluation are inexorably intertwined. If you get one of the three, then you invariably can get the other two.
One interesting thing that I noted from reading Betrand Meyer is that coroutines were done very well in Simula. Intersting that Sather is a takeoff on the concept of coroutines, but never officially accepted by Meyer in the Eiffel language.
Speaking of Sather, what's up? I was hoping that GNU taking over the project would spring it forward, but last I checked it hasn't made a whole lot of progress. Not that Eiffel really needs a spinoff language, but Sather has been interesting in it's own right.
|
|
Chris Rathman - Re: Iteration Abstraction in Sather
4/11/2001; 12:18:34 AM (reads: 1376, responses: 0)
|
|
Sather iterators were inspired by CLU iterators I must admit a certain blindspot to CLU on the subject of iterators. You've alledued to CLU iterators in the past (in perhaps a cryptic manner to others), but I was wondering if you had some examples of CLU iterators?
|
|
Ehud Lamm - Re: Iteration Abstraction in Sather
4/11/2001; 5:32:48 AM (reads: 1436, responses: 0)
|
|
I was wondering if you had some examples of CLU iterators?
One wouldn't want you to remain CLUless, so here is an example (from A Brief Introduction to CLU by Guttag):
set[t] = cluster is create, insert, member, elems, equal
rep = array[t]
create = proc() retrurns (cvt)
return rep$new())
end create
...
elems = iter (s:cvt) yields (t)
for e: t in rep$elems(s) do yield(e) end
end elems
equal = proc (s1: set, s2: set) returns (bool)
if rep$size(down(s1)) ~= rep$size(down(s2)) then
return (false) end
for e: t in elems(s1) do
if ~member(s2, e) then return(false) end
end
return(true)
end equal
end set
Set is a cluster (ADT). elems is an iterator. Notice that yield is used and not return. Inside it uses the elems iterator of rep, which is an array (see first declartion). Notice how the builtin iterator works just like the user created iterator which is used inside the equal function.
I know this is a simple example. I am not a CLU expert. The Sather paper above goes into more details about the capabilities of CLU iterators (as compare to the Sather variety).
|
|
Ehud Lamm - Re: Iteration Abstraction in Sather
4/12/2001; 6:42:21 AM (reads: 1375, responses: 0)
|
|
Another discussion of iterators can be found on this wiki page about Java iterator semantics.
|
|
|
|