View mode: basic / threaded / horizontal-split · Log in · Help
April 28, 2008
Re: How about assert?
On Mon, 28 Apr 2008 16:29:11 +0400, downs <default_357-line@yahoo.de>  
wrote:

> Note that if we had trailing delegate syntax, combined with a  
> break/continue convention like we currently have with opApply, as well  
> as return forwarding, foreach wouldn't be necessary and could be moved  
> to a library function :)
>
> The result would look something like: foreach([2, 3, 4, 5]) (int x) {  
> writefln(x); }
>
> Probably too big a change though, sadly.
>
> Also, let's really move assert into an object.d function. There's _no_  
> reason this should be a keyword.
>
>  --downs

Remove assert and you loose static assert, too.
Unless, you introduce static_assert keyword :)
April 28, 2008
Re: How about assert?
Koroskin Denis wrote:
> On Mon, 28 Apr 2008 16:29:11 +0400, downs <default_357-line@yahoo.de>
> wrote:
> 
>> Note that if we had trailing delegate syntax, combined with a
>> break/continue convention like we currently have with opApply, as well
>> as return forwarding, foreach wouldn't be necessary and could be moved
>> to a library function :)
>>
>> The result would look something like: foreach([2, 3, 4, 5]) (int x) {
>> writefln(x); }
>>
>> Probably too big a change though, sadly.
>>
>> Also, let's really move assert into an object.d function. There's _no_
>> reason this should be a keyword.
>>
>>  --downs
> 
> Remove assert and you loose static assert, too.
> Unless, you introduce static_assert keyword :)

This is easy to solve in concept, although possibly hard in actual implementation.

Implement CTFE exceptions :)
May 06, 2008
Re: Do we need "foreach"?
"Robert Fraser" <fraserofthenight@gmail.com> wrote in message 
news:fv48l1$670$4@digitalmars.com...
>
> Java's solution is to use a colon in place of the semicolon.
>
> for(x : y)

I rather like C#'s "x in y". It's more obvious than either the difference 
between two or three semicolons, or the difference between semicolon and 
normal colon. Of course, C# still uses it like "foreach(x in y)" instead of 
"for(x in y)". But in any language, I do think I'd prefer the dichotomy of 
"for(;;)" and "for(x in y)", as opposed to pretty much any other syntax. 
Especially for reverse iteration - "foreach_reverse" is incredibly long. So 
"for_reverse" would be an improvement. But in D's case, I don't know if 
using "in" in this manner could cause parsing trouble since "in" already has 
another meaning.

Assuming it's reasonably possible, I would vote for adding something like 
"for(x in y)" or "for(x from y)" or "for(x of y)", etc., as either a 
replacement or an alternative for "foreach(;)".

Speaking of "in", (and getting a bit off topic, sorry), I might as well put 
it out there that I vastly prefer C#'s behavior of requiring attributes like 
"ref" and "out" to be explicitly specified when calling a function:

void Foo(out int someVal) { someVal = 5; }

int bar;
Foo(out bar); // OK
Foo(bar); // Error, caller MUST show that they KNOW that bar may change
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home