April 01, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Wed, 01 Apr 2009 20:54:12 +0200, Trass3r <mrmocool@gmx.de> wrote:
>template Sequence(size_t count, size_t index = 0)
>{
> static if (index < count)
> alias Tuple!(index, Sequence!(count, index + 1)) Sequence;
>}
There was ellipsis to suggest that you should terminate the recursion properly :) Sorry
template Sequence(size_t count, size_t index = 0)
{
static if (index < count)
alias Tuple!(index, Sequence!(count, index + 1)) Sequence;
else
alias Tuple!() Sequence;
}
| |||
April 01, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Max Samukha | Max Samukha schrieb:
> On Wed, 01 Apr 2009 20:54:12 +0200, Trass3r <mrmocool@gmx.de> wrote:
>
>> template Sequence(size_t count, size_t index = 0)
>> {
>> static if (index < count)
>> alias Tuple!(index, Sequence!(count, index + 1)) Sequence;
>> }
>
> There was ellipsis to suggest that you should terminate the recursion
> properly :) Sorry
>
> template Sequence(size_t count, size_t index = 0)
> {
> static if (index < count)
> alias Tuple!(index, Sequence!(count, index + 1)) Sequence;
> else
> alias Tuple!() Sequence;
> }
OMG, I knew the recursion base case was missing, but I couldn't imagine how to represent "nothing". Of course, an empty tuple.
But the reason I posted is cause that bug(?) is still present.
dmd doesn't crash anymore, but using const still doesn't work.
| |||
April 01, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r <mrmocool@gmx.de> wrote:
>
>OMG, I knew the recursion base case was missing, but I couldn't imagine how to represent "nothing". Of course, an empty tuple.
>
>But the reason I posted is cause that bug(?) is still present. dmd doesn't crash anymore, but using const still doesn't work.
I think it's not a bug because "const" storage class doesn't always mean "compile time". It's rather a variable (we should find a better name) which is initialized once and cannot be changed later. To ensure compiletimeness, you can declare the variable as "static const", "static invariant" or "enum"
| |||
April 01, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Max Samukha | Max Samukha schrieb:
> On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r <mrmocool@gmx.de> wrote:
>
>> OMG, I knew the recursion base case was missing, but I couldn't imagine how to represent "nothing". Of course, an empty tuple.
>>
>> But the reason I posted is cause that bug(?) is still present.
>> dmd doesn't crash anymore, but using const still doesn't work.
>
> I think it's not a bug because "const" storage class doesn't always
> mean "compile time". It's rather a variable (we should find a better
> name) which is initialized once and cannot be changed later. To ensure
> compiletimeness, you can declare the variable as "static const",
> "static invariant" or "enum"
Man, static is one of the things that are totally confusing. It has various meanings depending on where you use it and moreover it's hard to find documentation about the one you need cause it's spread all over the docs.
But what you are talking about is in fact what "final" does (once initialized it can't be changed).
| |||
April 02, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | I came across another strange bug(?):
Using const, static const or auto instead of enum makes it work.
Using the foreach way also works with enum.
void main()
{
enum members = ["foo", "bar"];
for (uint i=0; i<members.length; i++)
// foreach (i; Sequence!(members.length))
{
writefln(members[i]);
}
}
But enum with for yields:
object.Error: Access Violation
std.encoding.EncodingSchemeASCII à‘B ANSI_X3.4-1968 ’B ANSI_X3.4-1986 (’B ASCII @’B IBM367 P’B ISO646-US `’B ISO_646.irv:1991 x’B US-ASCII ˜’B cp367 °’B csASCIIiso-ir-6 À’B us Ø’B ? è’B €“B std.encoding.EncodingSchemeASCII TB ø’B “B €“B ”B 0“B GA ƒ@ ƒ@ pƒ@ tFA GA $GA 4GA LGA œGA ìGA ÔHA IA `IA KA 8KA dKA encoding.1270 pOB
È“B ”B ”B øGA pkB 0“B Unable to create class ”B Unrecognized Encoding: @”B à”B std.encoding.EncodingScheme TB `”B h”B à”B 0QB ”B ÔHA IA `IA KA 8KA dKA ЕB std.encoding.UnrecognizedEncodingException TB $ 0•B * T•B ЕB @–B €•B €ƒ@ ƒ@ ƒ@ pƒ@ –B std.encoding.EncodingException TB $ ð•B –B –B ðYB @–B €ƒ@ ƒ@ ƒ@ pƒ@ P—B core.exception.UnicodeException TB ( °–B Ø–B P—B ðYB —B €ƒ@ ƒ@ ƒ@ pƒ@ No appropriate switch clause found " p—B 0˜B core.exception.SwitchError TB $ —B Ä—B 0˜B pSB à—B €ƒ@ ƒ@ ƒ@ pƒ@ Hidden method called for P˜B ™B core.exception.HiddenFuncError TB $ €˜B ¤˜B ™B pSB ИB €ƒ@ ƒ@ ƒ@ pƒ@ Finalization error @™B An exception was thrown while finalizing an instance of class > `™B PšB core.exception.FinalizeError TB ( °™B Ø™B PšB pSB šB LA ƒ@ ƒ@ pƒ@ @qB std.dateparse pOB
€šB ÈšB КB
ðWB @qB À©B unrecognized attribute äšB redundant attribute ›B unmatched ')'
(›B q @›B P›B printProgram()
10: REchar '
| |||
April 02, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r |
Trass3r wrote:
> I came across another strange bug(?):
> Using const, static const or auto instead of enum makes it work.
> Using the foreach way also works with enum.
>
> void main()
> {
> enum members = ["foo", "bar"];
> for (uint i=0; i<members.length; i++)
> // foreach (i; Sequence!(members.length))
> {
> writefln(members[i]);
> }
> }
>
> But enum with for yields:
>
> ...
Wow, I think you just made the executable puke its guts! :S
-- Daniel
| |||
April 02, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | Trass3r wrote:
> I came across another strange bug(?):
> Using const, static const or auto instead of enum makes it work.
> Using the foreach way also works with enum.
>
> void main()
> {
> enum members = ["foo", "bar"];
> for (uint i=0; i<members.length; i++)
> // foreach (i; Sequence!(members.length))
> {
> writefln(members[i]);
> }
> }
>
> But enum with for yields:
>
> object.Error: Access Violation
> std.encoding.EncodingSchemeASCII à‘B ANSI_X3.4-1968 ’B
...
Confirmed. Congratulations, you've discovered the Bug of the Year!
| |||
April 02, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Thu, 02 Apr 2009 00:07:56 +0200, Trass3r <mrmocool@gmx.de> wrote: >Max Samukha schrieb: >> On Wed, 01 Apr 2009 23:22:40 +0200, Trass3r <mrmocool@gmx.de> wrote: >> >>> OMG, I knew the recursion base case was missing, but I couldn't imagine how to represent "nothing". Of course, an empty tuple. >>> >>> But the reason I posted is cause that bug(?) is still present. dmd doesn't crash anymore, but using const still doesn't work. >> >> I think it's not a bug because "const" storage class doesn't always mean "compile time". It's rather a variable (we should find a better name) which is initialized once and cannot be changed later. To ensure compiletimeness, you can declare the variable as "static const", "static invariant" or "enum" > >Man, static is one of the things that are totally confusing. It has various meanings depending on where you use it and moreover it's hard to find documentation about the one you need cause it's spread all over the docs. Agree, there are too many meanings of 'static' - global, compile-time, fixed-size, non-instance. The good thing is that these meanings are interrelated. Probably, 'static' in module constructor definitions is redundant. On the other hand, module constructors are not many and could be otherwise easily confused with class instance constructors. > >But what you are talking about is in fact what "final" does (once initialized it can't be changed). There is no 'final' storage class in D2. Or you are talking about the concept? | |||
April 03, 2009 Re: Shouldn't __traits return Tuples? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Trass3r | On Thu, 02 Apr 2009 03:56:35 +0200, Trass3r <mrmocool@gmx.de> wrote: >I came across another strange bug(?): >Using const, static const or auto instead of enum makes it work. >Using the foreach way also works with enum. > >void main() >{ > enum members = ["foo", "bar"]; > for (uint i=0; i<members.length; i++) >// foreach (i; Sequence!(members.length)) > { > writefln(members[i]); > } >} > >But enum with for yields: > >object.Error: Access Violation >std.encoding.EncodingSchemeASCII à‘B ANSI_X3.4-1968 ’B >ANSI_X3.4-1986 (’B ASCII @’B IBM367 P’B ISO646-US Logged as http://d.puremagic.com/issues/show_bug.cgi?id=2792 Gide | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply