[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 <relson@osagesoftware.com> 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 portnoy@portnoy.org
PGP fingerprint: A1BF 5A81 03E7 47CE 71E0 3BD4 8DA6 9268 5BB6 4BBE
"Poodle: The other white meat." -- Sherman, Sherman's Lagoon
- Re: PROPOSAL: Objective-C++, (continued)
- Re: PROPOSAL: Objective-C++, Kim Shrier, 2001/11/19
- Re: PROPOSAL: Objective-C++, Philippe C.D. Robert, 2001/11/19
- Re: PROPOSAL: Objective-C++, Björn Gohla, 2001/11/19
- Re: PROPOSAL: Objective-C++, Nicola Pero, 2001/11/19
- Re: PROPOSAL: Objective-C++, David Relson, 2001/11/19
- Re: PROPOSAL: Objective-C++, Erik M. Buck, 2001/11/19
- Re: PROPOSAL: Objective-C++, David Relson, 2001/11/19
- Re: PROPOSAL: Objective-C++, Helge Hess, 2001/11/20
- NSInvocations (was Re: PROPOSAL: Objective-C++), Stephen Brandon, 2001/11/20
- Re: NSInvocations (was Re: PROPOSAL: Objective-C++), Helge Hess, 2001/11/20
- Re: PROPOSAL: Objective-C++,
Stephen Peters <=
- Re: PROPOSAL: Objective-C++, Helge Hess, 2001/11/20
- Re: PROPOSAL: Objective-C++, Stefan Böhringer, 2001/11/20
- Re: PROPOSAL: Objective-C++, Ovidiu Predescu, 2001/11/19
- Re: PROPOSAL: Objective-C++, Björn Gohla, 2001/11/19
- ObjC additions (Was: Re: PROPOSAL: Objective-C++), Stefan Urbanek, 2001/11/19
- Re: ObjC additions (Was: Re: PROPOSAL: Objective-C++), Ovidiu Predescu, 2001/11/19
- Re: ObjC additions (Was: Re: PROPOSAL: Objective-C++), Ziemowit Laski, 2001/11/19
- Re: ObjC additions (Was: Re: PROPOSAL: Objective-C++), Helge Hess, 2001/11/20
- Re: ObjC additions (Was: Re: PROPOSAL: Objective-C++), Björn Gohla, 2001/11/19
- Re: ObjC additions (Was: Re: PROPOSAL: Objective-C++), Bjoern Giesler, 2001/11/20