1 Changes to RSL 1 Changes to RSL
1.2 Comments 1.2 Comments
1.1 With expressions

1.1 With expressions

There is a new kind of class expression:

with element-object_expr-list in class_expr

which allows the qualifications in names to be omitted. This is particularly useful when you redefine operators. For example, if you have in a scheme S

                                     
 ...
 value + : T × T → T
 ...

and in another you have S as a parameter or make an object from it, then without the with expression you have to write

                                     
 class
 object O : S
 ...
 O.(+)(x,y)
 ...
 end

The operator + outside the object O has to be called O.(+) and used prefix.

Now you can write instead

                                     
 with O in class
 object O : S
 ...
 x + y
 ...
 end

The same can be done if "O : S" is a scheme parameter.

The meaning of "with X in" is, essentially, that an applied occurrence of a name N in its scope can mean either N or X.N. It is necessary, of course, that of the two possibilities either only one exists or they are distinguishable.

With expressions may be nested. "with Y in with X in" means that a name N in its scope can mean N or X.N or Y.N or Y.X.N. (The last arises because X is in the scope of the outer with, and so can mean X or Y.X.)

It is generally more efficient to use a single with rather than nesting them. "with Y, X in" means that a name N in its scope can mean N or X.N or Y.N. Order within a single with is not significant.


Chris George, April 17, 2008

1.1 With expressions
1 Changes to RSL 1 Changes to RSL
1.2 Comments 1.2 Comments