[net.lang.c] Side effects in Pascal.

kjm@ut-ngp.UUCP (Ken Montgomery) (04/21/85)

From: lspirkov@udenva.UUCP (Goldilocks)
>In article <> kjm@ut-ngp.UUCP (Ken Montgomery) writes:
>>[]
>>
>>From: lspirkov@udenva.UUCP (Goldilocks)
>>>In article <> jack@boring.UUCP (Jack Jansen) writes:
>>>>
>>>>procedure p(var i:integer):integer;
>>              ^^^

[...]

>
>I wasn't talking about the var parameters.  i was talking
>about his syntax.  try running that bit of code (with
>a main program & the rest of the skeleton) and see what you
>get...
>
>                                        Goldi
>
>ps:  what it should have been was:
>function p(var i:integer):integer;
>^^^^^^^^
>        ...

Yes.  My goof on the syntax.  But, about the point of the original
example which, as I remember, was that side effects of expressions
can occur even in an allegedly "clean" language like Pascal.  The
example demonstrated this adequately, even with the coding error.
(I was paying attention to the point begin made, not to minor errors
which any compiler would catch.  I think the procedure/function
split is ridiculous, anyway.)


I also just saw the following article, whose salient part I will
excerpt:

From: john@moncol.UUCP (John Ruschmeyer) Message-ID: <259@moncol.UUCP>
>>>>procedure p(var i:integer):integer;
>>              ^^^
>                           ^^^^^^^^
>[...]
>
>The part I have highlighted is used in a FUNCTION declaration to declare
>the type of the value returned. The type of values returned by a PROCEDURE
>is declared by the 'var' as you pointed out.
>
>The correct declaration is:
>
>        procedure p(var i:integer);
>
>I don't have the original article handy, but it almost looks like someone
>was trying to perform the illegal:
>
>        function p(var i:integer):integer;
>
>which would be an attempt at declaring a function which returns two values.
>I pray that somewhere there isn't a compiler which would accept that. 
>(Ooh, ick!)
>
>Name:       John Ruschmeyer

Berkeley Pascal accepted a function declaration syntactically equivalent
to the above, as did the local Cyber Pascal compiler, in the following:

   program x(output);

   var j:integer;

   function a(var i:integer):integer;
   begin
       a := i;
       i := i + 1;
   end;

   begin
       j := 1;
       j := j + a(j);
       writeln(j);
   end.

I believe Mr. Jansen, in the article on which this whole brouhaha is
based, was advocating *not* writing code with side effects.  (BTW, the 
above program prints '3' on the Vax and '2' on the Cyber.)  However,
I fail to see why it is necessarily bad for a function to return several
values.

--
The above viewpoints are mine.  They are unrelated to
those of anyone else, including my cats and my employer.

Ken Montgomery  "Shredder-of-hapless-smurfs"
...!{ihnp4,allegra,seismo!ut-sally}!ut-ngp!kjm  [Usenet, when working]
kjm@ut-ngp.ARPA  [for Arpanauts only]