Path: utzoo!mnetor!uunet!mcvax!ukc!cam-cl!scc From: scc@jenny (Stephen Crawley) Newsgroups: comp.lang.misc Subject: Re: Iterators Message-ID: <111@gannet.cl.cam.ac.uk> Date: 28 Mar 88 15:01:35 GMT References: <1147@jenny.cl.cam.ac.uk> <2913@enea.se> Sender: news@cl.cam.ac.uk Reply-To: scc@cl.cam.ac.uk (Stephen Crawley) Organization: U of Cambridge Comp Lab, UK Lines: 40 In article <2913@enea.se> sommar@enea.UUCP(Erland Sommarskog) writes: >Stephen Crawley (scc@cl.cam.ac.uk) writes: >>2) Declare the loop body procedure in the same (non-global) scope as >> the local variables for the loop. The loop locals are then available >> to the loop body procedure as non-locals. This assumes that your >> language allows this ... C, BCPL, Pascal, Modula-*, Ada etc don't, >> but Algol-68 and Mesa do, as do any languages which support proper >> procedure closures. >> > >I'm not entirely sure what you mean, so my apologies if my objection >isn't relevant. But looking at your example, it seems something that >is straghtforward to do in Ada. Arland's objection is both relevant and correct. Since Ada does not allow you to treat procedures as values, the mechanism I proposed (passing procedure as parameters to other procedures) does not work. However, Ada does allow you to use procedures as parameters to a generic package. As Erland pointed out, this allows you to construct iterators. [It is sad that Ada forces you to go to the trouble of constructing a generic package for a data structure you want to iterate over.] Perhaps I shouldn't make statements about languages I've never used ... >(There are probably some people objecting strongly against the use >of the exception here. And I may well agree it's brute force. >I included it just to show that there is a way out, ever the author >of the iterator forgot to put in a stop condition.) I'll excuse you! :-) End conditions on pseudo-iterators are frequently messy. Yet another reason for wanting REAL iterators in a language. [Sorry about the crap on the end of my last article. People around here have made it unnecessarily hard to post news ... and that was the result.] -- Steve