• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Several questions on Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Several questions on Objective C


  • Subject: Re: Several questions on Objective C
  • From: Ondra Cada <email@hidden>
  • Date: Sun, 7 Apr 2002 22:56:40 +0200

On Sunday, April 7, 2002, at 10:44 , Erik M. Buck wrote:

p.s. Operator overloading is the one saving grace of C++. Think quadratic
roots. Think matrix/vector math.

Well, I've never needed that myself (and thus never done it), but I guess it would be relatively simple to expand the ObjC language by a _specific_ set of overloadable operators.

The idea is quite plain:

(i) make a preprocessor, which would translate a pattern

exp @c exp

(where exp is an ObjC expression, @ is just '@', and c is any single character) to

[exp operator_G:exp]

where G is the glyph name of the character c.

I don't say the preprocessor (with all the precedence rules and alike) would be extremely simple, but I bet it should be finished and debugged in a week or so.

(ii) the usage would be quite intuitive, would it not?

NSString *s=s1 @+ s2; // == s=[s1 stringByAppendingString:s2]

etc...

As for the actual overloading, nothing more than defining the appropriate "operator_G:" methods would be needed.

Well, I repeat I *never* felt the need myself, but if anyone really lacks overloaded operators in ObjC, I guess this would be a way, which should not bring any of the grave drawbacks of operator overloading of C++ (mainly thanks to the different scope forced by the mandatory '@'), being at the same time almost as conveninent. At least, I don't see *too* grave a difference between "a + b * c - (d + e)" and "a @+ b @* c @- (d @+ e)"
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Operator overloading (was: Re: Several questions on Objective C)
      • From: Michael Gersten <email@hidden>
    • encodeWithCoder for a BOOL?
      • From: Marc Respass <email@hidden>
References: 
 >Re: Several questions on Objective C (From: "Erik M. Buck" <email@hidden>)

  • Prev by Date: Re: Retrieving "default" defaults after registerDefaults?
  • Next by Date: Sending AppleEvents from Cocoa
  • Previous by thread: Re: Several questions on Objective C
  • Next by thread: encodeWithCoder for a BOOL?
  • Index(es):
    • Date
    • Thread