Re: ePub/Mobi/AZW3/PDF of Phobos Runtime Library

2022-06-28 Thread forkit via Digitalmars-d-learn
On Tuesday, 28 June 2022 at 21:14:42 UTC, Marcone wrote: Is there any way to do this automatically like Python? https://docs.python.org/3/download.html Of course there is. But someone has to volunteer their time and effort to do it ;-)

Re: ePub/Mobi/AZW3/PDF of Phobos Runtime Library

2022-06-28 Thread forkit via Digitalmars-d-learn
On Tuesday, 28 June 2022 at 18:42:11 UTC, Marcone wrote: Beloved, I love programming in D. D is my favorite programming language. I'm not a professional programmer, but I love to program. I would like to learn D deeply. Most programming languages have a PDF/CHM/MOBI/ePub version of the

Re: Can I create a package with friendly modules

2022-06-12 Thread forkit via Digitalmars-d-learn
On Sunday, 12 June 2022 at 05:46:17 UTC, Mike Parker wrote: I don't get it. How does this enable one module to access the private parts of another module? Isn't 'private' *always* private to the module? The idea I had, was to be able to spread a 'module' over more than one file - for

Re: Can I create a package with friendly modules

2022-06-11 Thread forkit via Digitalmars-d-learn
On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote: e.g. If I could something like this: // foo_1.d module foo_1 private int a; // a is private to module foo_1 // foo_2.d module foo_2 private int b; // b is private to module foo_2 // foo.d module foo[dependencies:foo_1, foo_2]; import

Can I create a package with friendly modules

2022-06-11 Thread forkit via Digitalmars-d-learn
Is it possible to create a package.d, consisting of (for example), two modules, where each module can access private declarations within each other. In essence, declaring 'a module level friendship', or a kind of 'extended module' if you want. I might still want to add another module to the

Re: C-like static array size inference - how?

2022-06-08 Thread forkit via Digitalmars-d-learn
On Wednesday, 8 June 2022 at 01:32:42 UTC, Steven Schveighoffer wrote: I like `$`. It's got a well-defined meaning, and already is somewhat magic. -Steve I agree it's magic. warray[5..$] - this is one of the best uses of syntax magic in D! I think it's what first attracted me to the

Re: C-like static array size inference - how?

2022-06-07 Thread forkit via Digitalmars-d-learn
On Wednesday, 8 June 2022 at 01:11:45 UTC, Mike Parker wrote: ...The author withdrew the DIP .. That's a shame. Seems like a useful language feature. I'd be using it already if it existed. I'd have gone for: int[..] arr = [1,2,3];

Re: Why are structs and classes so different?

2022-05-18 Thread forkit via Digitalmars-d-learn
On Sunday, 15 May 2022 at 21:33:24 UTC, Ali Çehreli wrote: I still think my answer is the real one. My implied question remains: Why does C++ have struct and class disticnction? I know they have different default access specifications but does that warrant two kinds? Here is a

Re: Question on shapes

2022-05-17 Thread forkit via Digitalmars-d-learn
On Tuesday, 17 May 2022 at 04:37:58 UTC, Ali Çehreli wrote: In you OOP example, I am curious why you chose Shape to be an interface, rather than a base class.

Re: Why are structs and classes so different?

2022-05-15 Thread forkit via Digitalmars-d-learn
On Sunday, 15 May 2022 at 15:26:40 UTC, Kevin Bailey wrote: I've done some scripting in D over the years but I never dug into D until recently. I'm going through Learning D and I was reminded that structs and classes are so different. - struct methods are non-virtual while class methods are

Re: Why are structs and classes so different?

2022-05-15 Thread forkit via Digitalmars-d-learn
On Sunday, 15 May 2022 at 15:59:17 UTC, Alain De Vos wrote: Can i summarize , structs are value-objects which live on the stack. class instances are reference objects which live on the heap. the real difference, is that structs, being value types, are passed by value, and classes, being

Re: Back to Basics at DConf?

2022-05-13 Thread forkit via Digitalmars-d-learn
On Friday, 13 May 2022 at 15:56:31 UTC, H. S. Teoh wrote: My mental image of this is Ali presenting some simple common task, then at 3/4 of the presentation there's an amazing trick that lets you write it in D in 5 times less code than in other languages, and my mind is blown and I remember

Re: Back to Basics at DConf?

2022-05-13 Thread forkit via Digitalmars-d-learn
On Friday, 13 May 2022 at 03:31:53 UTC, Ali Çehreli wrote: On 5/12/22 18:56, forkit wrote: > So...you want to do a talk that challenges D's complexity, by getting > back to basics? I wasn't thinking about challenging complexity but it gives me ideas. I am looking for concrete topics like

Re: Back to Basics at DConf?

2022-05-12 Thread forkit via Digitalmars-d-learn
On Thursday, 12 May 2022 at 21:58:33 UTC, Ali Çehreli wrote: I am considering proposing a presentation for DConf 2022. Would a "Back to Basics" style presentation be interesting? If, so what exact topic would you like to see? For ideas, here is what CppCon 2021 had on their track:

Re: range result in Tuple! and how to convert into assocArray by sort?

2022-05-11 Thread forkit via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 03:22:04 UTC, MichaelBi wrote: s is the string, and print result as following: s.array.sort!("athen how to transfer into [['A',231],['C',247],['G',240],['T',209]]? tried map!, but can only sortout key or value... tried array(), but result is not sorted

Re: Using regular expressions when reading a file

2022-05-06 Thread forkit via Digitalmars-d-learn
On Friday, 6 May 2022 at 07:51:01 UTC, Alexander Zhirov wrote: On Friday, 6 May 2022 at 05:40:52 UTC, forkit wrote: auto myTuple = line.split(" = "); Well, only if as a strict form :) well.. a settings file should be following a strict format. ..otherwise...anything goes... and good luck

Re: Using regular expressions when reading a file

2022-05-05 Thread forkit via Digitalmars-d-learn
On Thursday, 5 May 2022 at 17:53:57 UTC, Alexander Zhirov wrote: I want to use a configuration file with external settings. I'm trying to use regular expressions to read the `Property = Value` settings. I would like to do it all more beautifully. Is there any way to get rid of the line break

Re: How to use destroy and free.

2022-05-04 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 21:55:18 UTC, H. S. Teoh wrote: On Wed, May 04, 2022 at 09:46:50PM +, forkit via Digitalmars-d-learn wrote: [...] That languages with GC typically give the programmer some control over the GC, is evidence that programmers do care (otherwise such features would

Re: How to use destroy and free.

2022-05-04 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 15:04:13 UTC, cc wrote: The MemUtils package offers a `ScopedPool` utility that seems interesting. It isn't well documented however so I have no idea if it actually works like I expect. I presume this would work something akin to a VM memory snapshot/rollback for

Re: How to use destroy and free.

2022-05-04 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 12:57:26 UTC, Ali Çehreli wrote: On 5/3/22 22:37, forkit wrote: > In any case, I disagree that caring about when memory gets deallocted > means you shouldn't be using GC. (or did I get that one wrong too??) At least I don't agree with you there. :) Yes, one should

Re: How to use destroy and free.

2022-05-04 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 08:23:33 UTC, Mike Parker wrote: On Wednesday, 4 May 2022 at 05:37:49 UTC, forkit wrote: That's not at all what I said. You don't have to care about *when* memory is deallocated, meaning you don't have to manage it yourself. In any case, I disagree that caring

Re: How to use destroy and free.

2022-05-03 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 05:13:04 UTC, Mike Parker wrote: On Wednesday, 4 May 2022 at 04:52:05 UTC, forkit wrote: It is certainly *not* about you not having to care anymore (about memory management). That's not at all what I said. You don't have to care about *when* memory is

Re: How to use destroy and free.

2022-05-03 Thread forkit via Digitalmars-d-learn
On Wednesday, 4 May 2022 at 02:42:44 UTC, Mike Parker wrote: On Tuesday, 3 May 2022 at 14:57:46 UTC, Alain De Vos wrote: Note, It's not i'm against GC. But my preference is to use builtin types and libraries if possible, But at the same time be able to be sure memory is given free when a

Re: Where I download Digital Mars C Preprocessor sppn.exe?

2022-04-03 Thread forkit via Digitalmars-d-learn
On Saturday, 2 April 2022 at 23:40:39 UTC, Marcone wrote: ImportC is deprecated as everything in D is deprecated and abandoned. No link works, every download link is broken as no one cares. All D code is always full of bugs and needs to be corrected by the user before trying to run it, in

Re: How to remove all characters from a string, except the integers?

2022-03-04 Thread forkit via Digitalmars-d-learn
On Friday, 4 March 2022 at 02:10:11 UTC, Salih Dincer wrote: On Thursday, 3 March 2022 at 20:23:14 UTC, forkit wrote: On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote: I'm a simple man who uses D with the old C mentality: [...] ```d string s, str = "4A0B1de!2C9~6";

Re: How to use ImportC?

2022-03-03 Thread forkit via Digitalmars-d-learn
On Thursday, 3 March 2022 at 19:05:22 UTC, Leonardo wrote: I saw the new feature called ImportC, it's cool to be able to use C code/libraries, but I'm not much experience in C and didn't understand this incomplete documentation: https://dlang.org/spec/importc.html How to use ImportC? I

Re: How to remove all characters from a string, except the integers?

2022-03-03 Thread forkit via Digitalmars-d-learn
On Thursday, 3 March 2022 at 19:28:36 UTC, matheus wrote: I'm a simple man who uses D with the old C mentality: import std.stdio; void main(){ string s, str = "4A0B1de!2C9~6"; foreach(i;str){ if(i < '0' || i > '9'){ continue; } s ~= i; } writeln("Result: ", s);

Re: initializing struct containing user defined type

2022-02-18 Thread forkit via Digitalmars-d-learn
On Friday, 18 February 2022 at 16:45:24 UTC, Ali Çehreli wrote: ... I think that syntax will be obviated when D will have named arguments. Ali Huh? D doesn't have named arguments, already? That's an important component for safe(r) programming. Do you know if there is a DIP for this, and

Re: split Error - no overload matches

2022-02-14 Thread forkit via Digitalmars-d-learn
On Monday, 14 February 2022 at 11:37:38 UTC, ag0aep6g wrote: On 14.02.22 12:14, forkit wrote: However, if I uncomment the //import std.uni : isWhite; then it will compile. I don't understand. I thought 'import std;' would be sufficient here?? "isWhite" is ambiguous. There's std.uni.isWhite

split Error - no overload matches

2022-02-14 Thread forkit via Digitalmars-d-learn
This code will not compile. Error: no overload matches for `split` However, if I uncomment the //import std.uni : isWhite; then it will compile. I don't understand. I thought 'import std;' would be sufficient here?? // module test; @safe: import std; void main() { //import

Re: Offline D documentation/tutorial

2022-02-13 Thread forkit via Digitalmars-d-learn
On Sunday, 13 February 2022 at 00:43:18 UTC, Mike Parker wrote: If you’ve installed dmd via one of the supported installers (or the zip), you should already have the html files for the spec. On Windows, they’re in a subdirectory. I assume on other platforms they’re in the standard doc

Re: how to handle very large array?

2022-02-09 Thread forkit via Digitalmars-d-learn
On Thursday, 10 February 2022 at 01:43:54 UTC, H. S. Teoh wrote: On Thu, Feb 10, 2022 at 01:32:00AM +, MichaelBi via Digitalmars-d-learn wrote: On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote: > [...] thanks, very helpful! i am using a assocArray now... Are you sure

Re: How to verify DMD download with GPG?

2022-02-08 Thread forkit via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 10:17:19 UTC, Ola Fosheim Grøstad wrote: I don't use GPG often, so I probably did something wrong, and failed to get a trusted verification. I do like the idea that a hacker cannot change the signature file if gaining access to the web/file hosts, but how to

iteration over directories is unsafe

2022-02-05 Thread forkit via Digitalmars-d-learn
It is not possible to do a simple iteration over directories in @safe mode. Really? I have to resort to unsafe?? // module test; @safe: // nope. no can do. import std; void main() { auto dFiles = dirEntries("", "*.{d,di}", SpanMode.depth); foreach(d; dFiles)

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
On Friday, 4 February 2022 at 15:58:19 UTC, Stanislav Blinov wrote: .. ... As others have already stated, casting immutability away is something that has to be supported, e.g. to interface with const-agnostic APIs. `@safe` requires such casts to be more verbose, with good reason. I concede

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
On Friday, 4 February 2022 at 10:09:22 UTC, Patrick Schluter wrote: On Thursday, 3 February 2022 at 02:01:34 UTC, forkit wrote: On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote: would be nice if the compiler told me something though :-( i.e. "hey, dude, you really wanna to

Re: ldc executable crashes with this code

2022-02-04 Thread forkit via Digitalmars-d-learn
On Friday, 4 February 2022 at 10:09:22 UTC, Patrick Schluter wrote: On Thursday, 3 February 2022 at 02:01:34 UTC, forkit wrote: On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote: would be nice if the compiler told me something though :-( i.e. "hey, dude, you really wanna to

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
On Thursday, 3 February 2022 at 03:25:39 UTC, H. S. Teoh wrote: On Thu, Feb 03, 2022 at 02:01:34AM +, forkit via Digitalmars-d-learn wrote: [...] would be nice if the compiler told me something though :-( i.e. "hey, dude, you really wanna to that?" Mark your func

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
On Thursday, 3 February 2022 at 01:57:12 UTC, H. S. Teoh wrote: would be nice if the compiler told me something though :-( i.e. "hey, dude, you really wanna to that?"

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote: oops! forgot the .dup char[] palindrome = cast(char[])"able was I ere I saw elba".dup; ;-)

Re: ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote: On Wed, Feb 02, 2022 at 11:21:52PM +, forkit via Digitalmars-d-learn wrote: [...] char[] palindrome = cast(char[])"able was I ere I saw elba"; String literals are immutable by default. Casting immutable t

ldc executable crashes with this code

2022-02-02 Thread forkit via Digitalmars-d-learn
Any reason why compiling this with ldc would cause the exe to crash? Compiling with DMD (using either declaration of palindrome works just fine though) // module test; import std; void main() { char[] palindrome = cast(char[])"able was I ere I saw elba"; //char[] palindrome

Re: gdc or ldc for faster programs?

2022-01-26 Thread forkit via Digitalmars-d-learn
On Wednesday, 26 January 2022 at 11:25:47 UTC, Iain Buclaw wrote: Whenever I've watched talks/demos where benchmarks were the central topic, GDC has always blown LDC out the water when it comes to matters of math. .. https://dlang.org/blog/2020/05/14/lomutos-comeback/

Re: gdc or ldc for faster programs?

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 20:01:18 UTC, Johan wrote: Tough to say. Of course DMD is not a serious contender, but I believe the difference between GDC and LDC is very small and really in the details, i.e. you'll have to look at assembly to find out the delta. Have you tried

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:35:29 UTC, forkit wrote: I should point out (to anyone looking at that code I posted), that it's easier, and makes more sense, to just write: writeln( ["typeA", "typeB", "typeC"].choice ); ... but my main focus here, was learning about variadic template

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 22:07:43 UTC, Ali Çehreli wrote: thanks. makes it even shorter and simpler :-) // -- module test; @safe: import std; auto RandomChoice(R...)(R r) { auto rnd = MinstdRand0(unpredictableSeed); return only(r).choice(rnd); } void main() { writeln(

Re: passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 11:50:08 UTC, vit wrote: thanks. problem solved (providing all parameters are of the same type). // --- module test; import std; auto RandomChoice(R...)(R r) { auto rnd = MinstdRand0(unpredictableSeed); return only(r).randomSample(1, rnd).front; }

passing a variadic parameter to randomSample

2022-01-25 Thread forkit via Digitalmars-d-learn
so I'm trying to write (or rather learn how to write) a 'variadic template function', that returns just one of its variadic parameter, randomly chosen. But can't get my head around the problem here :-( .. Error: template `std.random.randomSample` cannot deduce function from argument types `

Re: unordered output of an associated array of associated arrays

2022-01-24 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 02:12:50 UTC, H. S. Teoh wrote: That's the *easy* way out?? Try this instead: aaTable.keys.sort.each!((k) { aaTable[k].keys.sort.each!((kk) { writefln("%s:%s:%s", k, kk, aaTable[k][kk]); });

Re: unordered output of an associated array of associated arrays

2022-01-24 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 00:43:07 UTC, forkit wrote: oh. thanks :-) I will get that integrated into my example code, and will post again, once it's working (so others can learn too) ok.. so I took the easy way out ;-) output is now ordered: typeA:10003:[1, 1, 1, 0, 0, 0, 0, 0]

Re: unordered output of an associated array of associated arrays

2022-01-24 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 00:39:05 UTC, H. S. Teoh wrote: AA's are unordered containers. Do not rely on entries to appear in any specific order when you traverse an AA; it is implementation-dependent and may differ from OS to OS / platform to platform / sequence of operations performed

Re: unordered output of an associated array of associated arrays

2022-01-24 Thread forkit via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 00:23:40 UTC, forkit wrote: another example: output is: typeA: 10001:[0, 0, 1, 1, 1, 1, 1, 1] 10002:[0, 0, 0, 1, 1, 1, 1, 1] typeB: 10005:[0, 0, 0, 0, 0, 0, 1, 1] 10003:[0, 0, 0, 0, 1, 1, 1, 1]

unordered output of an associated array of associated arrays

2022-01-24 Thread forkit via Digitalmars-d-learn
so I'm trying to understand why the output of the code below, is in reverse order of the declaration (and how to fix it so that it outputs in an ordered way) i.e. output is: typeA: A2:A2value A1:A1value typeB: B3:B3value B2:B2value B1:B1value // --

Re: dynamic format specifier possible?

2022-01-23 Thread forkit via Digitalmars-d-learn
On Sunday, 23 January 2022 at 22:08:28 UTC, Ali Çehreli wrote: You use an asterisk and provide the width as an argument. This one uses the length of the name of the program: import std; void main(string[] args) { int val = 999000; writefln("[%*s]", args.front.length, val); // [

dynamic format specifier possible?

2022-01-23 Thread forkit via Digitalmars-d-learn
I would like to calculate the width of the format specifier dynamically, at runtime. e.g int WIDTH = something.length; then my format specifier would be: %WIDTHs instead of %9s // --- module test; import std; void main() { int val = 999000; writefln("[%9s]", val); // [ 999000] }

Re: map question

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov wrote: thanks for the explanation. That really helped :-) writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) ); [1, 1, 1, 1, 0] (or after reading Ali's response - getting rid of rnd, and using _ ) writeln(

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 22:44:31 UTC, forkit wrote: and here is how to get the ip (depending on the formatting of your output of course) // --- module test; import std; void main() { auto result = execute(["bash", "-c", "nmap -sn 192.168.11.0/24 | ack -B2 \"Philips\""]);

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 23:15:18 UTC, forkit wrote: oh.. this is better i think... ip = str[ ((lastIndexOf(str, "(")) + 1) .. lastIndexOf(str, ")") ];

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 20:55:38 UTC, Daren Scot Wilson wrote: is this helpful: // --- module test; import std; void main() { auto result = execute(["bash", "-c", "nmap -sn 192.168.11.0/24 | ack -B2 \"Phillips\""]); if(canFind(result.to!string, "Host is up"))

map question

2022-01-22 Thread forkit via Digitalmars-d-learn
trying to make sense of the below: // --- module test; import std; void main() { auto rnd = Random(unpredictableSeed); int howManyTimes = 5; // ok - using 'e =>' makes sense writeln(howManyTimes.iota.map!(e => rnd.dice(0.6, 1.4)).format!"%(%s,%)"); // ok - though

Re: automate tuple creation

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 01:33:16 UTC, Steven Schveighoffer wrote: That second `valuesPerRecord` is not used in the lambda, and also it's not referring to the original element, it's the name of a parameter in the lambda. Are you sure this is doing what you want? -Steve It just

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 01:33:16 UTC, Steven Schveighoffer wrote: so I why watching this video by Andrei: https://www.youtube.com/watch?v=mCrVYYlFTrA In it, he talked about writing the simplest design that could possibly work Which got me thinking // module test;

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 22:25:32 UTC, forkit wrote: I really like how alias and mixin can simplify my code even further: //--- int[][int][] CreateDataSet (const(int) recordsNeeded, const(int) valuesPerRecord) { int[][int][] records; records.reserve(recordsNeeded); const

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 21:56:33 UTC, H. S. Teoh wrote: What's the point of calling .dup here? The only reference to records is going out of scope, so why can't you just return it? The .dup is just creating extra work for nothing. T good pickup. thanks ;-) // module test;

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 21:43:38 UTC, forkit wrote: oops... should be: // --- int[][int][] CreateDataSet (const(int) recordsNeeded, const(int)valuesPerRecord) { int[][int][] records; records.reserve(recordsNeeded); const int iotaStartNum = 100_000_001; foreach(i, id;

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 21:01:11 UTC, forkit wrote: even better, I got rid of all those uncessary arrays ;-) // --- int[][int][] CreateDataSet (const(int) recordsNeeded, const(int)valuesPerRecord) { int[][int][] records; records.reserve(recordsNeeded); foreach(i, id;

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 18:50:46 UTC, Steven Schveighoffer wrote: Yeah, iota is a random-access range, so you can just pass it directly, and not allocate anything. Looking at the usage, it doesn't need to be an array at all. But modifying the code to properly accept the range might

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 18:36:42 UTC, H. S. Teoh wrote: This is wasteful if you're not planning to use every ID in this million-entry long array. Much better to just use an AA to keep track of which IDs have already been generated instead. Of course, if you plan to use most of the

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 09:10:56 UTC, forkit wrote: ok... in the interest of corecting the code I posted previously... ... here is a version that actually works in secs (for a million records), as opposed to hours! // --- /+

Re: automate tuple creation

2022-01-21 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 08:53:26 UTC, Stanislav Blinov wrote: turns out the problem has nothing to do with appender... It's actually this line: if (!idArray.canFind(x)): when i comment this out in the function below, the program does what I want in seconds. only problem is, the

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 04:08:33 UTC, forkit wrote: // -- void ProcessRecords (in int[][int][] recArray, const(string) fname) { auto file = File(fname, "w"); scope(exit) file.close; Appender!string bigString = appender!string; bigString.reserve(recArray.length);

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 03:57:01 UTC, H. S. Teoh wrote: std.array.appender is your friend. T :-) // -- void ProcessRecords (in int[][int][] recArray, const(string) fname) { auto file = File(fname, "w"); scope(exit) file.close; Appender!string bigString = appender!string;

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 03:45:08 UTC, forkit wrote: On Friday, 21 January 2022 at 02:30:35 UTC, Ali Çehreli wrote: The bigger question is, why did 'formattedRecords' exist at all? You could have written the output directly to the file. Oh. this was intentional, as I wanted to write

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 02:30:35 UTC, Ali Çehreli wrote: The bigger question is, why did 'formattedRecords' exist at all? You could have written the output directly to the file. Oh. this was intentional, as I wanted to write once, and only once, to the file. The consequence of that

Re: -debug question

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 02:10:34 UTC, Steven Schveighoffer wrote: thanks Steven (and Ali too).

-debug question

2022-01-20 Thread forkit via Digitalmars-d-learn
I have a line of code, that I do NOT want executed when -debug is passed in. enforce(!exists(fname), "Oop! That file already exists!"); Is this even possible? (with using -version ..)

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Friday, 21 January 2022 at 01:35:40 UTC, forkit wrote: oops. nasty mistake to make ;-) module test; @safe should be: module test; @safe:

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 23:49:59 UTC, Ali Çehreli wrote: so here is final code, in idiomatic D, as far as I can tell ;-) curious output when using -profile=gc .. a line referring to: std.array.Appender!(immutable(char)[]).Appender.Data std.array.Appender!string.Appender.this

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 22:31:17 UTC, Steven Schveighoffer wrote: Because it would allow altering const data. I'm not sure I understand. At what point in this function is valuesArray modified, and thus preventing it being passed in with const? // --- int[][int][] CreateDataSet

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 21:16:46 UTC, forkit wrote: Cannot work out why I cannot pass valuesArray in as ref const?? get error: Error: cannot append type `const(int[])[const(int)]` to type `int[][int][]` // -- int[][int][] CreateDataSet(ref const int[] idArray, ref

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 12:40:09 UTC, Stanislav Blinov wrote: Allocating 4 megs to generate 10 numbers??? You can generate a random number between 99900 and 10. ... // id needs to be 9 digits, and needs to start with 999 x = uniform(999*10^^6, 10^^9);

Re: automate tuple creation

2022-01-20 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 10:11:10 UTC, bauss wrote: Don't make them random then, but use an incrementor. If you can have ids that aren't integers then you could use uuids too. https://dlang.org/phobos/std_uuid.html The 'uniqueness' of id would actually be created in the database.

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 04:38:39 UTC, forkit wrote: all done ;-) // --- module test; import std.stdio : writeln; import std.range : iota, isForwardRange, hasSlicing, hasLength, isInfinite; import std.array : array, Appender; import std.random : Random, unpredictableSeed, dice,

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 04:00:59 UTC, forkit wrote: void makeUniqueIDs(ref uint[] arr, size_t sz) { ... } arrg! what was i thinking! ;-) // --- void makeUniqueIDs(ref uint[] arr, size_t sz) { arr.reserve(sz); // id needs to be 9 digits, and needs to start with 999

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Thursday, 20 January 2022 at 00:30:44 UTC, H. S. Teoh wrote: Do the id's have to be unique? yep... I'm almost there ;-) // --- module test; import std.stdio : writeln; import std.range : iota, isForwardRange, hasSlicing, hasLength, isInfinite; import std.array : array, Appender;

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 21:59:15 UTC, forkit wrote: so at the moment i can get a set number of tuples, with a set number of bool values contained within each tuple. e.g. createBoolMatrix(mArrBool,3, 2); [[1, 0], [1, 1], [1, 0]] my next challenge (more for myself, but happy for

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 22:35:58 UTC, Ali Çehreli wrote: so I combined ideas from all responses: // -- module test; import std.stdio : writeln; import std.range : iota, isForwardRange, hasSlicing, hasLength, isInfinite, array; import std.random : Random, unpredictableSeed, dice;

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 23:22:17 UTC, forkit wrote: oops // e.g: create a matrix consisting of 5 tuples, with each tuple containing 3 random bools (0 or 1) createBoolMatrix(mArrBool,5, 3);

Re: automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 21:59:15 UTC, forkit wrote: oh. that randomShuffle was unnecessary ;-)

automate tuple creation

2022-01-19 Thread forkit via Digitalmars-d-learn
so I have this code below, that creates an array of tuples. but instead of hardcoding 5 tuples (or hardcoding any amount of tuples), what I really want to do is automate the creation of how-ever-many tuples I ask for: i.e. instead of calling this: createBoolMatrix(mArrBool); I would call

Re: number ranges

2022-01-18 Thread forkit via Digitalmars-d-learn
On Wednesday, 19 January 2022 at 03:00:49 UTC, Tejas wrote: On Tuesday, 18 January 2022 at 20:43:08 UTC, forkit wrote: On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using

Re: shared defaultlib with dmd

2022-01-18 Thread forkit via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 22:35:08 UTC, H. S. Teoh wrote: On Tue, Jan 18, 2022 at 10:04:15PM +, forkit via Digitalmars-d-learn wrote: so I use this compile command (on Windows, using ldc) -link-defaultlib-shared=true Then (in simple example) the size of my compiled .exe: From 806KB

Re: shared defaultlib with dmd

2022-01-18 Thread forkit via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 22:09:18 UTC, Adam D Ruppe wrote: On Tuesday, 18 January 2022 at 22:04:15 UTC, forkit wrote: so I use this compile command (on Windows, using ldc) On Linux dmd can do `-defaultlib=libphobos2.so` for the same thing. On Windows, dmd cannot handle a shared

Re: number ranges

2022-01-18 Thread forkit via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 20:50:06 UTC, Ali Çehreli wrote: Needs a little more work to be correct. The following produces and empty range. ;) range(uint.min, uint.max) Also, is it important for the result to be the same as T? For example, even if T is ubyte, because b+1 is 'int',

shared defaultlib with dmd

2022-01-18 Thread forkit via Digitalmars-d-learn
so I use this compile command (on Windows, using ldc) -link-defaultlib-shared=true Then (in simple example) the size of my compiled .exe: From 806KB down to 18KB Oh. That's so much nicer on my SSD ;-) (yes, I understand the implictions here of dynamic sharing, but I test/compile/debug so

Re: number ranges

2022-01-18 Thread forkit via Digitalmars-d-learn
On Tuesday, 18 January 2022 at 16:02:42 UTC, Tejas wrote: Newer languages nowadays use `start..intent, think it's something we should follow? I've decided to avoid using number ranges 'directly', and instead use a wrapper function... auto range(T:T)(T a, T b) { import std.range :

Re: number ranges

2022-01-17 Thread forkit via Digitalmars-d-learn
On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: If I ever needed to foreach over 1-based indices, I'd write it this way in order to avoid all confusion: foreach (i; 1 .. 5 + 1) { } This will immediately make whoever reads the code (i.e., myself after 2

Re: number ranges

2022-01-17 Thread forkit via Digitalmars-d-learn
On Monday, 17 January 2022 at 22:06:47 UTC, H. S. Teoh wrote: Basically, foreach (i; a .. b) is equivalent to: for (auto i = a; i < b; i++) Just think of that way and it will make sense. I think it's fair to say, that I'm familiar with 0-based indexing ;-) my concern

Re: number ranges

2022-01-17 Thread forkit via Digitalmars-d-learn
On Monday, 17 January 2022 at 11:58:18 UTC, Paul Backus wrote: This kind of half-open interval, which includes the lower bound but excludes the upper bound, is used in programming because it lets you write foreach (i; 0 .. array.length) writef("%s ", array[i]); ...without going past

number ranges

2022-01-17 Thread forkit via Digitalmars-d-learn
so I'm wondering why the code below prints: 1 2 3 4 and not 1 2 3 4 5 as I would expect. foreach (value; 1..5) writef("%s ", value); also, why is this not possible: int[] arr = 1..5.array;

  1   2   >