foreach, an analogy

Marcio mqmnews123 at sglebs.com
Thu Oct 19 09:22:30 PDT 2006


Gregor Richards wrote:
> The bigger door is 'for'.  'foreach' is nothing but a convenient wrapper 
> around 'for'.  And don't you OOphiles go telling me that your fancy 
> class foo that has iteration /needs/ 'foreach':
>   for (auto bar = foo.begin(); !(bar is null); bar = foo.iterate(bar))
> Is it less pretty than foreach?  Yeah.  That's why foreach exists.  But 
> don't go saying that the reverse foreach is a band-aid patch, because 
> both forms are just convenience wrappers around the far more powerful 
> and useful 'for'.  Your small door is actually the screen door.
> 
>  - Gregor Richards


	Wrapper... pre-defined... ok...

	Then maybe the general mechanism is a way to let the end-user define 
these wrappers, and therefore make your language extensible and be able 
to define even DSLs?

	Isn't that what Nemerle does, inspired by LISP? 
http://nemerle.org/What_is_Nemerle

	Mix that with yield-like iterators, and then you have very expressive 
power. Code that reads well, in a language close to the problem domain.


marcio



More information about the Digitalmars-d-announce mailing list