July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Reply to Walter,
> Kirk McDonald wrote:
>
>> In the spec for the new ForeachRangeStatement, it says:
>>
>> "If Foreach is foreach, then the variable is set to LwrExpression,
>> then incremented at the end of each iteration."
>>
>> What does "incremented" mean, exactly? If have a class or struct that
>> defines opAddAssign, would it call foo.opAddAssign(1) (as ++foo
>> does)? Similarly, would the foreach_reverse form call
>> foo.opSubAssign(1)?
>>
> Right now, it doesn't work with structs/classes, but when it does,
> it'll be as you wrote.
>
what will this do
foreach(float f; 1 .. toBigFor1ToIncrement)
loop forever?
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> what will this do
>
> foreach(float f; 1 .. toBigFor1ToIncrement)
>
> loop forever?
The same thing as:
for (float f = 1; f < toBigFor1ToIncrement; f++)
What foreach ranges buy you is:
1) The type of the loop index is automatically inferred
2) The termination condition is evaluated only once
While these may seem trivial, they are often a source of bugs.
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Don Clugston wrote:
>> I'm having trouble understanding the difference between "isScalar", "isArithmetic", and "isIntegral". Is this table correct?
>>
>> int uint real wchar
>> Y Y Y N isArithmetic
>> N N Y N isFloating
>> Y Y N Y isIntegral
>> Y Y Y Y isScalar
>> N Y N N isUnsigned
>>
>> ----------------
>
> wchar is arithmetic and unsigned.
OK. Then is there any difference between scalar and arithmetic ?
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | Don Clugston wrote:
> Walter Bright wrote:
>> Don Clugston wrote:
>>> I'm having trouble understanding the difference between "isScalar", "isArithmetic", and "isIntegral". Is this table correct?
>>>
>>> int uint real wchar
>>> Y Y Y N isArithmetic
>>> N N Y N isFloating
>>> Y Y N Y isIntegral
>>> Y Y Y Y isScalar
>>> N Y N N isUnsigned
>>>
>>> ----------------
>>
>> wchar is arithmetic and unsigned.
>
> OK. Then is there any difference between scalar and arithmetic ?
I haven't checked DMDs handling of this, but if I understand the terms correctly then the difference should be in the handling of complex types (cfloat & friends) which should be arithmetic types but not scalar ones.
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound1@digitalmars.com> wrote in message news:f82mav$2t9v$4@digitalmars.com... > Craig Black wrote: >> Very nice Walter! Question about traits. I'm guessing allMembers returns both functions and fields? Is there an isField or isFunction to differentiate? > > You can look at the types to see if they are data or functions. But probably more traits need to be added - I thought I'd wait on that to see just what was required, rather than throw in a lot of useless geegaws. It's hard to predict in advance. If you had class A { void function() f; void delegate() g; void foo() {} } What would be f's type, g's type, and foo's type? |
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston | Don Clugston wrote:
> Walter Bright wrote:
>> Don Clugston wrote:
>>> I'm having trouble understanding the difference between "isScalar", "isArithmetic", and "isIntegral". Is this table correct?
>>>
>>> int uint real wchar
>>> Y Y Y N isArithmetic
>>> N N Y N isFloating
>>> Y Y N Y isIntegral
>>> Y Y Y Y isScalar
>>> N Y N N isUnsigned
>>>
>>> ----------------
>>
>> wchar is arithmetic and unsigned.
>
> OK. Then is there any difference between scalar and arithmetic ?
scalar includes pointers.
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> If you had
>
> class A
> {
> void function() f;
> void delegate() g;
> void foo() {}
> }
>
> What would be f's type, g's type, and foo's type?
f: pointer to function returning void
g: delegate returning void
foo: function returning void
|
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright escribió: > > http://www.digitalmars.com/d/1.0/changelog.html > http://ftp.digitalmars.com/dmd.1.019.zip > > http://www.digitalmars.com/d/changelog.html > http://ftp.digitalmars.com/dmd.2.003.zip How can we check specific overloads with __traits? For example, class A { abstract void foo(); int foo(int i) { return i; } } void main () { auto isvirtual = __traits(isAbstractFunction, A.foo); // what is it? } BTW, the documentation for __traits has isVirtualFunction in the example for isAbstractFunction. -- Carlos Santander Bernal |
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Mon, 23 Jul 2007 09:45:57 -0700, Walter Bright wrote: > Don Clugston wrote: >> I'm having trouble understanding the difference between "isScalar", "isArithmetic", and "isIntegral". Is this table correct? >> >> int uint real wchar >> Y Y Y N isArithmetic >> N N Y N isFloating >> Y Y N Y isIntegral >> Y Y Y Y isScalar >> N Y N N isUnsigned >> >> ---------------- > > wchar is arithmetic and unsigned. Are you serious??? Why are we allowed to do mathematics with characters? dchar r = power( 'a' * 'b' + 'd' * '€') / '$'; Doesn't make sense so why is wchar arithmetic? If you insist in this wart, then we also need an 'isCharacter' trait to distinguish characters from numbers. -- Derek Parnell Melbourne, Australia skype: derek.j.parnell |
July 23, 2007 Re: DMD 1.019 and 2.003 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Mon, 23 Jul 2007 12:22:32 -0700, Walter Bright wrote: > Don Clugston wrote: >> Walter Bright wrote: >>> Don Clugston wrote: >>>> I'm having trouble understanding the difference between "isScalar", "isArithmetic", and "isIntegral". Is this table correct? >>>> >>>> int uint real wchar >>>> Y Y Y N isArithmetic >>>> N N Y N isFloating >>>> Y Y N Y isIntegral >>>> Y Y Y Y isScalar >>>> N Y N N isUnsigned >>>> >>>> ---------------- >>> >>> wchar is arithmetic and unsigned. >> >> OK. Then is there any difference between scalar and arithmetic ? > > scalar includes pointers. And yet one can do (some) arithmetic on pointers ... !? import std.stdio; void main() { int i; int* p; p = &i; p += 2; writefln("%s %s", &i, p); } -- Derek Parnell Melbourne, Australia skype: derek.j.parnell |
Copyright © 1999-2021 by the D Language Foundation