digitalmars.D - Am I doing it wrong?
- Emil Madsen (9/9) Oct 03 2010 So I wrote a program, to find prime numbers, just to check out this pure
- Denis Koroskin (4/11) Oct 03 2010 Make your result an "enum" (i.e. compile-time constant) if you really wa...
- Emil Madsen (6/21) Oct 03 2010 Well the result is assigned to an immutable int, shouldn't that be a com...
- Denis Koroskin (2/5) Oct 03 2010 No
- Torarin (8/10) Oct 03 2010 Immutable means that the variable, or the memory it points to, will
- Emil Madsen (8/19) Oct 03 2010 ah ofc! I shoulda know :) - So I were doing it wrong :)
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/27) Oct 03 2010 Thanks for the question; I learned something too. :)
- Emil Madsen (8/41) Oct 03 2010 So I've been told, but havn't been able to find it, so I rechecked, and
- Torarin (3/6) Oct 03 2010 Yes, effectively you are declaring an anonymous enum with one element.
- Emil Madsen (8/14) Oct 03 2010 can the enum be a float? if calcprimes returned a float? - and if so, wi...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (10/14) Oct 03 2010 n
- Simen kjaeraas (9/17) Oct 03 2010 an
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (10/25) Oct 04 2010 e,
- Jonathan M Davis (8/11) Oct 03 2010 auto, enum, immutable, and const all use type inference. So, you can dec...
- Emil Madsen (5/18) Oct 03 2010 --
So I wrote a program, to find prime numbers, just to check out this pure thing; http://gist.github.com/608493 However, the program has a runtime of about 5 seconds? - in my mind, if the function is pure, shouldn't the compiler insure that it was evaluated at compiletime? - or am I doing it wrong? -- // Yours sincerely // Emil 'Skeen' Madsen
Oct 03 2010
On Sun, 03 Oct 2010 14:54:06 +0400, Emil Madsen <sovende gmail.com> wrote:So I wrote a program, to find prime numbers, just to check out this pure thing; http://gist.github.com/608493 However, the program has a runtime of about 5 seconds? - in my mind, if the function is pure, shouldn't the compiler insure that it was evaluated at compiletime? - or am I doing it wrong?Make your result an "enum" (i.e. compile-time constant) if you really want to calculate it in compile-time: enum primes = calcPrimes();
Oct 03 2010
Well the result is assigned to an immutable int, shouldn't that be a compile const too? 2010/10/3 Denis Koroskin <2korden gmail.com>On Sun, 03 Oct 2010 14:54:06 +0400, Emil Madsen <sovende gmail.com> wrote: So I wrote a program, to find prime numbers, just to check out this pure-- // Yours sincerely // Emil 'Skeen' Madsenthing; http://gist.github.com/608493 However, the program has a runtime of about 5 seconds? - in my mind, if the function is pure, shouldn't the compiler insure that it was evaluated at compiletime? - or am I doing it wrong?Make your result an "enum" (i.e. compile-time constant) if you really want to calculate it in compile-time: enum primes = calcPrimes();
Oct 03 2010
On Sun, 03 Oct 2010 15:08:33 +0400, Emil Madsen <sovende gmail.com> wrote:Well the result is assigned to an immutable int, shouldn't that be a compile const too?No
Oct 03 2010
2010/10/3 Emil Madsen <sovende gmail.com>:Well the result is assigned to an immutable int, shouldn't that be a compile const too?Immutable means that the variable, or the memory it points to, will not change. You can still assign run-time values to it: void main(string[] args) { immutable string a = args[0]; writeln(a); }
Oct 03 2010
ah ofc! I shoulda know :) - So I were doing it wrong :) Say I'm doing that enum a = calcPrimes(); then a will be an enum with 1 element, that I can use as an int right? - or is there something special to be aware of? On 3 October 2010 13:20, Torarin <torarind gmail.com> wrote:2010/10/3 Emil Madsen <sovende gmail.com>:-- // Yours sincerely // Emil 'Skeen' MadsenWell the result is assigned to an immutable int, shouldn't that be acompileconst too?Immutable means that the variable, or the memory it points to, will not change. You can still assign run-time values to it: void main(string[] args) { immutable string a = args[0]; writeln(a); }
Oct 03 2010
Emil Madsen wrote:ah ofc! I shoulda know :) - So I were doing it wrong :)Thanks for the question; I learned something too. :) But in case you don't already know, there is also the D.learn newsgroup. This question might be more useful there. AliSay I'm doing that enum a = calcPrimes(); then a will be an enum with 1 element, that I can use as an int right? - or is there something special to be aware of? On 3 October 2010 13:20, Torarin <torarind gmail.com> wrote:2010/10/3 Emil Madsen <sovende gmail.com>:Well the result is assigned to an immutable int, shouldn't that be acompileconst too?Immutable means that the variable, or the memory it points to, will not change. You can still assign run-time values to it: void main(string[] args) { immutable string a = args[0]; writeln(a); }
Oct 03 2010
So I've been told, but havn't been able to find it, so I rechecked, and there it was, apperently I'm getting blind >.< I'll make sure not to pollute this mailing list with these questions again then :) - Thanks once again On 3 October 2010 23:28, Ali =C7ehreli <acehreli yahoo.com> wrote:Emil Madsen wrote:--=20 // Yours sincerely // Emil 'Skeen' Madsenah ofc! I shoulda know :) - So I were doing it wrong :)Thanks for the question; I learned something too. :) But in case you don't already know, there is also the D.learn newsgroup. This question might be more useful there. Ali Say I'm doing that enum a =3D calcPrimes();then a will be an enum with 1 element, that I can use as an int right? - or is there something special to be aware of? On 3 October 2010 13:20, Torarin <torarind gmail.com> wrote: 2010/10/3 Emil Madsen <sovende gmail.com>:Well the result is assigned to an immutable int, shouldn't that be acompileconst too?Immutable means that the variable, or the memory it points to, will not change. You can still assign run-time values to it: void main(string[] args) { immutable string a =3D args[0]; writeln(a); }
Oct 03 2010
2010/10/3 Emil Madsen <sovende gmail.com>:ah ofc! I shoulda know :) - So I were doing it wrong :) Say I'm doing that enum a = calcPrimes(); then a will be an enum with 1 element, that I can use as an int right?Yes, effectively you are declaring an anonymous enum with one element. By default an int.
Oct 03 2010
can the enum be a float? if calcprimes returned a float? - and if so, will the enum be a float or an int? (will it be casted, or will it work as an auto type?) thanks btw :) On 3 October 2010 13:28, Torarin <torarind gmail.com> wrote:2010/10/3 Emil Madsen <sovende gmail.com>:-- // Yours sincerely // Emil 'Skeen' Madsenah ofc! I shoulda know :) - So I were doing it wrong :) Say I'm doing that enum a = calcPrimes(); then a will be an enum with 1 element, that I can use as an int right?Yes, effectively you are declaring an anonymous enum with one element. By default an int.
Oct 03 2010
Emil Madsen wrote:can the enum be a float? if calcprimes returned a float? - and if so, w=illthe enum be a float or an int? (will it be casted, or will it work as a=nauto type?) =20Yes, basically "enum" is a synonym for "compile-time const auto" (although the "auto" part can be replaced by an explicit type). Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Oct 03 2010
J=C3=A9r=C3=B4me M. Berger <jeberger free.fr> wrote:Emil Madsen wrote:=can the enum be a float? if calcprimes returned a float? - and if so,=anwill the enum be a float or an int? (will it be casted, or will it work as=Or, you know, just "compile-time const", as the lack of a specified type= , and const being a storage class, allows for type inference. Auto is not necessary. -- = Simenauto type?)Yes, basically "enum" is a synonym for "compile-time const auto" (although the "auto" part can be replaced by an explicit type).
Oct 03 2010
Simen kjaeraas wrote:J=C3=A9r=C3=B4me M. Berger <jeberger free.fr> wrote: =20Emil Madsen wrote:can the enum be a float? if calcprimes returned a float? - and if so,=anwill the enum be a float or an int? (will it be casted, or will it work as=e,=20 Or, you know, just "compile-time const", as the lack of a specified typ=auto type?)Yes, basically "enum" is a synonym for "compile-time const auto" (although the "auto" part can be replaced by an explicit type).and const being a storage class, allows for type inference. Auto is not=necessary. =20I know, but since the question was "can the enum be a float?", I felt it necessary to put the redundant "auto" in my explanation. Jerome --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Oct 04 2010
On Sunday 03 October 2010 04:34:31 Emil Madsen wrote:can the enum be a float? if calcprimes returned a float? - and if so, will the enum be a float or an int? (will it be casted, or will it work as an auto type?)auto, enum, immutable, and const all use type inference. So, you can declare auto a = 7; enum b = 7.7; immutable c = "hello"; const d = false; enum, however, is the only one which is a compile-time constant. - Jonathan M Davis
Oct 03 2010
perfect :), thanks :) On 3 October 2010 13:39, Jonathan M Davis <jmdavisProg gmx.com> wrote:On Sunday 03 October 2010 04:34:31 Emil Madsen wrote:-- // Yours sincerely // Emil 'Skeen' Madsencan the enum be a float? if calcprimes returned a float? - and if so,willthe enum be a float or an int? (will it be casted, or will it work as an auto type?)auto, enum, immutable, and const all use type inference. So, you can declare auto a = 7; enum b = 7.7; immutable c = "hello"; const d = false; enum, however, is the only one which is a compile-time constant. - Jonathan M Davis
Oct 03 2010