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*.
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
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.
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
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.
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
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,
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,
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
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
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
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`
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
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
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<
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()
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<
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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 {}
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 =
, "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
"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
>
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
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
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
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
>
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
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.
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
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
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
> >
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
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
>
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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?
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
/* 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
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
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
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.
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
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
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
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
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
void main(){
for ({int x=0; short y=0;} x < 10; x++, y++){
}
}
wtf?
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
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
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
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 =
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) { ... }
Ops, tk u .. sometimes C# is a bad teacher :-)
for (int x = 0, int y = 0; .)
for (int x=0, y=0; ...)
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
85 matches
Mail list logo