Optional parameters: Difference between revisions

Added Objective-C solution.
(→‎{{header|Ruby}}: Clarify, and sneak a link to Named parameters#Ruby.)
(Added Objective-C solution.)
Line 1,010:
// implementation goes here
}</lang>
 
=={{header|Objective-C}}==
Without getting into any detail, here is one way you might implement optional arguments. (Note that since Objective-C is a strict superset of C, any C solution can be used as well.)
<lang objc>typedef enum { kOrdNone, kOrdLex, kOrdByAddress, kOrdNumeric } SortOrder;
 
@interface MyArray : NSObject {}
// . . .
@end
 
@implementation MyArray
 
- (void)sort {
[self sortWithOrdering:kOrdLex onColumn:0 reversed:NO];
}
 
- (void)sortWithOrdering:(SortOrder)ord {
[self sortWithOrdering:ord onColumn:0 reversed:NO];
}
 
- (void)sortWithOrdering:(SortOrder)ord onColumn:(int)col {
[self sortWithOrdering:ord onColumn:col reversed:NO];
}
 
- (void)sortWithOrdering:(SortOrder)ord onColumn:(int)col reversed:(BOOL)rev {
// . . . Actual sort goes here . . .
}
 
@end</lang>
 
=={{header|OCaml}}==