Newsgroups: comp.lang.c++,comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uhog.mit.edu!bloom-beacon.mit.edu!gatech!howland.reston.ans.net!ix.netcom.com!netcom.com!milod
From: milod@netcom.com (John DiCamillo)
Subject: Re: Smalltalk @ Operator in C++
Message-ID: <milodD5pFxn.FDK@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
References: <3k7rdd$drs@News1.mcs.com> <milodD5KGus.sp@netcom.com> <3kd9cq$phj@News1.mcs.com>
Date: Sun, 19 Mar 1995 20:36:58 GMT
Lines: 65
Sender: milod@netcom12.netcom.com
Xref: glinda.oz.cs.cmu.edu comp.lang.c++:118431 comp.lang.smalltalk:21931

jim.fleming@bytes.com (Jim Fleming) writes:
>In article <milodD5KGus.sp@netcom.com>, milod@netcom.com says...
>>jim.fleming@bytes.com (Jim Fleming) writes:

>>>How do I convert Smalltalk programs that heavily use the @ method
>>>selector to C++?

>>I don't know how *you* would do this in C++, but I would do it:
>>
>>   TPoint a(150,200);
>>

>I guess my original question was not clear. If I have a program
>that uses *operators* to provide better readability, and I happen
>to to desire to convert that program to another language that also
>has "operators" and an extensive set of "operator overloading"
>features, why would I want to give up my notation?

Because not all programming languages express all concepts in the
same way.  In particular, C++ operator overloading is unlike any
language feature in Smalltalk (which is typeless, and has no built-
in operators).

>For example, if I had been using:
>	a = (x + 3.1416) * y;
>Do I really want to change this to:
>	a = multiply(add(x,3.1416),y);
>Is that a step forward?

I don't know.  But your question had to do with the @ operator,
which has no readily accepted meaning outside of the Smalltalk
(and apparently C+@) programming community.

>My question has to do with the @ operator.
>In the example, + and * are operators.

>Maybe it will help to look at real code and you can show me what I
>have to write in C++. In both examples shown, a Point object is
>created with a value of (x,y)=>(160,240) and this object is sent
>the message "grid" with an argument of (x,y)=>(50,50). The result
>is a Point object with (x,y)=>(150,250).

>Smalltalk:
>result := 160@240 grid: 50@50.

>C+@:
>result = (160@240).grid(50@50);

>C++:
Point result(160,240);
result.alignToGrid(50,50);  // personally, I would not make this
							// a method of the Point class...

Grid grid(50,50);
result = grid.snap(result);

This last is a better design (IMHO) because it encapsulates knowledge
of the grid in its own class.  This is useful for example in allowing
the user to selectively disable the grid snap; if the grid is turned
off, then the snap operation is a no-op.
-- 
    ciao,
    milo
================================================================
    John DiCamillo                        Pinin' for the fjords?
    milod@netcom.com                  What kind of talk is that?
