Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!think.com!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!pa.dec.com!src.dec.com!src.dec.com!mjordan From: mjordan@src.dec.com (Mick Jordan) Newsgroups: comp.lang.modula3 Subject: Re: Closures in m3 Message-ID: <1991Feb19.131249.21399@src.dec.com> Date: 19 Feb 91 21:12:49 GMT References: <7006@rossignol.Princeton.EDU> Sender: news@src.dec.com (News) Reply-To: mjordan@src.dec.com (Mick Jordan) Organization: DEC Systems Research Center Lines: 31 > I would like to hear people's comments on this proposal. If you won't > buy ``more elegant,'' perhaps you'll buy ``typechecked at compile time.'' 'List' is an example of an interface that was simply copied from the M2+ world, hence the REFANY. It is certainly not the best way to do callback iterators in Modula-3, which are neatly handled by 'object closures' as you suggest, particularly given that state needed by the WalkProc can be bundled up as a subtype of WalkClosure. Actually, for simple data structures I prefer the following style of iterator: VAR someContainerType: SomeContainerType.T; containedType: ContainedType.T; iter := SomeContainerType.NewIter(someContainerType); BEGIN WHILE SomeType.Next(iter, containedType) DO (* process 'containedType' *) END; END; This has the virtue that you do not need to bundle up state into the object closure, nor do you need to code a new procedure. Finally, note that, because Modula-3 permits nested procedures to be passed as arguments, the closure REFANY ('arg') isnt really necessary since local state can be accessed directly from the nested procedure. However, not everybody likes nested procedures. Mick Jordan