discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PROPOSAL: Objective-C++


From: Erik M. Buck
Subject: Re: PROPOSAL: Objective-C++
Date: Mon, 19 Nov 2001 20:49:38 -0600

> I learned Objective-C after 3 years of (nearly) exclusive use of
> Smalltalk.  I was pleased to get the added speed of C's primitive types
> (int, float, etc) and loops, but really missed blocks.  A very simple use
> of a block is to apply a operation to all elements of a collection
(array),
> for example:
>
> - (void) arrayDo: (NSArray *) array
> {
>          [ array do: [ :item | item doSomething ]];
> }
>
> This example can currently be coded in Objective-C, but isn't nearly as
> elegant:
>
> - (void) arrayDo: (NSArray *) array
> {
>          int i;
>          for (i = 0; i < [ array length ]; i += 1 )
>          {
>                  NSObject *item = [ array objectAtIndex: i ];
>                  [ item doSomething ];
>          }
> }
>

I personally like

[array makeObjectPerformSelector:@selector(doSomething)];





reply via email to

[Prev in Thread] Current Thread [Next in Thread]