On May 21, 2008, at 11:20 PM, Johnny Lundy wrote:
You're correct - there is no first argument per se: it is part of the method selector, together they are called a "keyword."

http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_3.html

A message with a single argument affixes a colon to the selector name and puts the argument right after the colon. This construct is called a keyword ; a keyword ends with a colon, and an argument follows the colon. Thus we could diagram a message expression with a single argument (and assignment) as the following:

****If a message has multiple arguments, the selector has multiple keywords. A selector name includes all keywords****, including colons, but does not include anything else, such as return type or parameter types. A message expression with multiple keywords (plus assignment) could be diagrammed as follows:

I should clarify my previous statement slightly in light of this particular conceptual document.

I said:

Objective-C does not have named arguments. Nor does it have keyword arguments.

Quite specifically, Objective-C has no notion of the arguments arriving at the call site with any kind of labels applied to them. That is, the sub-parts of the method name -- of the selector -- are not optional, nor can the order be varied.

"Named arguments" and "keyword arguments" often carry the implication that the arguments to a method can vary at runtime; can have default values, can be in a different order, can possibly have additional named arguments, etc... This implication would further seem to be supported by the at-runtime method dispatch resolution featured within Objective-C.

Yet, this is exactly *not* how Objective-C works. For all intents and purposes, an Objective-C method declaration is simply a C function that prepends two additional arguments; self and _cmd.

That is, this....

- (BOOL) doSomethingNeat:(NeatMode) aMode toThisThing: (Thing *) aThing;

.... is equivalent to this function...

BOOL doSomethingNeatFunc(id self, SEL _cmd, NeatMode aMode, Thing *aThing);

... as far as the compiler type resolver is concerned. The order, type and number of arguments is absolutely fixed (var-args being the one exception; same rules apply as C).

This is quite distinctly different than the named or keyword arguments available in a language like Python:

def func(a, b, NeatMode=SuperNeat, Thing=DefaultThing):
        pass

Where Thing (and NeatMode) might be omitted or might have different values when called.

b.bum


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to