4 ms·
Objective.st has a very clean syntax. But this can also be done with Objective-C: [[@[@1, @2, @3] valueForKeyPath:@"@sum.self"] integerValue] + 5 This can b
by LinaLauneBaer 13y ago
Objective.st has a very clean syntax. But this can also be done with Objective-C:
[[@[@1, @2, @3] valueForKeyPath:@"@sum.self"] integerValue] + 5
This can be improved:
@implementation NSArray (Private)
- (NSInteger)collect {
return [[self valueForKeyPath:@"@sum.self"] integerValue];
}
@end
And then you can write:
[[@[@1, @2, @3] collect] + 5;
I know: HOM is a more abstract/generic thing. If it was built in the language you could just use it as is without reinventing the wheel all the time... I just want to point out that Objective-C can be made look nice as well :)
- mpweiher 13y agoYes, I first implemented HOM in Objective-C, back in 1997 or so... However, collect + 5 doesn't first sum and then add 5 to the sum, it distributes the +5 to every element, and any other message you care to send.
- LinaLauneBaer 13y agoOmg are you marcel weiher? How can I do you something good? Beer? Candy? :) Back in the days I read your paper and obviously I forgot what "collect" means... If you are Marcel then you are one of my heros.