Path: utzoo!attcan!uunet!husc6!bloom-beacon!gatech!bbn!uwmcsd1!csd4.milw.wisc.edu!markh From: markh@csd4.milw.wisc.edu (Mark William Hopkins) Newsgroups: comp.lang.pascal Subject: Re: The gaping hole left by var parameters ... Summary: Something can be done about it. Message-ID: <5915@uwmcsd1.UUCP> Date: 29 May 88 01:10:30 GMT References: <5879@uwmcsd1.UUCP> <3499@omepd> Sender: daemon@uwmcsd1.UUCP Reply-To: markh@csd4.milw.wisc.edu (Mark William Hopkins) Organization: University of Wisconsin-Milwaukee Lines: 59 In article <3499@omepd> bobdi@omepd.UUCP (Bob Dietrich) writes: >In article <5879@uwmcsd1.UUCP> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes: >>What's wrong with var parameters? >>Try these out to see how they compile and run: >>Enjoy ... > >I see you've rediscovered aliasing and functions having side-effects, but >you're certainly not pointing out anything new. Languages that have a >variable parameter mechanism and scoping have always had this problem, and >it isn't likely to go away. Likewise functions with side-effects. Both >mechanisms have their drawbacks, but are generally too useful to plug all the >holes (the old "double-edged sword" argument). Attempts are made from time to >time, but they usually just force the programmer into an alternate and >perhaps less natural construct (like returning a result in a parameter >instead of as a function result). You have a point on one matter: as long a Pascal does not allow files-as-values side-effects must occur be allowed in functions. Also, as long as Pascal does not allow the one to construct functions that can return MULTIPLE values, one will need to write procedures with var parameters in their stead. Example: procedure Switch(var A, B : char); var C : char; begin C := A; A := B; B := C end; called in the environment Switch (X, Y) would become: function Switch(A, B : char) --> (char, char); var C : char; begin C := A; A := B; B := C; return (A, B) end; called as follows: (X, Y) := Switch(X, Y) The function could even be simplified to: function Switch(A, B : char) --> (char, char);... begin return (B, A) end; so that it would no longer be necessary to declare it, it could be directly substituted into the calling environment: (X, Y) := (Y, X) These kinds of simplifications would result in general. The cost is modest: introducing a new type constructor for either LISTS or for variable-sized arrays (TUPLES) and introducing functions that return values of such types.