November 03, 2005 Re: Dynamic array syntax proposal | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | Oskar Linde wrote:
>>But this starts to lose the simplicity of the 'for'.
>
>
> And the 'while' alternative also loses the 'continue' semantics.
>
> So use goto cont; instead of continue:
>
> # { // Begin a new scope block
> # int a=0;
> # int i=10;
> # while (a<10)
> # {
> # ...
> # cont: // continue label # a++; i--;
> # }
> # }
>
> Neat? :)
>
> Of course, the comma operator helps: :)
>
> # {
> # int a = -1;
> # int i = 11;
> # while(a++,i--,a<10)
> # {
> # ...
> # }
> # }
Now come on guys, this was a serious proposal. I'm pretty sure nobody
wants to use gotos anymore. And yes, we should have comma-syntax inside
the for-statement, it's extremely easy to implement now that we already
have the same syntax on another hierarchy level. I hope Walter has time
to comment this issue.
|
November 03, 2005 Array/tuple literals | WAS: Dynamic array syntax proposal | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jari-Matti Mäkelä | Using comma for tupple/array literal operator may bring some problems not just with "for" comma-sequence expressions, but also with function call argument lists. Hum... then again maybe not, as it didn't with comma-sequence expressions.
Anyway, here's an alternative ideia for tupple/array construction, which uses the '~' concatenation operator for that purpose:
auto arr = 1 ~ 2 ~ 3; // arr type is int[3]
(1 ~ 4 ~ 9)[2]; // value: 9
One could also use it for slices instead of the slice operator:
"Whatever"[4~8]; // value: "ever"
slice = 4~7; // slices are now first class entities.
str[slice]; // value: "eve"
I'm not sugesting this syntax, just presenting it, as it has some disadvantages besides it's advantages.
Advantages:
* Short syntax allow to replace the slice operator [ .. ]
* Makes some conceptual sense because '~' is already used as a concatenation operator
Disadvantages:
* Cannot construct literals of arrays of arrays, just arrays of primitives/references.
* Doesn't visually look as clean/meaningful as the ',' comma operator.
One could have a similar syntax with the ',' token, changing some of the advantages and disadvantages. One would unfortunately maintain the first disadvantage, which is why I think something better should tried to be found.
Has this issue been discussed in the past, with any reasonable ideias brought up?
--
Bruno Medeiros - CS/E student
"Certain aspects of D are a pathway to many abilities some consider to be... unnatural."
|
November 03, 2005 Re: Array/tuple literals | WAS: Dynamic array syntax proposal | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruno Medeiros | I' m going to join this tuple discussion too: Has anyone seen the syntax for anonymous structs in comega language? It goes something like this struct{int,float} getTuple(){return new {1,2.5};} ... struct{int,float} x = getTuple(); intPart = x[0]; floaPart = x[1]; |
Copyright © 1999-2021 by the D Language Foundation