Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!elroy.jpl.nasa.gov!usc!wuarchive!udel!princeton!cs!elan!nr From: nr@elan.Princeton.EDU (Norman Ramsey) Newsgroups: comp.lang.modula3 Subject: Closures in m3 Message-ID: <7006@rossignol.Princeton.EDU> Date: 18 Feb 91 19:56:07 GMT Sender: news@cs.Princeton.EDU Organization: Dept. of Computer Science, Princeton University Lines: 29 Many of the table, list, et cetera data structure packages make it possible to enumerate elements of the table. Typically the procedures implementing the enumeration accept a REFANY as arguments, and this REFANY is used as a closure argument. An example from List: TYPE WalkProc = PROCEDURE (arg, element: REFANY) RAISES {}; (* The type of procedures for walking over lists. *) PROCEDURE Walk( l: T; p: WalkProc; arg: REFANY := NIL ); (* Applies p to each of the elements of l in turn. The only exceptions raised are those possibly raised by p. *) I suggest that it would be more elegant for enumeration to use closures (as in Thread). TYPE WalkClosure = OBJECT METHODS apply(element:REFANY) END; PROCEDURE Walk( l: T; p: WalkClosure ); 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.'' -- Norman Ramsey nr@princeton.edu