damm@diku.dk (Kristian Damm Jensen) (05/29/88)
In article <5915@uwmcsd1.UUCP> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes: >In article <3499@omepd> bobdi@omepd.UUCP (Bob Dietrich) writes: << stuf deleted >> >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. This is not correct. A way to overcome this problem is to put those multiple values in a record, and let the function return a pointer to the record. Agreed, this doesn't seem very elegant, but it works, an you favor a LISP-like programming style, then it's very handy. >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) This example would then become Type TwoCharPointer = ^ThoCharRecord; TwoCharRecord = Record a, b : Char End; Function Switch (TwoChars : TwoCharRecord) : TwoCharPointer; Var help : Char; Return : TwoCharPointer; Begin With ThoChars Do Begin help := a; a := b; b := help End; Return^ := TwoChars; Switch := Return End; -- Kristian Damm Jensen (damm@diku.denet.uucp)
art@buengc.BU.EDU (A. R. Thompson) (05/31/88)
In article <3854@diku.dk> damm@diku.dk (Kristian Damm Jensen) writes: >In article <5915@uwmcsd1.UUCP> markh@csd4.milw.wisc.edu (Mark William Hopkins) writes: >>In article <3499@omepd> bobdi@omepd.UUCP (Bob Dietrich) writes: > << stuf deleted >> >>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. > >This is not correct. A way to overcome this problem is to put those >multiple values in a record, and let the function return a pointer to >the record. Agreed, this doesn't seem very elegant, but it works, an you Wrong. The result of the function is the pointer, not the record. The pointer is a single value of a simple type. Actually, functions that have structured types as a result type are to become part of the new Pascal standard due out soon. When? The Oregon Software Pascal compiler, which I use as the Encore Pascal-2 compiler, does indeed allow structured types as the result types of functions. I can attest that this is quite handy, and makes good logical sense to boot. Rest deleted.
windley@iris.ucdavis.edu (Phil Windley) (05/31/88)
In article <347@buengc.BU.EDU> art@buengc.bu.edu (A. R. Thompson) writes: >Wrong. The result of the function is the pointer, not the record. The >pointer is a single value of a simple type. Actually, functions that have >structured types as a result type are to become part of the new Pascal >standard due out soon. When? > >The Oregon Software Pascal compiler, which I use as the Encore Pascal-2 >compiler, does indeed allow structured types as the result types of >functions. I can attest that this is quite handy, and makes good logical >sense to boot. > Berkeley Pascal (the one that comes with most BSD implementations of UNIX) allows this as well. It works great. I teach an introductory CS class and trying to teach good data abstraction would be difficult if it were not for this. Try writing a rational number package without being able to return structured types from a function. The best you can do is to simulate it with pointers and there's no need for that extra complication. Phil Windley | windley@iris.ucdavis.edu Robotics Research Lab | ucbvax!ucdavis!iris!windley University of California, Davis |
bobdi@omepd (Bob Dietrich) (06/01/88)
In article <347@buengc.BU.EDU> art@buengc.bu.edu (A. R. Thompson) writes: > [...] Actually, functions that have >structured types as a result type are to become part of the new Pascal >standard due out soon. When? > There is a letter ballot out now on whether to send the latest version of the draft proposed Extended Pascal standard out for public comment. The ballot period ends June 3, and results should be available at the Joint Pascal Committee (JPC) meeting the week of June 13 in Minnesota. Assuming the ballot succeeds, a month or so later the draft will go out for a public comment period of probably 60 days. Any comments received must be resolved, and then the decision made whether or not the resolution caused substantial change, which means going through the cycle again. This will be the second public comment period for the draft. The first comment period generated a couple of inches of comments and responses, but I think we are converging. Extended Pascal won't be a perfect language (name one that is to everyone!), but I think it will be quite useful. Bob Dietrich Intel Corporation, Hillsboro, Oregon (503) 696-4400 or 2092(messages x4188,2111) usenet: tektronix!ogcvax!omepd!bobdi or tektronix!psu-cs!omepd!bobdi or ihnp4!verdix!omepd!bobdi