Jump to content

The Science of Programming/SwayPresentations/Objects/PublicAndPrivateComponents2

From Wikibooks, open books for an open world

Public and Private Components

We overload assignment so that only variables can appear on the left hand side of the assignment operator.

   function =($a,b)
       {
       var assign = shadowed(:=);
   
       if (type($a . code) != :VARIABLE)
          {
          throw(:restrictedAssignment,
              "you are only allowed to assign to simple variables");
          }
   
       $a assign b;
       }

So, anything like:

   x . a = 3;

throws an exception.

Since setters can access the variables directly, they are not affected by this change.


Next Previous Top