Re: Infinite fibonacci sequence, lazy take first 42 values

2022-04-21 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 21 April 2022 at 04:36:13 UTC, Salih Dincer wrote: My favorite is the struct range. Because it is more understandable and personalized. Moreover, you can limit it without using ```take()```. And it's inherently lazy, so no extra processing/calculation other than what's

Re: Beginner memory question.

2022-04-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 16 April 2022 at 20:48:15 UTC, Adam Ruppe wrote: On Saturday, 16 April 2022 at 20:41:25 UTC, WhatMeWorry wrote: Is virtual memory entering into the equation? Probably. Memory allocated doesn't physically exist until written to a lot of the time. This might be very much an OS

Re: Can Enums be integral types?

2022-04-19 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 19 April 2022 at 13:20:21 UTC, Bastiaan Veelo wrote: There is nothing that requires enum values to be unique, though: ```d import std; void main() { enum E {Zero = 0, One = 0, Two = 0} writeln(E.Two); // Zero! } ``` True, but if you want it be useful they really need to be

Re: Can Enums be integral types?

2022-04-18 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 17 April 2022 at 18:25:32 UTC, Bastiaan Veelo wrote: On Saturday, 16 April 2022 at 11:39:01 UTC, Manfred Nowak wrote: In the specs(17) about enums the word "integral" has no match. But because the default basetype is `int`, which is an integral type, enums might be integral types

Re: How to implement this?

2022-04-07 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:54:35 UTC, Era Scarecrow wrote: Maybe it should be `cast(A*) `? Confusing HTML entities bit on here. Probably just ignore it. Maybe you are doing it backwards. What if you had ```d struct B { A* a; } A[] arraylist; ``` then in the init append a new item to

Re: How to implement this?

2022-04-07 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 8 April 2022 at 04:31:45 UTC, Elvis Zhou wrote: B b; init(\); structs ~= cast(A*)\ //Error: copying `cast(A*)\& b` into allocated memory escapes a reference to local variable `b` Maybe it should be `cast(A*) \`?

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 23 March 2022 at 00:51:42 UTC, Era Scarecrow wrote: On Tuesday, 22 March 2022 at 21:23:43 UTC, H. S. Teoh wrote: We already have this: import std.conv : to; int x; long y; y = x.to!long; // equivalent to straight assignment / cast x =

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 22 March 2022 at 21:23:43 UTC, H. S. Teoh wrote: On Tue, Mar 22, 2022 at 09:11 PM, Era Scarecrow wrote: [...] I'd almost wish D had a more lenient mode and would do automatic down-casting, then complain if it *would* have failed to downcast data at runtime. [...] We already

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 22 March 2022 at 18:47:19 UTC, Ali Çehreli wrote: On 3/22/22 11:28, Era Scarecrow wrote: > So when should you use size_t? I use size_t for anything that is related to count, index, etc. However, this is a contested topic because size_t is unsigned. I don't see a problem with

Re: Basic question about size_t and ulong

2022-03-22 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 18 March 2022 at 23:01:05 UTC, Ali Çehreli wrote: P.S. On a related note, I used to make the mistake of using size_t for file offsets as well. That is a mistake because even on a 32-bit system (or build), file sizes can be larger than uint.max. So, the correct type is long for

Re: Nested Classes with inheritance

2022-03-20 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 20 March 2022 at 05:44:44 UTC, Salih Dincer wrote: On Sunday, 20 March 2022 at 01:28:44 UTC, Era Scarecrow wrote: Inheritance and Polymorphism is one of the hardest things to grasp mostly because examples they give in other books of 'objects' is so far unrelated to software that it

Re: Nested Classes with inheritance

2022-03-19 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 March 2022 at 12:23:02 UTC, user1234 wrote: I think OP is learning OOP. His error looks like that for the least. True. Looking at the code it shouldn't spaghetti in on itself infinitely and is basically clean in his intent. Inheritance and Polymorphism is one of the hardest

Re: Nested Classes with inheritance

2022-03-18 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 19 March 2022 at 00:16:48 UTC, user1234 wrote: That crashes because of the creation of `Bar b` member, which itself has a Bar b member, which itself... Mhmm... So There's Foo with Bar b, which has Bar b which has Bar b which... just keeps going over and over again. It appears

Re: How to exclude function from being imported in D language?

2022-03-17 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 March 2022 at 22:28:27 UTC, bauss wrote: What D just needs is a way to specify the entry point, in which it just defaults to the first main function found, but could be any function given. Which is similar to what Java does. When i was first learning Java in a company i would

Re: static init c struct with array filed

2022-03-16 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 16 March 2022 at 11:27:20 UTC, user1234 wrote: assuming the c library takes by reference My experience all arrays are effectively just pointers, and the brackets/length is only really applicable to stack allocated fixed length allocations. In my own C projects i always used

Re: Strange behavior of iota

2022-02-15 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 15 February 2022 at 22:24:53 UTC, bachmeier wrote: On Tuesday, 15 February 2022 at 22:02:13 UTC, Adam D Ruppe wrote: for(a = v.length; a > cast(size_t) -1, a += -1) After looking at the documentation and seeing CommonType!(int, uint) is uint, I have to say that iota's behavior

Re: How to verify DMD download with GPG?

2022-02-14 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 10:17:19 UTC, Ola Fosheim Grøstad wrote: I do like the idea that a hacker cannot change the signature file if gaining access to the web/file hosts, but how to verify it in secure way? For Linux sources there's MD5 and SHA-1 hashes i believe. If you have two or

Re: how to handle very large array?

2022-02-12 Thread Era Scarecrow 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: thanks, very helpful! i am using a assocArray now... Are you sure that's what you need? Depends. if you do say TYPE[long/int] then you have

Re: How to work with hashmap from memutils properly?

2022-02-11 Thread Era Scarecrow via Digitalmars-d-learn
On Friday, 11 February 2022 at 02:43:24 UTC, Siarhei Siamashka wrote: Though this strange benchmark is testing performance of an LRU with ... wait for it ... 10 elements, which makes using hashmap/dict/AA a completely ridiculous idea. Hmmm... if it's static data i can see maybe a enum

Re: number ranges

2022-01-18 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 17 January 2022 at 22:28:10 UTC, H. S. Teoh wrote: This will immediately make whoever reads the code (i.e., myself after 2 months :D) wonder, "why +1?" And the answer will become clear and enlightenment ensues. ;-) In those cases i find myself rewriting said code. Generally to

Re: Throw stack trace from program kill

2022-01-16 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 16 January 2022 at 18:03:53 UTC, Paul Backus wrote: On POSIX, you can use the `sigaction` function to install a signal handler for `SIGINT`, the signal generated by CTRL+C. To terminate the program with a stack trace, simply have the signal handler `throw` an `Error`. I never

Re: Dynamic array or not

2022-01-16 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 16 January 2022 at 15:32:41 UTC, Salih Dincer wrote: If count is not equal to 8 I get weird results! The reason of course, is the free(): // [93947717336544, 1, 2, 3, 4, 5, 6] I wonder if you're seeing something you're not suppose to as part of the internals; Typically malloc for

Re: mixin does not work as expected

2022-01-05 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:40:15 UTC, rempas wrote: I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: Back

Re: print ubyte[] as (ascii) string

2021-12-30 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 30 December 2021 at 09:34:27 UTC, eugene wrote: The buffer contains (ascii) string terminated with '\n'. In order to print it not as an array of numbers (buf is 1024 bytes long), but as usual string I do Few years ago i asked a similar question, not to do UTF-8 but to do Ascii.

Re: AA and struct with const member

2021-12-29 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:11:13 UTC, Stanislav Blinov wrote: Because opIndexAssign cannot distinguish at compile time between initialization and assignment: ```d Stuff[Key] aa; aa[key] = Stuff(args); // ostensibly, initialization aa[key] = otherStuff; // assignment to existing

Re: AA and struct with const member

2021-12-28 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 07:51:04 UTC, frame wrote: On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: Success! So i summarize, either work with a pointer, or drop the const... Of course casting the const away was the first thing I did but I think this is not

Re: AA and struct with const member

2021-12-27 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: I feel stupid right now: One cannot assign a struct that contains const member to AA? Error: cannot modify struct instance ... of type ... because it contains `const` or `immutable` members This is considered a modification? ```d

Re: How to print unicode characters (no library)?

2021-12-27 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 27 December 2021 at 07:12:24 UTC, rempas wrote: On Sunday, 26 December 2021 at 21:22:42 UTC, Adam Ruppe wrote: write just transfers a sequence of bytes. It doesn't know nor care what they represent - that's for the receiving end to figure out. Oh, so it was as I expected :P

Re: First time using Parallel

2021-12-26 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 26 December 2021 at 15:36:54 UTC, Bastiaan Veelo wrote: On Sunday, 26 December 2021 at 15:20:09 UTC, Bastiaan Veelo wrote: So if you use `workerLocalStorage` ... you'll get your output in order without sorting. Scratch that, I misunderstood the example. It doesn't solve ordering.

Re: Double bracket "{{" for scoping static foreach is no longer part of D

2021-12-26 Thread Era Scarecrow via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 16:30:06 UTC, data pulverizer wrote: On Wednesday, 22 December 2021 at 16:10:42 UTC, Adam D Ruppe wrote: So OUTSIDE a function, static foreach() {{ }} is illegal because a plain {} is illegal outside a function. But INSIDE a function, static foreach() {{ }}

Re: First time using Parallel

2021-12-26 Thread Era Scarecrow via Digitalmars-d-learn
On Sunday, 26 December 2021 at 11:24:54 UTC, rikki cattermole wrote: I would start by removing the use of stdout in your loop kernel - I'm not familiar with what you are calculating, but if you can basically have the (parallel) loop operate from (say) one array directly into another then you

First time using Parallel

2021-12-25 Thread Era Scarecrow via Digitalmars-d-learn
This is curious. I was up for trying to parallelize my code, specifically having a block of code calculate some polynomials (*Related to Reed Solomon stuff*). So I cracked open std.parallel and looked over how I would manage this all. To my surprise I found ParallelForEach, which gives the

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

  1   2   3   >