Interesting C++ use of white space.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Interesting C++ use of white space.

Owen Densmore
Administrator
Bjarne Stroustrup, creator of C++, posed this interesting use of overloading:

The idea was somewhat forced upon him by ATT Labs mathematicians and physicists who wanted:
int x,y,z;
z=xy
to function as in standard math notation as set z to x times y.

I believe the notion failed to achieve popularity due to lexical scoping of the language, where variables might lie in entirely different bodies of source code.  Closures were, of course considered as a way to define the allowed scope for variables, but C++ had not implemented them.

   -- Owen



============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
lectures, archives, unsubscribe, maps at http://www.friam.org
Reply | Threaded
Open this post in threaded view
|

Re: Interesting C++ use of white space.

Bruce Sherwood
I think you meant z = x y, Owen.

In the TUTOR language of the PLATO computer-based education system
(see links on my home page, http://www4.ncsu.edu/~basherwo), I
implemented a function called "compute" for evaluating algebraic
student input in which xy (or x y) was treated as x*y. The method
relied on the fact that in typical algebraic usage in educational
settings variables have short names. The symbol-table lookup searched
for the longest name, so that if x, y, and xy were all defined "xy"
was taken to mean a reference to the variable xy. But if only x and y
were defined, "xy" was taken to mean x*y.

However, for clarity and lack of ambiguity ordinary calculations in
the TUTOR language did not permit implied multiplication. If you meant
x*y you had to express it as x*y.

Another interesting aspect of the compute function was that it
compiled the expression to machine code and stored this code in a
buffer where it could be reused, thereby permitting fast looping
execution of user-input statements.

Bruce

On Sun, Apr 1, 2012 at 12:02 AM, Owen Densmore <[hidden email]> wrote:

> Bjarne Stroustrup, creator of C++, posed this interesting use of
> overloading:
>
> http://www2.research.att.com/~bs/whitespace98.pdf
>
>
> The idea was somewhat forced upon him by ATT Labs mathematicians and
> physicists who wanted:
>
> int x,y,z;
> z=xy
>
> to function as in standard math notation as set z to x times y.
>
> I believe the notion failed to achieve popularity due to lexical scoping of
> the language, where variables might lie in entirely different bodies of
> source code.  Closures were, of course considered as a way to define the
> allowed scope for variables, but C++ had not implemented them.
>
>    -- Owen
>
>
>
>
> ============================================================
> FRIAM Applied Complexity Group listserv
> Meets Fridays 9a-11:30 at cafe at St. John's College
> lectures, archives, unsubscribe, maps at http://www.friam.org

============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
lectures, archives, unsubscribe, maps at http://www.friam.org
Reply | Threaded
Open this post in threaded view
|

Re: Interesting C++ use of white space.

Owen Densmore
Administrator
On Sun, Apr 1, 2012 at 9:59 AM, Bruce Sherwood <[hidden email]> wrote:
I think you meant z = x y, Owen.

No, surprisingly enough.  Further down the paper you'll find this section:
 
Overloading Missing Whitespace

After some experimentation, it was discovered that the overloading mechanism described so far did not go far enough. When using the mechanism, the physicists tended to omit the space character and write
xy
rather than
x y
This problem persisted even after the overloading rules had been clearly and repeatedly explained. What was needed wasn't just the ability to overload explicit use of whitespace, but also implicit application. This is easily achieved by modifying the lexical analyzer to recognize 
xy
as the two tokens 
x y 
when x and y are declared. The "missing whitespace" between two identifiers are assumed to be a space.

On Sun, Apr 1, 2012 at 9:59 AM, Bruce Sherwood <[hidden email]> wrote:
I think you meant z = x y, Owen.

In the TUTOR language of the PLATO computer-based education system
(see links on my home page, http://www4.ncsu.edu/~basherwo), I
implemented a function called "compute" for evaluating algebraic
student input in which xy (or x y) was treated as x*y. The method
relied on the fact that in typical algebraic usage in educational
settings variables have short names. The symbol-table lookup searched
for the longest name, so that if x, y, and xy were all defined "xy"
was taken to mean a reference to the variable xy. But if only x and y
were defined, "xy" was taken to mean x*y.

However, for clarity and lack of ambiguity ordinary calculations in
the TUTOR language did not permit implied multiplication. If you meant
x*y you had to express it as x*y.

Another interesting aspect of the compute function was that it
compiled the expression to machine code and stored this code in a
buffer where it could be reused, thereby permitting fast looping
execution of user-input statements.

Bruce

On Sun, Apr 1, 2012 at 12:02 AM, Owen Densmore <[hidden email]> wrote:
> Bjarne Stroustrup, creator of C++, posed this interesting use of
> overloading:
>
> http://www2.research.att.com/~bs/whitespace98.pdf
>
>
> The idea was somewhat forced upon him by ATT Labs mathematicians and
> physicists who wanted:
>
> int x,y,z;
> z=xy
>
> to function as in standard math notation as set z to x times y.
>
> I believe the notion failed to achieve popularity due to lexical scoping of
> the language, where variables might lie in entirely different bodies of
> source code.  Closures were, of course considered as a way to define the
> allowed scope for variables, but C++ had not implemented them.
>
>    -- Owen
>
>
>
>
> ============================================================
> FRIAM Applied Complexity Group listserv
> Meets Fridays 9a-11:30 at cafe at St. John's College
> lectures, archives, unsubscribe, maps at http://www.friam.org

============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
lectures, archives, unsubscribe, maps at http://www.friam.org


============================================================
FRIAM Applied Complexity Group listserv
Meets Fridays 9a-11:30 at cafe at St. John's College
lectures, archives, unsubscribe, maps at http://www.friam.org