Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread rikki cattermole via Digitalmars-d-learn
On 30/08/2022 8:16 AM, Gavin Ray wrote: It must have been the "writing at end of file" bit? I don't know. It read like it should work. The offsets were correct, it just didn't work *shrug*.

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread Gavin Ray via Digitalmars-d-learn
On Monday, 29 August 2022 at 15:52:31 UTC, rikki cattermole wrote: After a bunch of playing around I managed to determine that it is as simple as the mode. exists(dbFileName) ? "r+" : "w+" Will fix it. Of course you shouldn't delete the file like that method is doing. It should probably re

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 29 August 2022 at 16:21:53 UTC, ag0aep6g wrote: You never change `pageId`. So as far as I can tell, you're always `seek`-ing to the same position, and you just overwrite the same piece of the file again and again. Whoops. I guess I missed the point of the question there.

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread ag0aep6g via Digitalmars-d-learn
On Sunday, 28 August 2022 at 22:46:17 UTC, Gavin Ray wrote: I've put the code, stripped to a minimal example here: - https://ldc.godbolt.org/z/fzsx3Tnnn [...] But if the same code is placed inside of a `for` loop, suddenly no writes occur: [...] Does anyone know what is happening

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread rikki cattermole via Digitalmars-d-learn
After a bunch of playing around I managed to determine that it is as simple as the mode. exists(dbFileName) ? "r+" : "w+" Will fix it. Of course you shouldn't delete the file like that method is doing. It should probably reinitialize the FILE* descriptor.

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread Gavin Ray via Digitalmars-d-learn
On Monday, 29 August 2022 at 07:04:49 UTC, bauss wrote: Does anyone know what is happening here? It's really puzzling. You probably need to flush the output. That's a good idea. I gave it a shot, and the following doesn't seem to change anything unfortunately: ```d void writePage(PageId pa

Re: Disk write in a "for" loop with RwMutex never happens

2022-08-29 Thread bauss via Digitalmars-d-learn
3, 4] ``` Where here, `pageData` is the data to be written to a file, and `readData` is the result of trying to read the freshly written file data. But if the same code is placed inside of a `for` loop, suddenly no writes occur: ```d pageData[0..4] = [0, 0, 0, 0] readData[0..4] = [0, 0,

Disk write in a "for" loop with RwMutex never happens

2022-08-28 Thread Gavin Ray via Digitalmars-d-learn
to a file, and `readData` is the result of trying to read the freshly written file data. But if the same code is placed inside of a `for` loop, suddenly no writes occur: ```d pageData[0..4] = [0, 0, 0, 0] readData[0..4] = [0, 0, 0, 0] pageData[0..4] = [0, 0, 0, 1] readData[0..4] = [0, 0,

Re: Printing Tuple!(...)[] using for loop?

2021-07-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/2/21 12:21 AM, Kirill wrote: I have a `Tuple!(string, ..., string)[] data` that I would like to print out: `a   b   c` `1   2   3` `4   5   6`     Furthermore, I want to be able to print any N rows and M columns of that table. For instance:     `b   c`     `2   3`     or

Re: Printing Tuple!(...)[] using for loop?

2021-07-02 Thread Bastiaan Veelo via Digitalmars-d-learn
On Friday, 2 July 2021 at 04:21:24 UTC, Kirill wrote: I have a `Tuple!(string, ..., string)[] data` If there are only strings in the tuple, it could be simplified by making it a static array of strings instead. The compile-time index issue would go away. —Bastiaan

Re: Printing Tuple!(...)[] using for loop?

2021-07-02 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Friday, 2 July 2021 at 04:21:24 UTC, Kirill wrote: ... 1. use static foreach for tuple loop. 2. start column and end column should be known at compile time. Either make them immutable, or as enum constant, or pass them as an template argument. Tuple is basically a wrapper over built in t

Printing Tuple!(...)[] using for loop?

2021-07-01 Thread Kirill via Digitalmars-d-learn
I have a `Tuple!(string, ..., string)[] data` that I would like to print out: `a b c` `1 2 3` `4 5 6` Furthermore, I want to be able to print any N rows and M columns of that table. For instance: `b c` `2 3` or `1 2 3` `4 5 6`

Re: preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:48:17 UTC, mipri wrote: On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error

Re: preset counter variable in a for loop

2020-02-28 Thread mipri via Digitalmars-d-learn
On Friday, 28 February 2020 at 12:44:52 UTC, Namal wrote: Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Well, that's the error. b has no effect

preset counter variable in a for loop

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++) std::cout<

Re: preset counter variable in a for loop --> 'has no effect' Error

2020-02-28 Thread drug via Digitalmars-d-learn
nt i = 0;  for(i; i<3; i++)    std::cout< D compiler is smart enough to say that the first use of `b` in for loop is useless. Use either this variant: ``` import std.stdio; void main(){ int b = 0; for (; b<3; b++){ writeln(b); } } ``` or this: ``` import std.stdio; void main()

preset counter variable in a for loop --> 'has no effect' Error

2020-02-28 Thread Namal via Digitalmars-d-learn
Hello, I don't understand why this simple code causes a compiler error.. import std.stdio; void main(){ int b = 0; for (b; b<3; b++){ writeln(b); } } $Error: b has no effect Same works perfectly fine in C++ #include int main(){ int i = 0; for(i; i<3; i++) std::cout<

Re: For loop with separator

2019-07-06 Thread a11e99z via Digitalmars-d-learn
On Saturday, 6 July 2019 at 11:48:42 UTC, berni wrote: On Thursday, 4 July 2019 at 17:00:33 UTC, Q. Schroll wrote: The prime example is printing the comma when printing a list: There is one between any two elements, but neither is one at front or behind the last one. If it is just for printin

Re: For loop with separator

2019-07-06 Thread berni via Digitalmars-d-learn
On Thursday, 4 July 2019 at 17:00:33 UTC, Q. Schroll wrote: The prime example is printing the comma when printing a list: There is one between any two elements, but neither is one at front or behind the last one. If it is just for printing commas in between, you can use range.join(", ") htt

Re: For loop with separator

2019-07-04 Thread Alex via Digitalmars-d-learn
On Thursday, 4 July 2019 at 17:00:33 UTC, Q. Schroll wrote: Probably you've come over this problem once in a while, too. You have a repeating solution, so you use a for(each) loop. Sometimes, there is an action to be performed between the end of one iteration and the beginning of the next, if th

For loop with separator

2019-07-04 Thread Q. Schroll via Digitalmars-d-learn
Probably you've come over this problem once in a while, too. You have a repeating solution, so you use a for(each) loop. Sometimes, there is an action to be performed between the end of one iteration and the beginning of the next, if there is one. The prime example is printing the comma when pri

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread Daniel Kozák via Digitalmars-d-learn
On Thursday, 23 May 2019 at 18:37:17 UTC, H. S. Teoh wrote: On Thu, May 23, 2019 at 06:20:23PM +, kdevel via Digitalmars-d-learn wrote: On Thursday, 23 May 2019 at 09:44:15 UTC, Cym13 wrote: [...] > To go fast, read/write bigger chunks. Or use rawWrite instead of write (reduces the runtim

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, May 23, 2019 at 11:06 PM Daniel Kozak wrote: > On Thu, May 23, 2019 at 11:10 AM BoQsc via Digitalmars-d-learn < > digitalmars-d-learn@puremagic.com> wrote: > > https://matthias-endler.de/2017/yes/ > So this should do it void main() { import std.range : array, cycle, take; impor

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, May 23, 2019 at 11:19 PM Daniel Kozak wrote: Fixed version without decode to dchar void main() { import std.range : array, cycle, take; import std.stdio; import std.utf; immutable buf_size = 8192; immutable buf = "\x00".byCodeUnit.cycle.take(buf_size).array; auto

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, May 23, 2019 at 11:10 AM BoQsc via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > This code of D creates a dummy 47,6 MB text file filled with Nul > characters in about 9 seconds > > import std.stdio, std.process; > > void main() { > > writeln("Creating a dummy f

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 23, 2019 at 06:20:23PM +, kdevel via Digitalmars-d-learn wrote: > On Thursday, 23 May 2019 at 09:44:15 UTC, Cym13 wrote: [...] > > To go fast, read/write bigger chunks. > > Or use rawWrite instead of write (reduces the runtime to about 1.6 s). > When using write time is IMHO spent

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread kdevel via Digitalmars-d-learn
On Thursday, 23 May 2019 at 09:44:15 UTC, Cym13 wrote: [...] Note in particular the blocksize argument. I set it to 1M but by default it's 512 bytes. If you use strace with the command above you'll see a series of write() calls, each writting 1M of null bytes to testfile. That's the main diff

Re: Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread Cym13 via Digitalmars-d-learn
On Thursday, 23 May 2019 at 09:09:05 UTC, BoQsc wrote: This code of D creates a dummy 47,6 MB text file filled with Nul characters in about 9 seconds import std.stdio, std.process; void main() { writeln("Creating a dummy file"); File file = File("test.txt", "w"); for (int

Why GNU coreutils/dd is creating a dummy file more efficiently than D's For loop?

2019-05-23 Thread BoQsc via Digitalmars-d-learn
This code of D creates a dummy 47,6 MB text file filled with Nul characters in about 9 seconds import std.stdio, std.process; void main() { writeln("Creating a dummy file"); File file = File("test.txt", "w"); for (int i = 0; i < 5000; i++) { file

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread Meta via Digitalmars-d-learn
On Thursday, 8 September 2016 at 12:36:29 UTC, drug wrote: &c is address of the variable c, that is allocated on the stack and has the same address on every iteration cast(void*)c return the value of variable c that is address of a class instance and is different for every iteration in other w

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread drug via Digitalmars-d-learn
08.09.2016 15:24, lobo пишет: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread lobo via Digitalmars-d-learn
On Thursday, 8 September 2016 at 12:36:29 UTC, drug wrote: 08.09.2016 15:24, lobo пишет: [...] &c is address of the variable c, that is allocated on the stack and has the same address on every iteration cast(void*)c return the value of variable c that is address of a class instance and is diff

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread lobo via Digitalmars-d-learn
On Thursday, 8 September 2016 at 12:28:55 UTC, Meta wrote: On Thursday, 8 September 2016 at 12:24:48 UTC, lobo wrote: [...] I don't have time to explain at the moment, but change the `&c` to `cast(void*)c` and you will see what you expect. I will post an explanation soon. Thanks for the bl

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread rikki cattermole via Digitalmars-d-learn
On 09/09/2016 12:24 AM, lobo wrote: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { i

Re: Classes new'd inside for loop are all the same instance?

2016-09-08 Thread Meta via Digitalmars-d-learn
On Thursday, 8 September 2016 at 12:24:48 UTC, lobo wrote: I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {}

Classes new'd inside for loop are all the same instance?

2016-09-08 Thread lobo via Digitalmars-d-learn
I am confused, which is normal, but I'd appreciate some help :-) If I create N classes in a for loop they are all the same instance. I would expect each to be a unique instance of the class. See the code below --- class C {} void main() { import std.stdio; auto c1 =

Re: Regex match in for loop

2014-07-15 Thread Brad Anderson via Digitalmars-d-learn
, "g"); for(short i = 0; i < greetings.count(); i++) { auto m = match(greetings[i], r); } } To the best of my knowledge, declaring a variable inside a for loop is illegal, you can not delacre the same variable repeatedly over the iterations. There is nothing wrong with declaring a

Re: Regex match in for loop

2014-07-15 Thread H. S. Teoh via Digitalmars-d-learn
"salut"]; > > regex r = regex("hello", "g"); > > for(short i = 0; i < greetings.count(); i++) > { > > auto m = match(greetings[i], r); > } > > } > > To the best of my knowledge, declaring a variable inside a for loop is >

Regex match in for loop

2014-07-15 Thread seany via Digitalmars-d-learn
i++) { auto m = match(greetings[i], r); } } To the best of my knowledge, declaring a variable inside a for loop is illegal, you can not delacre the same variable repeatedly over the iterations. Also just the declaration auto m; outside the for loop does not make sense either - auto needs

Re: for loop parens

2013-07-13 Thread H. S. Teoh
On Sat, Jul 13, 2013 at 05:08:11PM +0200, JS wrote: > On Saturday, 13 July 2013 at 01:06:09 UTC, H. S. Teoh wrote: [...] > >I find this fixation on syntax rather strange. As long as the syntax > >is not *too* ugly (*cough*C++ templates*cough*) isn't the *semantics* > >more important? A pretty langu

Re: for loop parens

2013-07-13 Thread Russel Winder
On Sat, 2013-07-13 at 12:43 +0200, ixid wrote: > > I think that Python has syntax evidently and demonstrably > > superior to D. Why not Python? > > White spaces with meaning cause hard to find bugs, the Python > syntax is not appropriate for large projects and this is well > known. That is not

Re: for loop parens

2013-07-13 Thread JS
On Saturday, 13 July 2013 at 01:06:09 UTC, H. S. Teoh wrote: On Fri, Jul 12, 2013 at 05:51:21PM -0700, Brad Roberts wrote: On 7/12/13 1:46 PM, ixid wrote: [...] >It seems a pity that D is achieving such power and elegance >in some >areas while failing to take on some of the syntactic beauty >

Re: for loop parens

2013-07-13 Thread bearophile
ixid: White spaces with meaning cause hard to find bugs, the Python syntax is not appropriate for large projects and this is well known. Well known by who? What's your evidence? My experience says otherwise :-) Bye, bearophile

Re: for loop parens

2013-07-13 Thread ixid
I think that Python has syntax evidently and demonstrably superior to D. Why not Python? White spaces with meaning cause hard to find bugs, the Python syntax is not appropriate for large projects and this is well known. That is not the case for the small changes Go has made.

Re: for loop parens

2013-07-13 Thread monarch_dodra
On Saturday, 13 July 2013 at 06:56:46 UTC, Ali Çehreli wrote: On 07/12/2013 10:34 PM, QAston wrote:> On Saturday, 13 July 2013 at 04:42:58 UTC, QAston wrote: >> Also, i don't know what's wrong with parens - 2 additional keystrokes? >> I didn't see a for loop i a lo

Re: for loop parens

2013-07-13 Thread Ali Çehreli
On 07/12/2013 10:34 PM, QAston wrote:> On Saturday, 13 July 2013 at 04:42:58 UTC, QAston wrote: >> Also, i don't know what's wrong with parens - 2 additional keystrokes? >> I didn't see a for loop i a long time - ranges + foreach are >> everywhere. And foreach

Re: for loop parens

2013-07-12 Thread Jonathan M Davis
On Saturday, July 13, 2013 07:03:28 QAston wrote: > On Saturday, 13 July 2013 at 04:56:19 UTC, Jonathan M Davis wrote: > > On Saturday, July 13, 2013 06:42:57 QAston wrote: > >> On Friday, 12 July 2013 at 20:46:21 UTC, ixid wrote: > >> > Yes, I don't expect anyone to change their opinion though > >

Re: for loop parens

2013-07-12 Thread QAston
On Saturday, 13 July 2013 at 04:42:58 UTC, QAston wrote: Also, i don't know what's wrong with parens - 2 additional keystrokes? I didn't see a for loop i a long time - ranges + foreach are everywhere. And foreach is 4 chars more to type than for :P. Replying to myself, bu

Re: for loop parens

2013-07-12 Thread QAston
On Saturday, 13 July 2013 at 04:56:19 UTC, Jonathan M Davis wrote: On Saturday, July 13, 2013 06:42:57 QAston wrote: On Friday, 12 July 2013 at 20:46:21 UTC, ixid wrote: > Yes, I don't expect anyone to change their opinion though > frankly the anti-groups opinions feel more like attachment to >

Re: for loop parens

2013-07-12 Thread Jonathan M Davis
On Saturday, July 13, 2013 06:42:57 QAston wrote: > On Friday, 12 July 2013 at 20:46:21 UTC, ixid wrote: > > Yes, I don't expect anyone to change their opinion though > > frankly the anti-groups opinions feel more like attachment to > > the status quo than something that's evidently and demonstrabl

Re: for loop parens

2013-07-12 Thread QAston
nderful feature - it has 0 cost, so the benefit/cost ratio approaches infinity :). Also, i don't know what's wrong with parens - 2 additional keystrokes? I didn't see a for loop i a long time - ranges + foreach are everywhere. And foreach is 4 chars more to type than for :P.

Re: for loop parens

2013-07-12 Thread H. S. Teoh
imited and often prettiness > lends itself to expressiveness. People find D templates much easier to > use than C++ ones and in part that's because they're much easier for > humans to parse. But I find C's for-loop syntax easier to parse, because what's in the preamble

Re: for loop parens

2013-07-12 Thread ixid
As long as the syntax is not *too* ugly (*cough*C++ templates*cough*) isn't the *semantics* more important? A pretty language that has limited expressiveness is useless; a powerful language that's a bit ugly in syntax isn't any less powerful because of it. T What is the cost of expressiven

Re: for loop parens

2013-07-12 Thread H. S. Teoh
On Fri, Jul 12, 2013 at 05:51:21PM -0700, Brad Roberts wrote: > On 7/12/13 1:46 PM, ixid wrote: [...] > >It seems a pity that D is achieving such power and elegance in some > >areas while failing to take on some of the syntactic beauty that is > >within reach. The ultimate language would look somet

Re: for loop parens

2013-07-12 Thread Brad Roberts
On 7/12/13 1:46 PM, ixid wrote: They are not issues in Go, but Walter is strongly against optional semicolons, as bearophile said. Me and others (like you) like optional semicolons, but since Walter doesn't and it's his language, that will not change. I personally understand much better the co

Re: for loop parens

2013-07-12 Thread ixid
I'm not sure how much of a problem it is, especially given that Go has a strict style guide, but the objection has come up that these two are very different: if i < f() { g() } and if i < f() { g() } In the second case, a semicolon is inserted on the same line as the i

Re: for loop parens

2013-07-12 Thread ixid
They are not issues in Go, but Walter is strongly against optional semicolons, as bearophile said. Me and others (like you) like optional semicolons, but since Walter doesn't and it's his language, that will not change. I personally understand much better the code without semicolons, like in

Re: for loop parens

2013-07-12 Thread Simen Kjaeraas
On 2013-07-12, 22:38, ixid wrote: On Friday, 12 July 2013 at 20:30:59 UTC, bearophile wrote: ixid: Similarly what are D user's potential issues with Go-like semi-colon rules? And would this be possible as a subset of current D code? Such changes will not happen even in D4. Walter is strong

Re: for loop parens

2013-07-12 Thread bearophile
ixid: Similarly what are D user's potential issues with Go-like semi-colon rules? And would this be possible as a subset of current D code? Such changes will not happen even in D4. Walter is strongly against the idea of optional semicolons, on the base that semicolons help the parser, so th

Re: for loop parens

2013-07-12 Thread Ary Borenszweig
On 7/12/13 5:38 PM, ixid wrote: On Friday, 12 July 2013 at 20:30:59 UTC, bearophile wrote: ixid: Similarly what are D user's potential issues with Go-like semi-colon rules? And would this be possible as a subset of current D code? Such changes will not happen even in D4. Walter is strongly a

Re: for loop parens

2013-07-12 Thread ixid
On Friday, 12 July 2013 at 20:30:59 UTC, bearophile wrote: ixid: Similarly what are D user's potential issues with Go-like semi-colon rules? And would this be possible as a subset of current D code? Such changes will not happen even in D4. Walter is strongly against the idea of optional sem

Re: for loop parens

2013-07-12 Thread ixid
On Friday, 12 July 2013 at 20:02:46 UTC, bearophile wrote: ixid: If curly brackets were required where parens were omitted what would prevent such a syntax in D? Maybe nothing, beside lot of programmers that want the "freedom" to omit curly brackets :-) Bye, bearophile Similarly what are

Re: for loop parens

2013-07-12 Thread bearophile
ixid: If curly brackets were required where parens were omitted what would prevent such a syntax in D? Maybe nothing, beside lot of programmers that want the "freedom" to omit curly brackets :-) Bye, bearophile

Re: for loop parens

2013-07-12 Thread ixid
On Friday, 12 July 2013 at 19:44:43 UTC, bearophile wrote: ixid: Go and Rust seem to have been able to dispense with the parens in for loops, is this something that would be possible to do in D or are there parsing and grammatical reasons not to do this? Go has chosen a different syntax. I

Re: for loop parens

2013-07-12 Thread bearophile
ixid: Go and Rust seem to have been able to dispense with the parens in for loops, is this something that would be possible to do in D or are there parsing and grammatical reasons not to do this? Go has chosen a different syntax. I don't think D syntax of for loops can change now... Bye, b

for loop parens

2013-07-12 Thread ixid
Go and Rust seem to have been able to dispense with the parens in for loops, is this something that would be possible to do in D or are there parsing and grammatical reasons not to do this?

Re: Why do i have to add to the counter when using for loop to perfectly get result?

2013-05-30 Thread estew
Well, after a quick glance at the code you're iterating N times but only printing N-1 times. When counter == peak the loop does nothing so you'd get something like: chosen=5 for(int counter = 0; counter < chosen ; ++counter){ // note +1 removed } counter = 0, 1, 2, [3]NO_PRINT, 4 *0 ***1

Why do i have to add to the counter when using for loop to perfectly get result?

2013-05-30 Thread Tori
/* licenced under the wtfpl license :D... as if i even understand how to license*/ import std.stdio; void main(){ //yeah... im making a diamond pattern out off asterisks writeln("Pick a number that is odd"); int chosen; bool oddnoteven = false; while(o

Re: a FOR loop and floating variables

2013-05-02 Thread bearophile
Simen Kjaeraas: Both 5 and 9 in the second example are integers (int). When you divide one int by another, the result is an int, and hence (5/9) is 0. Yes, smarter languages (like Pascal..., but also Python, Ada, etc) have two different division operators to avoid such silly C semantics, th

Re: a FOR loop and floating variables

2013-05-02 Thread Martin Drašar
Dne 2.5.2013 20:14, Carlos napsal(a): I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5

Re: a FOR loop and floating variables

2013-05-02 Thread Simen Kjaeraas
On 2013-05-02, 20:14, Carlos wrote: I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5.

a FOR loop and floating variables

2013-05-02 Thread Carlos
I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5.0" for "5" I get cero on the celsius s

Re: for loop

2012-01-23 Thread Jonathan M Davis
ialize: > ; > NoScopeNonEmptyStatement > > Initialize is NoScope. That's a pretty cool feature actually, since it gives you much more flexibility with regards to the types of the variables that you declare in the beginning of the for loop (or other things that you might want to

Re: for loop

2012-01-23 Thread Timon Gehr
On 01/23/2012 07:06 PM, bearophile wrote: Ellery Newcomer: void main(){ for ({int x=0; short y=0;} x< 10; x++, y++){ } } I don't understand, is that a compiler bug? Aren't x and y in a sub-scope that ends before you use x and y? Bye, bearophile It is not a bug. ForSta

Re: for loop

2012-01-23 Thread Mantis
23.01.2012 20:06, bearophile пишет: Ellery Newcomer: void main(){ for ({int x=0; short y=0;} x< 10; x++, y++){ } } I don't understand, is that a compiler bug? Aren't x and y in a sub-scope that ends before you use x and y? Bye, bearophile According to specs, this is Bloc

Re: for loop

2012-01-23 Thread bearophile
Ellery Newcomer: > void main(){ > for ({int x=0; short y=0;} x < 10; x++, y++){ > } > } I don't understand, is that a compiler bug? Aren't x and y in a sub-scope that ends before you use x and y? Bye, bearophile

Re: for loop

2012-01-23 Thread Trass3r
void main(){ for ({int x=0; short y=0;} x < 10; x++, y++){ } } wtf?

Re: for loop

2012-01-23 Thread Ellery Newcomer
On 01/22/2012 11:37 AM, Zachary Lund wrote: This is an ugly solution (and I'm not 100% sure it's valid D) but: /+/ void main() { { short y = 0; int x = 0; for (; x < 10; ++x, ++y) { } } } /+/ raise you. void main(){ for ({int

Re: for loop

2012-01-22 Thread Zachary Lund
On 01/22/2012 11:37 AM, Zachary Lund wrote: On 01/22/2012 11:08 AM, bearophile wrote: Max Klyga: If you want to declare and initialize several variables in the for loop, you can do it if they are of the same type: for (int x = 0, y = 0; ...; .++x, ++y) { ... } And if you need different

Re: for loop

2012-01-22 Thread Zachary Lund
On 01/22/2012 11:08 AM, bearophile wrote: Max Klyga: If you want to declare and initialize several variables in the for loop, you can do it if they are of the same type: for (int x = 0, y = 0; ...; .++x, ++y) { ... } And if you need different types this sometimes is enough: void main

Re: for loop

2012-01-22 Thread bearophile
Max Klyga: > If you want to declare and initialize several variables in the for > loop, you can do it if they are of the same type: > > for (int x = 0, y = 0; ...; .++x, ++y) { ... } And if you need different types this sometimes is enough: void main() { for (auto x = 0, y =

Re: for loop

2012-01-22 Thread Max Klyga
y internally in the for header? that is something like C# for (int x = 0, int y = 0; .) this doesn't work in D. If you want to declare and initialize several variables in the for loop, you can do it if they are of the same type: for (int x = 0, y = 0; ...; .++x, ++y) { ... }

Re: for loop

2012-01-22 Thread RenatoL
Ops, tk u .. sometimes C# is a bad teacher :-)

Re: for loop

2012-01-22 Thread Trass3r
for (int x = 0, int y = 0; .) for (int x=0, y=0; ...)

for loop

2012-01-22 Thread RenatoL
This works: import�std.stdio; void�main() { int�x =�0; int�y =�0; for(;�((x�<�5)�&&�(y�<�5));�x++,�y�++) { writeln("x + y = ",�x�+�y); } } The question is easy: is it possible to insert x and y internally in the for header? that is something like C# for (int x = 0, in