Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!umich!sharkey!msuinfo!news From: draper@buster.cps.msu.edu (Patrick J Draper) Newsgroups: comp.lang.modula2 Subject: Re: Compilier Problems Message-ID: <1990Dec6.203456.9301@msuinfo.cl.msu.edu> Date: 6 Dec 90 20:34:56 GMT References: Sender: news@msuinfo.cl.msu.edu Reply-To: draper@buster.cps.msu.edu (Patrick J Draper) Organization: Dept. of Computer Science, Michigan State University Lines: 42 In article Modula2 List writes: >>FST allows complete structures etc.. through var parameters ... > >Returning function results through var parameters? A practice somewhat >frowned upon! Write a procedure instead. > >Rob Griffiths >Computing Department >The Open University Suppose you have a procedure that looks up a record in an index and returns the record number, a common database procedure. Both the database and index might have to be changed in the function, and need to be returned through variable parameters. example: PROCEDURE ReturnKeyRecord (VAR db : DB; VAR index : INDEX; key : ARRAY OF CHAR) : LONGCARD; This procedure accepts two types that hold all relevant information about the database and index files, such as record length, field names, etc. The return value is the record in the database where the key was found. Both db and index are modified by some aspect of this function (when the key is found, both the db and index file pointers are changed) and MUST be returned or the program will crash. The ability to return values through both the parameter and return value is a feature of M2 because it is intuitive, and is also a safe mechanism. The example I have given above is much more logical to me than the alternative form where a variable called record is a parameter. When I look at the function, I KNOW that the primary focus of the function is to return a LONGCARD based on the parameters given. ------------------------------------------------------------------------ Patrick Draper In times like these it is helpful to buster.cps.msu.edu remember that there have always been times like these. ------------------------------------------------------------------------ Brought to you by Super Global Mega Corp .com