discuss-gnustep
[Top][All Lists]
Advanced

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

Re: PROPOSAL: Objective-C++


From: Stephen Peters
Subject: Re: PROPOSAL: Objective-C++
Date: 19 Nov 2001 21:53:39 -0500
User-agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.7

David Relson <address@hidden> writes:

> At 12:06 AM 11/19/01, you wrote:

> [...] 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:
> 
> [ standard for loop deleted ]

(Actually, the easy way with the current NSArray would be to do   
        [ array makeObjectsPerformSelector: @selector(doSomething) ];
) 

As long as we're discussing this, I should point out that there is a
way to do this without modifying GNU's current Objective-C syntax,
utilizing some of Marcel Weiher's Higher Order Messaging (HOM)
concepts.  With this design, the collection classes implement a -do
method to fetch an iterator, which can then use invocation forwarding
to send the same message to all objects:

- (void) arrayDo: (NSArray *) array
{
        [ [ array do ] doSomething ];
}

Some more information from one of Marcel's posts to c.l.objective-.c
is below.  If intrigued, you might find it interesting to wander
through Marcel's other posts to that thread, since it mostly ends up
being a comparison of blocks and HOM.

http://groups.google.com/groups?q=g:thl2088540758d&selm=8m5v2e%24l70%241%40news.cs.tu-berlin.de

I understand Marcel has also been shopping the idea around the
Smalltalk forums with some success as well, since the idea has merit
there as well.

-- 
Stephen L. Peters                                  address@hidden
  PGP fingerprint: A1BF 5A81 03E7 47CE 71E0  3BD4 8DA6 9268 5BB6 4BBE
     "Poodle: The other white meat." -- Sherman, Sherman's Lagoon



reply via email to

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