foreach, an analogy

Brad Anderson brad at dsource.org
Mon Oct 23 07:58:27 PDT 2006


Andrey Khropov wrote:
> Brad Anderson wrote:
> 
>> I would guess that Walter has forgotten more about language architectures and
>> compiler design than you two ever knew combined.  foreach_reverse is not a
>> large enough issue to question Walter's abilities.
> 
> My intention was not to offend him personally, but some design decisions seem
> to be really strange.

ok.  I just wanted to make sure you understood some of the decisions are based
on Walter's vast experience.

> There're foreach analogs in Java 1.5, C#, Python, Ruby etc.
> but none of these languages have foreach_reverse. 
> Why do you think?
> 
> I think because reverse it's not so common operation and should better be
> accomplished in such a way (more generic):
> 
> ---------------
>   foreach(i;array.reverseIter)
> --------------
> 
> IMHO, it's more flexible.

And it's been stated in this thread that foreach could be replaced with a more
generic 'for', and shouldn't exist at all.  It depends on how far back you
want to go to be "pure."  Some sugar exists, and this is one that Walter seems
to want to keep around based on his comments.

> 
>> If you've listened closely, and I don't think you have, he has said repeatedly
>> that he sees enough utility (its use w/ arrays) that it's staying.  Give it a
>> few releases and hopefully this woeful abomination of sugar won't affect you
>> too much.
> 
> I think language should be consistent. 
> Shouldn't contain unnecessary built-in hacks.
>  Why not foreach_inorder, foreach_preorder, foreach_postorder,
>  	foreach_depthfirst, foreach_breadthfirst?
> 
> Want syntactic sugar for common operations?
> Allow syntax extensions such as in Nemerle:
> http://nemerle.org/Syntax_extensions

I see your point here, and thanks for the link.  I think these Nemerle
extensions might be as far as D can go.  While I would love to see Lisp-like
macros, D isn't the language for it, based on its non-sexp syntax.

BA



More information about the Digitalmars-d-announce mailing list