Re: struct inside struct: Is there a way to call a function of the outside struct from the inner struct?

2019-07-06 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 6 July 2019 at 12:33:00 UTC, berni wrote: Now I found this: https://forum.dlang.org/thread/eobdqkkczquxoepst...@forum.dlang.org Seems to be intentional, that this doesn't work. In my case I'm able to move d() into the outer struct... You'll need a pointer to the outer struct,

Re: Why are immutable array literals heap allocated?

2019-07-05 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 5 July 2019 at 16:25:10 UTC, Nick Treleaven wrote: Yes, I was wondering why the compiler doesn't statically allocate it automatically as an optimization. Which i would think it could, but silently adds .dup to the end as it points to a unnamed memory block of N size. Or if it's

Re: Bitfields

2019-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: As far as I can see std.bitmanip only caters for 8, 16, 32, and 64 bit long bitfields. I worked on/with bitfields in the past, the limit sizes is more or less for natural int types that D supports. However this limitation is

Re: Is using floating point type for money/currency a good idea?

2019-05-20 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 20 May 2019 at 12:50:29 UTC, Simen Kjærås wrote: If you're worried that $92_233_720_368_547_758.07 (long.max) is not enough money for your game, I'd note that the entire current world economy is about a thousandth of that. Even so, there's std.bigint.BigInt, which has no set limit,

Re: Is using floating point type for money/currency a good idea?

2019-05-20 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 20 May 2019 at 11:50:57 UTC, Dennis wrote: For a simple game, I think it's the easiest to just store an integer of cents (or the lowest amount of currency possible). Back in 2003 i did this very thing for when creating my C program for suggesting and helping with credit card

Re: Hookable Swap

2019-05-19 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 20 May 2019 at 02:18:51 UTC, Era Scarecrow wrote: Here's some outputs if you are interested Noticing how Heapify moves a large portion of areas more or less in their location, doing heapify before binary insertion sort lowers how much moving goes on quite a bit. Doing 2 heapify's

Re: Hookable Swap

2019-05-19 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 19 May 2019 at 06:13:13 UTC, Era Scarecrow wrote: Making a struct type/array that visually outputs and displays compares/mutations of a type. While using the library sorting functions (which relies on std.algorithm.mutation.swap Well been having fun with sorting and more of this;

Re: Same code different behaviour in debug & release mode?

2019-05-19 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 19 May 2019 at 17:55:10 UTC, Robert M. Münch wrote: It seems that the debugger has quite some problem when the code was compiled with optimization and debug-information. I remember having similar problems in a C program years ago, ended up just releasing the code unoptimized and

Hookable Swap

2019-05-19 Thread Era Scarecrow via Digitalmars-d-learn
Making a struct type/array that visually outputs and displays compares/mutations of a type. While using the library sorting functions (which relies on std.algorithm.mutation.swap) it doesn't call opAssign and doesn't pass through the struct. (which also changes the indexes which it shouldn't).

Re: Speed of math function atan: comparison D and C++

2018-03-04 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote: atan should work out to only be a few instructions (inline assembly) from what I've looked at in the source. Also you should post the code you used for each. Should be 3-4 instructions. Load input to the FPU (Optional?

Re: Caesar Cipher

2018-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 11 February 2018 at 18:01:20 UTC, Mario wrote: char[] encrypt(char[] input, char shift) { auto result = input.dup; result[] += shift; return result; } What's wrong? I mean, I know that z is being converted into a symbol, but how should I fix this? If you take Z (25)

Re: ESR on post-C landscape

2017-11-14 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 14 November 2017 at 06:32:55 UTC, lobo wrote: And I fixed it all right – took me two weeks of struggle. After which I swore a mighty oath never to go near C++ again. ...[snip]" Reminds me of the last time I touched C++. A friend wanted help with the Unreal Engine. While

Re: BinaryHeap as member

2017-11-13 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 13 November 2017 at 16:26:20 UTC, balddenimhero wrote: In the course of writing a minimal example I removed more than necessary in the previous pastebin (the passed IntOrder has not even been used). Thus here is the corrected one: https://pastebin.com/SKae08GT. I'm trying to port

Re: find difference between two struct instances.

2017-07-21 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 21 July 2017 at 21:03:22 UTC, FoxyBrown wrote: Is there a way to easily find the differences between to struct instances? I would like to report only the differences e.g., writeln(s1 - s2); prints only what is different between s1 and s2. This is entirely dependent on the

Re: How to init immutable static array?

2017-07-18 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 07:30:30 UTC, Era Scarecrow wrote: my_array[i]=some calculations(based on constants and n) i meant: tmp[i]=some calculations(based on constants and n)

Re: How to init immutable static array?

2017-07-18 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 07:20:48 UTC, Miguel L wrote: Hi, I need help again. I have an immutable static array and i need to initialize its contents inside a for loop. Something like this: void f(int n)() { immutable float[n] my_array; for(int i=0;i

Re: How to get the address of a static struct?

2017-07-09 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 10 July 2017 at 03:48:17 UTC, FoxyBrown wrote: static struct S auto s = // ?!?!?! invalid because S is a struct, but... basically s = S. So S.x = s.x and s.a = S.a; Why do I have to do this? Static has a different meaning for struct. More or less it means it won't have access

Re: CTFE output is kind of weired

2017-07-08 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 8 July 2017 at 21:29:10 UTC, Andre Pany wrote: app.d(17):called from here: test("1234\x0a5678\x0a") I wrote the source code on windows with a source file with \r\n file endings. But the console output has only the character X0a. In addition not the content of tmp is shown

Re: Funny issue with casting double to ulong

2017-07-04 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 4 July 2017 at 12:32:26 UTC, Patrick Schluter wrote: In times of lore, BCD floats were very common. The Sharp Pocket Computer used a BCD float format and writing machine code on them confronts one with the format. The TI-99/4A home computer also used a BCD float format in its Basic

Re: Funny issue with casting double to ulong

2017-07-02 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 3 July 2017 at 03:57:25 UTC, Basile B wrote: 6.251 has no perfect double representation. It's real value is: I almost wonder if a BCD, fixed length or alternative for floating point should be an option... Either library, or a hook to change how the FPU works since doubles are

Re: Is D slow?

2017-06-09 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 9 June 2017 at 18:32:06 UTC, Steven Schveighoffer wrote: Wow, so that's how D code would look like if it were C++ :) When dipping my toes into C++ to do a quicksort algorithm, I quickly got annoyed I'd have to create all the individual comparison functions rather than just one

Re: .sort vs sort(): std.algorithm not up to the task?

2017-06-07 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 8 June 2017 at 02:19:15 UTC, Andrew Edwards wrote: Pretty funny. But seriously, this is something that should just work. There is now to layers of indirection to achieve what I used to do quite naturally in the language. Hmmm while working on my recent sudoku solver using

Re: rawRead using a struct with variable leght

2017-06-07 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 7 June 2017 at 18:31:41 UTC, H. S. Teoh wrote: "Structs" with variable size fields have no direct equivalent in D's type system, so you'll probably have a hard time mapping this directly. What you *could* do, though, is to load the data into a ubyte[] buffer, then create a

Re: rawRead using a struct with variable leght

2017-06-05 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 5 June 2017 at 16:04:28 UTC, ade90036 wrote: Unfortunately the struct doesn't know at compile time what the size of the constant_pool array, or at-least was not able to specify it dynamically. It also won't know ahead of time how many fields, methods or attributes you have

Re: Mixin in Inline Assembly

2017-06-02 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:00:45 UTC, Era Scarecrow wrote: So why is the offset off by 14h (20 bytes)? It's not like we need a to set a ptr first. Go figure i probably found a bug... Well as a side note a simple yet not happy workaround is making a new array slice of the memory and

Re: "Lazy" initialization of structs

2017-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: If I'm reading this right, in the former, the struct is created when the function is called in run-time, and the type is then inferred after that? I don't really understand the behavior behind this. The only difference

Re: Mixin in Inline Assembly

2017-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 03:33:38 UTC, Era Scarecrow wrote: From what I'm seeing, it should be 8, 0ch, 10h, then 14h, all positive. I'm really scratching my head why I'm having this issue... What am i missing here? More experiments and i think it comes down to static arrays. The

Re: purity question

2017-05-28 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 29 May 2017 at 01:12:53 UTC, Era Scarecrow wrote: ... Hmm didn't notice the post had split. Otherwise i wouldn't have replied... That and thinking about the GC state (outside of allocating memory)...

Re: purity question

2017-05-28 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 28 May 2017 at 23:49:16 UTC, Brad Roberts wrote: // do something arbitrarily complex with s that doesn't touch globals or change global state except possibly state of the heap or gc Sounds like the basic definition of pure to me; At least in regards to D. Memory allocation

Re: Sudoku Py / C++11 / D?

2017-05-26 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 15 August 2012 at 20:13:10 UTC, Era Scarecrow wrote: On Wednesday, 15 August 2012 at 15:39:26 UTC, ixid wrote: Could you supply your code? Which one are you using as the hardest? If you're solving the 1400 second one in 12 seconds that's very impressive, I can't get it below 240

Re: Sorted sequences

2017-05-25 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 25 May 2017 at 10:39:01 UTC, Russel Winder wrote: C++ has std:priority_queue as a wrapper around a heap to create a sorted queue. Am I right in thinking that D has no direct equivalent, that you have to build you own wrapper around a heap? Do you even need a wrapper? Glancing

Re: Mixin in Inline Assembly

2017-05-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 17:32:35 UTC, Era Scarecrow wrote: Still I think I'll impliment my own version and then if it's faster I'll submit it. Decided I'd give my hand at writing a 'ScaledInt' which is intended to basically allow any larger unsigned type. Coming across some

Re: No tempFile() in std.file

2017-05-15 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 15 May 2017 at 22:38:15 UTC, Jonathan M Davis wrote: Personally, I think that it would be very much worth making hello world larger, since hello world really doesn't matter, but because there are plenty of folks checking out D who write hello world and then look at the executable

Re: Porting Java code to D that uses << and >>> operators

2017-05-01 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 1 May 2017 at 21:04:15 UTC, bachmeier wrote: On Monday, 1 May 2017 at 18:16:48 UTC, Era Scarecrow wrote: Reminds me... was the unsigned shift >>> ever fixed? What was wrong with it? Doing a broad test I'm seeing an issue with short & byte versions... Course that's probably due

Re: Porting Java code to D that uses << and >>> operators

2017-05-01 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 1 May 2017 at 15:53:41 UTC, Basile B. wrote: It's the same code in D. It extracts consecutive bits in x12 and x13 (and maskxx), put them at the beginning (right shift) and add them. Reminds me... was the unsigned shift >>> ever fixed?

Re: Problems with Zlib - data error

2017-04-21 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 21 April 2017 at 17:40:03 UTC, Era Scarecrow wrote: I think I'll just go with full memory compression and make a quick simple filter to manage the large blocks of 0's to something more manageable. That will reduce the memory allocation issues. Done and I'm happy with the results.

Re: Problems with Zlib - data error

2017-04-21 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 21 April 2017 at 12:57:25 UTC, Adam D. Ruppe wrote: But I didn't realize your thing was a literal example from the docs. Ugh, can't even trust that. Which was a larger portion of why I was confused by it all than otherwise. Still, it's much easier to salvage if I knew how the

Re: Problems with Zlib - data error

2017-04-21 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 20 April 2017 at 20:24:15 UTC, Adam D. Ruppe wrote: In short, byChunk reuses its buffer, and std.zlib holds on to the pointer. That combination leads to corrupted data. Easiest fix is to .dup the chunk... So that's what's going on. But if I have to dup the blocks then I have

Problems with Zlib - data error

2017-04-20 Thread Era Scarecrow via Digitalmars-d-learn
I took the UnCompress example and tried to make use of it, however it breaks midway through my program with nothing more than 'Data Error'. [code] //shamelessly taken for experimenting with UnCompress decmp = new UnCompress; foreach (chunk; stdin.byChunk(4096).map!(x => decmp.uncompress(x)))

Re: Duplicated functions not reported?

2017-04-16 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 15 April 2017 at 11:10:01 UTC, Stefan Koch wrote: It would requires an O(n^2) check per declaration. Even it is never used. which would make imports that much more expensive. Seems wrong to me... If you made a list/array of all the functions (based purely on signatures) then

Re: Error: out of memory

2017-03-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 18 March 2017 at 20:39:20 UTC, StarGrazer wrote: I have some CTFE's and meta programming that cause dmd to run out of memory ;/ I am generating simple classes, but a lot of them. dmd uses about 2GB before it quits. It also only uses about 12% of cpu. I've noticed heavy use of

Re: Using chunks with Generator

2017-03-14 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 14 March 2017 at 10:00:24 UTC, Tetiana wrote: Build fails with the following error: Just looking at the Documentation, Generator is an InputRange and chunks requires a ForwardRange (able to use save functionality). So the API doesn't match up more or less.

Re: simple static if / traits question...

2017-02-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 22 February 2017 at 21:27:47 UTC, WhatMeWorry wrote: I'm doing conditional compilation using static ifs like so: enum bool audio = true; // if audio flag is present and set to true, add to code build static if ( (__traits(compiles, audio)) && audio)

Re: How do I use CTFE to generate an immutable associative array at compile time?

2017-02-21 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 22:34:57 UTC, Chad Joan wrote: In this case the AA isn't actually coded into the executable; but at least the configuration from some_data.csv will be in the executable as a string. The program will construct the AA at startup. It's not as "cool", but it

Re: Can this implementation of Damm algorithm be optimized?

2017-02-12 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 13 February 2017 at 00:56:37 UTC, Nestor wrote: On Sunday, 12 February 2017 at 05:54:34 UTC, Era Scarecrow wrote: Ran some more tests. Wow! Thanks for the interest and effort. Certainly. But the bulk of the answer comes down that the 2 levels that I've already provided are the

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 11 February 2017 at 21:56:54 UTC, Era Scarecrow wrote: Just ran the unittests under the dmd profiler, says the algorithm is 11% faster now. So yeah slightly more optimized. Ran some more tests. Without optimization but with with 4 levels (a 2.5Mb table), it gains to a whopping

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 12 February 2017 at 00:43:55 UTC, Nestor wrote: I fail to see where you are declaring QG10Matrix2, because apparently it's an array of chars, but buildMatrix2 returns an array of int (2560 elements??) with lots of -1 values. I declared it here:

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 11 February 2017 at 21:41:11 UTC, Era Scarecrow wrote: But it seriously is a lot of overhead for such a simple function. Just ran the unittests under the dmd profiler, says the algorithm is 11% faster now. So yeah slightly more optimized. Another level and we could probably

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 11 February 2017 at 21:02:40 UTC, Era Scarecrow wrote: Yes i know, which is why i had 3 to calculate 2 inputs because the third is the temp/previous calculation. Alright I've found the bug and fixed it, and it passes with flying colors (brute force tests up to 6 digits);

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 11 February 2017 at 20:19:51 UTC, Nestor wrote: Notice this is no ordinary matrix, but an Anti-Simmetric QuasiGroup of order 10, and tmpdigit (called interim in the algorithm) is used in each round (although the function isn't recursive) together with each digit to calculate final

Re: Can this implementation of Damm algorithm be optimized?

2017-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 10 February 2017 at 11:27:02 UTC, Nestor wrote: Thank you for the detailed reply. I wasn't able to follow you regarding the multilevel stuff though :( The idea behind it is like this (which you can scale up): static immutable int[] QG10Matrix2 = buildMatrix2(); int[]

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 9 February 2017 at 19:39:49 UTC, Nestor wrote: OK I changed the approach using a multidimensional array for the matrix so I could ditch arithmetic operations altogether, but curiously after measuring a few thousand runs of both implementations through avgtime, I see no noticeable

Re: Can this implementation of Damm algorithm be optimized?

2017-02-09 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 9 February 2017 at 17:36:11 UTC, Nestor wrote: I was trying to port C code from the article in Wikiversity [1] to D, but I'm not sure this implementation is the most efficient way to do it in D, so suggestions to optimize it are welcome: import std.stdio; static immutable

Re: Is there anything fundamentally wrong with this code?

2017-02-04 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 3 February 2017 at 18:37:15 UTC, Johan Engelen wrote: The error is in this line. Instead of assigning to the `postProc` at module scope, you are defining a new local variable and assigning to it. Wasn't the compiler suppose to warn you when you are shadowing another variable? Or

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-27 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 27 January 2017 at 07:02:52 UTC, Jack Applegame wrote: On Monday, 16 January 2017 at 14:47:23 UTC, Era Scarecrow wrote: static char[1024*4] buffer; //4k reusable buffer, NOT thread safe Maybe I'm wrong, but I think it's thread safe. Because static mutable non-shared variables

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-26 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 17 January 2017 at 11:40:15 UTC, Nestor wrote: Thanks, but unfortunately this function does not produce proper UTF8 strings, as a matter of fact the output even starts with the BOM. Also it doesn't handle CRLF, and even for LF terminated lines it doesn't seem to work for lines

Re: Parsing a UTF-16LE file line by line, BUG?

2017-01-16 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 15 January 2017 at 19:48:04 UTC, Nestor wrote: I see. So correcting my original doubt: How could I parse an UTF16LE file line by line (producing a proper string in each iteration) without loading the entire file into memory? Could... roll your own? Although if you wanted it to be

Re: writeln and ~

2017-01-14 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 14 January 2017 at 17:42:05 UTC, Ignacious wrote: Why can't string concatenation automatically try to convert the arguments? Is there any reason this is bad behavior? Somehow I think that everything implicitly converting to a string seems like a bad idea. Although writefln

Re: Referring to array element by descriptive name

2017-01-14 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 14 January 2017 at 15:11:40 UTC, albert-j wrote: Is it possible to refer to an array element by a descriptive name, just for code clarity, without performance overhead? E.g. void aFunction(double[] arr) { double importantElement = arr[3]; ... use importantElement ... }

Re: Merging two arrays in a uniform order

2017-01-13 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 13 January 2017 at 19:47:38 UTC, aberba wrote: awesome. roundRobin? :) https://dlang.org/phobos/std_range.html#.roundRobin [quote] roundRobin(r1, r2, r3) yields r1.front, then r2.front, then r3.front, after which it pops off one element from each and continues again from r1. For

Re: Mixin in Inline Assembly

2017-01-11 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 11 January 2017 at 15:39:49 UTC, Guillaume Piolat wrote: On Wednesday, 11 January 2017 at 06:14:35 UTC, Era Scarecrow wrote: Suddenly reminds me some of the speedup assembly I was writing for wideint, but seems I lost my code. too bad, the 128bit multiply had sped up and the

Re: Mixin in Inline Assembly

2017-01-10 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 10 January 2017 at 10:41:54 UTC, Basile B. wrote: don't forget to flag asm pure nothrow {} otherwise it's slow. Suddenly reminds me some of the speedup assembly I was writing for wideint, but seems I lost my code. too bad, the 128bit multiply had sped up and the division needed

Re: Getch() Problem: C vs D

2017-01-09 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 9 January 2017 at 20:12:38 UTC, Adam D. Ruppe wrote: Probably a bug, though I don't like using the getch function, I usually use the full input stream. For direct interactions (a game menu or similar) getting individual characters makes sense; I can't help but think Rogue-likes.

Re: Getch() Problem: C vs D

2017-01-08 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 8 January 2017 at 21:19:15 UTC, LouisHK wrote: And works fine, but the D version below nothing happens when I hit ESCAPE: Is this a bug or there is another approach? Could this be because of maybe somehow it handles the console input? Kinda like how shift and different keys are

Re: Stack Space & Ackermann

2017-01-05 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 5 January 2017 at 07:30:02 UTC, H. S. Teoh wrote: Nonetheless, even if you optimize said code paths, you still won't be able to get any sane results for m>4 or anything beyond the first few values for m=4. The Ackermann function is *supposed* to be computationally intractible --

Re: Stack Space & Ackermann

2017-01-04 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 5 January 2017 at 06:20:28 UTC, rikki cattermole wrote: foreach(i; 0 .. 6) No need for iota. I thought that particular slice/range was depreciated. Still the few k that are lost in the iota doesn't seem to make a difference when i run the code again.

Re: Stack Space & Ackermann

2017-01-04 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 5 January 2017 at 04:53:23 UTC, rikki cattermole wrote: Well, you could create a fiber[0]. Fibers allow you to set the stack size at runtime. [0] http://dlang.org/phobos/core_thread.html#.Fiber.this Well that certainly does seem to do the trick. Unfortunately I didn't get the

Stack Space & Ackermann

2017-01-04 Thread Era Scarecrow via Digitalmars-d-learn
Well re-watched a video regarding the Ackermann function which is a heavily recursive code which may or may not ever give a result in our lifetimes. However relying on the power of memoize I quickly find that when the program dies (from 5 minutes or so) nearly instantly (and only using 9Mb of

Re: How to initialize a associative array?

2016-12-24 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: What's the correct way? You cannot initialize an AA at compile-time. Because AA's are provided by druntime and the ABI is not stable. For fun I'm throwing

Re: help on cartesianProduct()

2016-12-12 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 12 December 2016 at 14:27:07 UTC, Orut wrote: The code works beautifully! Thank you very much. Will certainly acknowledge you as source of this code if this becomes of part of a bigger project. I hope others searching this forum would also discover this code. It could probably

Re: help on cartesianProduct()

2016-12-11 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 11 December 2016 at 18:05:19 UTC, Era Scarecrow wrote: On Sunday, 11 December 2016 at 16:34:38 UTC, Orut wrote: I need to be able to vary the number of ranges to feed into cartesianProduct() at run time. Hmmm... what kind of ranges? Are they going to be arrays? Or something else?

Re: Separate IP parts

2016-12-11 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 10 December 2016 at 03:51:34 UTC, brocolis wrote: How do I separate IP parts with dlang? I found this very cool trick, with C++: http://stackoverflow.com/a/5328190 Heh, I'd prefer to use sscanf vs using the streams.

Re: help on cartesianProduct()

2016-12-11 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 11 December 2016 at 16:34:38 UTC, Orut wrote: I need to be able to vary the number of ranges to feed into cartesianProduct() at run time. In Python, this is possible because I can dynamically construct a list of lists, then unpack this list using the unpacking operator when it is

Re: How to get hash value of an object?

2016-12-04 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 29 November 2016 at 00:05:31 UTC, Steven Schveighoffer wrote: hashOf is kind of this horrible hacky thing that nobody should be using. It literally takes whatever you pass it and hashes the local bytes. Ugg... Anything with pointers, classes or arrays will have huge problems

Re: non-constant expression ["foo":5, "bar":10, "baz":2000]

2016-11-28 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 28 November 2016 at 09:06:34 UTC, Paolo Invernizzi wrote: The point is that I was trying to avoid some cycle between modules, detected by 2.072. This bug leads to pollution in the use of static this only to workaround the limitation... Wasn't someone working on a Associative Array

Re: A simplification of the RvalueRef idiom

2016-11-22 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 22 November 2016 at 16:05:35 UTC, Satoshi wrote: Sorry, but D seems to be worse and worse day by day. This should be resolved by language and not doing it by template function. Same thing should be applied for maybe monad and tuples. I'm reminded of trying to follow the rules

Re: Array operations with multidimensional arrays

2016-11-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 November 2016 at 21:05:49 UTC, John Colvin wrote: On Saturday, 19 November 2016 at 19:36:50 UTC, Marduk wrote: Thanks a lot! Now I get what it means that array declarations are read from right to left. The way I think about it is this: int is a type. int[3] is an array of 3

Re: what is mean? ( Offset 78887H Record Type 00C3)

2016-11-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 November 2016 at 07:12:49 UTC, Nicholas Wilson wrote: If you're using x64 then you should be using the microsoft linker. are you invoking the linker manually? I would guess that some files are old and compiled separately, and the source was changed at some point. But we

Re: Why double not? (!!)

2016-11-18 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 November 2016 at 04:54:22 UTC, Xinok wrote: On Saturday, 19 November 2016 at 03:52:02 UTC, Ryan wrote: Why do I see double `not` operators sometimes in D code? An example it the last post of this thread. http://forum.dlang.org/thread/ktlpnikvdwgbvfaam...@forum.dlang.org

Re: Variable-Length Bit-Level Encoding

2016-11-12 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 12 November 2016 at 19:13:13 UTC, Nordlöw wrote: 0 => [0] 1 => [1,0] 2 => [1,1,0] is easy but assumes a too extreme input value distribution. Does anybody have a suggestion for an encoder that is more suitable for real-world values that are, for instance, normally distributed?

Re: typeof(SortedRange) and is operator

2016-11-08 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 21:14:41 UTC, Jonathan M Davis wrote: No, as the others have point out, it's not a bug. If anything it's a language design flaw that no one has figured out how to resolve yet. The idea of a special struct for code that strips whitespace out, or a function that

Re: how to debug memory errors

2016-11-08 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 11:26:55 UTC, bachmeier wrote: Is there a valid use case for something like this? Why would you want to do anything inside ~this with GC memory? If we assume it's a C++ attachment/library/object using different memory allocation?

Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 06:04:59 UTC, thedeemon wrote: On Tuesday, 8 November 2016 at 05:36:22 UTC, Era Scarecrow wrote: Hmmm.. I had the impression that if something was referenced by another object, then it couldn't be collected, Another *live* object, I.e. reachable from globals

Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 November 2016 at 03:27:32 UTC, Steven Schveighoffer wrote: Err that makes no sense... If that's the case why have a destructor at all? To free non-GC resources. http://dlang.org/spec/class.html#destructors "Furthermore, the order in which the garbage collector calls

Re: how to debug memory errors

2016-11-07 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 7 November 2016 at 02:22:35 UTC, Steven Schveighoffer wrote: OP: it's not legal to destroy or even access GC allocated members in a destructor. The GC may have already destroyed that data. I would recommend printing the stack trace when you get the exception, and figure out where

Re: Sockets and using them...

2016-11-06 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 6 November 2016 at 09:51:41 UTC, sarn wrote: It sounds like you want to do the same thing: design a protocol that includes some kind of message that's agreed to mean, "Yo, make a new connection on this port." Basically, any off-the-shelf textbook on network protocol design will

Sockets and using them...

2016-11-06 Thread Era Scarecrow via Digitalmars-d-learn
So I've got a project where I want to create basically a decentralized chat program where every program is a host and a client. When you connect all connections can go through to route the chat to everyone else. So to make this work I've looked over the sockets package and I don't quite

Re: New to D

2016-10-27 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 27 October 2016 at 13:43:26 UTC, Steven Schveighoffer wrote: It depends on the size of the file and the expectation of duplicate words. I'm assuming the number of words is limited, so you are going to allocate far less data by duping on demand. In addition, you may incur penalties

Re: D1: zlib string to decode

2016-09-08 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 8 September 2016 at 16:19:44 UTC, jicman wrote: I have a zlib string that I want to decode. Anybody has any idea how to do that? I am trying to figure out what to send with a POST to create a new internal log and the person that created the form is no longer available, but I

Re: nested inout return type

2016-06-14 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 19:48:06 UTC, Steven Schveighoffer wrote: I honestly think the best place to go figure these things out is stackoverflow (or just the internet in general). Whenever I have a technical problem I can't figure out (or am too lazy to diagnose myself), I search and SO

Re: nested inout return type

2016-06-14 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 14 June 2016 at 14:47:11 UTC, Steven Schveighoffer wrote: On Tuesday, 14 June 2016 at 01:50:17 UTC, Era Scarecrow wrote: return cast(inout(Slice)) Slice(cast(T*)ptr+a, b-a); Better: inout(Slice)(ptr+a, b-a); Of course... My amateur D-fu skills show themselves. cast()

Re: Gotchas for returning values from blocks

2016-06-13 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 13 June 2016 at 14:16:58 UTC, jmh530 wrote: So returning a reference to something on the stack is a bad idea, but copying the value would be fine. This is easy enough to get wrong elsewhere too. I recall having an issue with a foreach, until I added a 'ref' to it. Looking at the

Re: Gotchas for returning values from blocks

2016-06-12 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 12 June 2016 at 18:24:58 UTC, jmh530 wrote: I'm just not sure if there are any gotchas to be aware of. Aside from forgetting it's it's own block, you might add a return statement to it and leave the entire function. Or forget what's in what scope (assuming you do more than 1-2

Re: Fibers, what for?

2016-06-11 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 12 June 2016 at 02:43:40 UTC, Patric Dexheimer wrote: I learned about Fibers on D, and now I´m starting to read about it (Threads/Fibers/Coroutines) etc. But when I try to make something usefull with it I just fail to see the real advantage over a normal structured programming

Re: Why I can't catch the exception?

2016-06-05 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 5 June 2016 at 18:15:47 UTC, Adam D. Ruppe wrote: On Sunday, 5 June 2016 at 18:02:12 UTC, Suliman wrote: I really can't understand why try-catch block do not handle exception. digit 1 is printing, so exception is accrue after it, but why nothing in catch block?

Re: Can I get a more in-depth guide about the inline assembler?

2016-06-03 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 4 June 2016 at 01:44:38 UTC, ZILtoid1991 wrote: Problem solved. Current assembly code: //moving the values to their destinations mov EBX, p[EBP]; movdMM0, src; movdMM1, [EBX]; The actual problem was the poor documentation of MMX instructions as it never really

Re: Can I get a more in-depth guide about the inline assembler?

2016-06-02 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 2 June 2016 at 13:32:51 UTC, ZILtoid1991 wrote: On Thursday, 2 June 2016 at 07:17:23 UTC, Johan Engelen wrote: Could you also paste the D version of your code? Perhaps the compiler (LDC, GDC) will generate similarly vectorized code that is inlinable, etc. ubyte[4] dest2 = *p;

Re: opCall override default constructor?

2016-06-02 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 2 June 2016 at 08:50:26 UTC, Jacob Carlborg wrote: Is it intentional that a non-static opCall overrides the default constructor of a struct? auto f = Foo(3); // line 14 main.d(14): Error: function main.Foo.opCall (string b) is not callable using argument types (int) It

Re: Can I get a more in-depth guide about the inline assembler?

2016-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 2 June 2016 at 00:52:48 UTC, ZILtoid1991 wrote: On Thursday, 2 June 2016 at 00:51:15 UTC, ZILtoid1991 wrote: I could get the code working with a bug after replacing pmulhuw with pmullw, but due to integer overflow I get a glitched image. I try to get around the fact that pmulhuw

Re: Can I get a more in-depth guide about the inline assembler?

2016-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 1 June 2016 at 23:23:49 UTC, ZILtoid1991 wrote: After some debugging, I found out that the p pointer becomes null at the end instead of pointing to a value. I have no experience with using in-line assemblers (although I made a few Hello World programs for MS-Dos with a

  1   2   >