[comp.lang.misc] Alternatives to refs, was: Re: Algol-68 Best Since Sliced Bread ? / Re

smryan@garth.UUCP (Steven Ryan) (11/26/88)

>        begin int I := 0, K := 1;
>        ref int Ptr := I;
>        Ptr := K;
>        Print (I);
>        end
>
>The reason has to do with implicit conversions involving "ref" modes
>...
>the desired behavior, but to its discredit, it seems to have violated the
>principle of "least surprise", therefore making it not quite so "clear".

The confusion is that at times ref is treated as pointer and other times
as a variable. Dereferencing can run away and confuse the program as to
which is meant.

Other language instead have a variable/value dichotomy which is overlooked
when convenient, and when inconvenient, it is overlooked.

Another suggestion I've read is to explicitly include vars and refs. Refs
would be like Pascal's hats, and vars would be like Algol's refs. Then one
might have `operators' like:

         := = (var mode destination, mode source)mode: assignation,
         variable = (ref mode address) var mode: address as a variable address,
         address = (var mode variable) ref mode: the variable's address,
         = = (ref mode a,b) bool: instead of `:=:', same with `:/=:'

Instead of dereferencing, there would be devarring.

then the above example would come out as

         begin
           var int I = loc int := 0, K = loc int := 1;
           var ref int Ptr = loc ref int := address I;
           Ptr := address K;
           Print (I);
         end

Incidentally, was everybody else as confused as I when in
        {int *p; *p=1;}
`*' was called dereferencing? It doesn't actual dereference: it converts
a pointer to integer value into integer variable.
-- 
                                                   -- s m ryan
+-------------------------------+----------------------------------------------+
| Home of the brave and land of |  Congress shall make no law respecting the   |
| [deleted by the authority of  |  establishment of religion,...; or abridging |
| the Official Secrets Act].    |  the freedom of speech, or of the press;...  |
+-------------------------------+----------------------------------------------+