check Input

2017-04-17 Thread dennis via Digitalmars-d-learn
Hi, try to build a little programm, but need to know how to check the input. For example: input only numbers: 0 - 9 but 1.5 for example is ok. thanks

Re: check Input

2017-04-17 Thread dennis via Digitalmars-d-learn
thank you all! i will try

DerelictGL3.reload(); crashes in release mode, but not in debug

2017-11-18 Thread Dennis via Digitalmars-d-learn
I'm trying to set up a game window with Derelict glfw and opengl. When I perform a default (debug) build, it correctly shows a window, but when I do this: dub run "--build=release" Then I get this: object.Error@(0): Access Violation 0x00443BCF 0x00425164 0x00418545 0x00418874

Re: DerelictGL3.reload(); crashes in release mode, but not in debug

2017-11-18 Thread Dennis via Digitalmars-d-learn
On Saturday, 18 November 2017 at 14:15:21 UTC, Mike Parker wrote: The proper place to report this sort of issue is at the DerelictGL3 issues page [1]. You'll also want to include some minimal, reproducible sample code. Okay, I've made an issue:

File.byLine for either Windows / Unix newlines

2017-12-11 Thread Dennis via Digitalmars-d-learn
I'm on Windows and I recently got confused by how Phobos functions handle newlines. ``` void main() { import std.stdio; import std.path : buildPath, tempDir; auto path = buildPath(tempDir(), "test.txt"); auto file = new File(path, "w"); file.write("hello there!\n");

Re: File.byLine for either Windows / Unix newlines

2017-12-11 Thread Dennis via Digitalmars-d-learn
Thanks for your reply, that clears it up. On Monday, 11 December 2017 at 21:13:11 UTC, Steven Schveighoffer wrote: 3. Stop using Windows ;) Haha, if only the rest of the userbase would follow.

Re: Splitting up large dirty file

2018-05-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 02:47:50 UTC, Jon Degenhardt wrote: Can you show the program you are using that throws when using byLine? Here's a version that only outputs the first chunk: ``` import std.stdio; import std.range; import std.algorithm; import std.file; import std.exception; void

Splitting up large dirty file

2018-05-15 Thread Dennis via Digitalmars-d-learn
I have a file with two problems: - It's too big to fit in memory (apparently, I thought 1.5 Gb would fit but I get an out of memory error when using std.file.read) - It is dirty (contains invalid Unicode characters, null bytes in the middle of lines) I want to write a program that splits it

Re: Splitting up large dirty file

2018-05-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 08:20:06 UTC, drug wrote: What is the purpose of `.drop(4)`? I'm pretty sure this is the reason of the exception. The file in question is a .json database dump with an array "rows" of 10 million 8-line objects. The newlines in the string fields are escaped, but

Re: Splitting up large dirty file

2018-05-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 08:20:06 UTC, drug wrote: What is the purpose of `.drop(4)`? I'm pretty sure this is the reason of the exception. The file in question is a .json database dump with an array "rows" of 10 million 8-line objects. The newlines in the string fields are escaped, but

Re: UFCS syntax I never saw before.

2018-05-21 Thread Dennis via Digitalmars-d-learn
On Monday, 21 May 2018 at 11:38:12 UTC, SrMordred wrote: what?? Here's another weird example: ``` void funWithUfcsAndPropertySyntax() { import std.typecons : tuple; "%s %s".writefln = ("foo".tuple = "bar").expand; } ``` source:

Re: Splitting up large dirty file

2018-05-21 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 May 2018 at 21:10:35 UTC, Dennis wrote: It's unfortunate that Phobos tells you 'there's problems with the encoding' without providing any means to fix it or even diagnose it. I have to take that back since I found out about std.encoding which has functions like `sanitize`,

Re: Splitting up large dirty file

2018-05-21 Thread Dennis via Digitalmars-d-learn
On Monday, 21 May 2018 at 17:42:19 UTC, Jonathan M Davis wrote: On Monday, May 21, 2018 15:00:09 Dennis via Digitalmars-d-learn wrote: drop is range-based, so if you give it a string, it's going to decode because of the whole auto-decoding mess with std.range.primitives.front and popFront

Re: Splitting up large dirty file

2018-05-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 10:30:34 UTC, Jonathan M Davis wrote: For various reasons, that doesn't always hold true like it should, but pretty much all of Phobos is written with that assumption and will generally throw an exception if it isn't. It's unfortunate that Phobos tells you

Re: Splitting up large dirty file

2018-05-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 May 2018 at 15:47:29 UTC, Jon Degenhardt wrote: If you write it in the style of my earlier example and use counters and if-tests it will work. byLine by itself won't try to interpret the characters (won't auto-decode them), so it won't trigger an exception if there are invalid

Re: foreach DFS/BFS for tree data-structure?

2018-06-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 June 2018 at 11:31:50 UTC, Robert M. Münch wrote: Is this possible? I read about Inputranges, took a look at the RBTree code etc. but don't relly know/understand where to start. You can also use opApply to iterate over a tree using foreach, see:

Re: How are switches optimized

2018-06-02 Thread Dennis via Digitalmars-d-learn
On Friday, 1 June 2018 at 21:18:25 UTC, IntegratedDimensions wrote: If one has a switch of N case then the last cost surely does not cost N times the cost of the first, approximately? It depends on the compiler and optimization level. In general, no optimization or just a handful of cases

Re: Elegant way to use dynamic bindings

2018-02-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 February 2018 at 14:51:30 UTC, Mike Parker wrote: Where was the lib file located? Was it in the root project directory? How are you compiling your project? What does your directory tree look like? (...) That depends. Is that the directory where your executable is written? Are you

Re: Elegant way to use dynamic bindings

2018-02-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 February 2018 at 18:14:06 UTC, Mike Wey wrote: You may need to pass `/s` to implib so it will add the underscore to the symbol in the import library. If it's actually needed depends on what the dll uses. That did it, now both dynamic loading and dynamic linking work. :) Thanks

Elegant way to use dynamic bindings

2018-02-09 Thread Dennis via Digitalmars-d-learn
I want to bind to a .dll on Windows, so I looked at how Derelict packages are doing it and found it does it like this: ``` extern(C) { alias da_CoreGetAPIVersions = m64p_error function(int*,int*,int*,int*); ... } __gshared { da_CoreGetAPIVersions CoreGetAPIVersions; ... } protected

Re: Elegant way to use dynamic bindings

2018-02-09 Thread Dennis via Digitalmars-d-learn
I read the Derelict documentation a while ago, I didn't grasp all of it. Reading it again, I can now make sense of it though. :) On Friday, 9 February 2018 at 12:53:44 UTC, Mike Parker wrote: Did you link with the library you created with implib? That linker error suggests you didn't. I

Re: Link to https://run.dlang.io/ ??

2018-02-20 Thread Dennis via Digitalmars-d-learn
I recently tried to go to that site, and I tried `run.dlang.com` which is the wrong URL. So I was looking through the D homepage for the right link but couldn't find it. Even a Google search for "online d compiler" or "run dlang online" didn't turn up anything directly, I had to go through the

bitmanip : read does not accept my array slice

2017-12-26 Thread Dennis via Digitalmars-d-learn
I was trying to translate this kind of C code to D: void calc(unsigned char *buf) { (...) res = read_u32_be([i]); } So I tried this: import std.bitmanip : read, Endian; void calc(ubyte[] buf) { (...) res = read!(uint, Endian.bigEndian)(buf[i..$]); } But then I get this error: template

Re: bitmanip : read does not accept my array slice

2017-12-26 Thread Dennis via Digitalmars-d-learn
Ah, so it's about lvalues an rvalues, not the type of the range. Makes sense now. On Tuesday, 26 December 2017 at 22:33:54 UTC, WebFreak001 wrote: BigEndian is default btw, you don't need to specify that but you can if you want. Dealing with Endianness bugs has been such a pain, I like to be

Re: Prime number

2018-08-02 Thread Dennis via Digitalmars-d-learn
On Thursday, 2 August 2018 at 08:30:05 UTC, Greatsam4sure wrote: I know D is very powerful from my little experience. What is the idiomatic way to get prime numbers say from 1-30 without using loops(outer and inner loop). Can map, filter, fold etc in algorithm be use. Pls show some code with

Static initialization of static arrays is weird

2018-08-19 Thread Dennis via Digitalmars-d-learn
I have a two dimensional static array in a game board struct and want to explicitly set the default value for each cell. Now typing the whole 9x9 array out would be cumbersome and I can't change the default constructor of a struct, so I played around with initializers and found some... strange

Re: Static initialization of static arrays is weird

2018-08-19 Thread Dennis via Digitalmars-d-learn
On Sunday, 19 August 2018 at 12:10:08 UTC, kinke wrote: I think the spec is pretty clear; the elements of the right-hand-side initializer array are interpreted as per-element initializer, i.e., `result[0] = 2, result[1] = 1` (rest: default-init). I can't find where in the spec it says that

Re: anyway to debug nogc code with writeln?

2018-09-02 Thread Dennis via Digitalmars-d-learn
On Saturday, 1 September 2018 at 21:53:03 UTC, aliak wrote: Anyway around this? I don't know if your situation allows it, but you can mark f explicitly as always @nogc. If your design assumes that it's @nogc, it's a good idea to add the attribute anyway. You can also use the C printf

Re: "immutable string" vs "const string*"

2018-09-09 Thread Dennis via Digitalmars-d-learn
On Sunday, 9 September 2018 at 08:41:37 UTC, Christian Mayer wrote: As of my current understanding "char" will create a new variable and copy the content of the original to the new variable. "char*" will just use the pointer. And "const char*" is good for when not modifying. But I also can

Re: Elegant way to use dynamic bindings

2018-03-08 Thread Dennis via Digitalmars-d-learn
On Friday, 9 February 2018 at 20:19:33 UTC, Dennis wrote: I'd still like to find a nice way to generate the boilerplate code for dynamic loading, if I come up with something I'll post it here. So I ended up using an import library for a while, but I then wanted to get the handle of the DLL,

Re: "%s"-format template function arguments

2018-04-15 Thread Dennis via Digitalmars-d-learn
On Sunday, 15 April 2018 at 12:04:19 UTC, vladdeSV wrote: How would I go on about to print all the arguments as I expected it, using "%s"? You can expand the template arguments into an array by putting it into square brackets: [args]. You can format an array with the default notation using

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 13:57:14 UTC, Vladimirs Nordholm wrote: Is there any reason for me to add the @property tags for the method? A list of things the @property tag does can be found here: https://dlang.org/spec/function.html#property-functions This behavior is particularly useful for

Re: @property for simple methods?

2018-04-02 Thread Dennis via Digitalmars-d-learn
On Monday, 2 April 2018 at 14:51:57 UTC, Vladimirs Nordholm wrote: Do you think I should I omit the @property tag, if the only wanted behaviour is to set a value (`foo.bar = "baz";`) ? You're probably fine either way, it's mostly for making your intention clear. Jonathan M Davis made a great

Re: how to correctly populate an array of dynamic closures?

2018-03-29 Thread Dennis via Digitalmars-d-learn
On Thursday, 29 March 2018 at 15:16:07 UTC, Ivan Kazmenko wrote: So, why do delegates of guns[] and huns[] all return 1, and how to correctly reproduce the behavior of funs[] while populating it in a loop? A delegate is a function with a pointer to the stack frame where it was created. It

Re: Slow start up time of runtime

2018-03-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 10:20:55 UTC, Dennis wrote: On Tuesday, 20 March 2018 at 09:51:09 UTC, bauss wrote: Besides if it was and it took 1 second to startup, then it wouldn't matter in practice with an actual application. This is not concerning for large applications indeed. But say, I

Re: Slow start up time of runtime

2018-03-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 09:51:09 UTC, bauss wrote: Besides if it was and it took 1 second to startup, then it wouldn't matter in practice with an actual application. This is not concerning for large applications indeed. But say, I want to implement my own `dir` (= `ls` on Unix) in D.

Slow start up time of runtime

2018-03-20 Thread Dennis via Digitalmars-d-learn
Simply running a "hello world.exe" takes, on my pc: 1.12s When compiled with dmd 0.62s When compiled with ldc 0.05s When compiled with dmc (C program) or dmd/ldc as a -betterC program I suppose initializing the runtime takes a lot of time. When making a simple command line utility, half a

Re: Slow start up time of runtime (correction: Windows real-time protection)

2018-03-21 Thread Dennis via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 13:26:48 UTC, HeiHon wrote: I added exclusions for the folder, where I installed dmd and ldc and I added an exclusion for the folder, where I compile my D programs. Now startup of dmd and freshly compiled programs is fast again. I've done this too now, thanks

Re: Logging Function Parameters

2018-03-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 March 2018 at 22:57:15 UTC, aliak wrote: // But you get a: // Error: Using the result of a comma expression is not allowed // writeln(mixin(arguments!f)); You can't mix part of a function call in: "Mixed in text must form complete declarations, statements, or

Re: Slow start up time of runtime (correction: Windows real-time protection)

2018-03-20 Thread Dennis via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 12:18:16 UTC, Adam D. Ruppe wrote: On Tuesday, 20 March 2018 at 09:44:41 UTC, Dennis wrote: I suspect you are seeing the Windows antivirus hitting you. D runtime starts up in a tiny fraction of a second, you shouldn't be noticing it. You're totally right,

importing std.array: empty in a struct messes things up

2018-03-04 Thread Dennis via Digitalmars-d-learn
I was making a stack interface for an array: ``` struct Stack(T) { import std.array: empty; T[] stack; alias stack this; } void main() { Stack!int stack; bool x = stack.empty; } ``` My expectation is that you can now call `empty` on a stack instance since I imported it in

Re: Alligned gc allocation of struct

2018-10-05 Thread Dennis via Digitalmars-d-learn
On Friday, 5 October 2018 at 10:03:35 UTC, Kagamin wrote: GC allocations are 16 bytes aligned. Is that an implementation detail or well-defined behavior?

Re: why is the default floating point value NAN ?

2018-10-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 15:51:21 UTC, Codifies wrote: okay I should have carried on reading the blog, its so uninitialized values stick out when debugging... Indeed, the initial value is not supposed to be useful, it's there because dealing with garbage memory when forgetting to

Re: Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 17 October 2018 at 00:12:13 UTC, H. S. Teoh wrote: I'm not sure what's the reasoning behind the saying that throwing exceptions in ctors is bad, but exceptions are exactly the kind of thing designed for handling this sort of situation. If the parser detects a problem early (i.e.,

Dealing with ranges where front and popFront do the same logic / eager ranges

2018-10-16 Thread Dennis via Digitalmars-d-learn
I've always been curious around the design choice of ranges to make front and popFront separate functions, instead of having popFront return the front. I suppose it is useful sometimes to be able to access front multiple times without having to save it temporarily (can't think of a specific

Re: Putting dmd error through grep for dustmite

2018-11-05 Thread Dennis via Digitalmars-d-learn
On Monday, 5 November 2018 at 03:13:26 UTC, Vladimir Panteleev wrote: cmd.exe will interpret \` verbatim (i.e. as \`), so, try not quoting the ` characters (or just replace them with . if you want the command to work in both shells). Of course, the one thing I didn't try. Thanks!

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 19:40:15 UTC, Mike Parker wrote: When you link statically with a library, you have to link with all of its dependencies, too. For GLFW, you'll need User32.lib, gdi32.lib, and OpenGL32.lib, off the top of my head. Aha. Now I wonder why LDC includes those

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 19:21:30 UTC, kinke wrote: May be worth another try with the proper command line. Thank you! LDC + LD now works without warnings. On Friday, 9 November 2018 at 19:21:30 UTC, kinke wrote: Run LDC or DMD with `-v`, that gives you the linker command line at the end

Re: How do I install a library?

2018-11-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 November 2018 at 23:43:38 UTC, Murilo wrote: It finally worked, but I can't just compile it normally, I have to use dub run, I wish it were something simple that I just download into the folder and then use an import statement and then compile it like any other program. I wish

Re: Differences between group() and chunkBy()

2018-11-14 Thread Dennis via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 12:28:38 UTC, Per Nordlöw wrote: Is it because of `group` has a default for the predicate whereas `chunkBy` hasn't. chunkBy splits the range into smaller ranges, group actually returns tuples of the item and the amount of occurences. Because in group the

Re: Using decodeFront with a generalised input range

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 10:45:49 UTC, Vinay Sajip wrote: As I see it, a ubyte 0x20 could be decoded to an ASCII char ' ', and likewise to wchar or dchar. It doesn't (to me) make sense to decode a char to a wchar or dchar. Anyway, you've shown me how decodeFront can be used, so great!

Re: Using decodeFront with a generalised input range

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 09:47:32 UTC, Vinay Sajip wrote: std.utf.decodeFront(Flag useReplacementDchar = No.useReplacementDchar, S)(ref S str) if (isInputRange!S && isSomeChar!(ElementType!S)) This is the overload you want, let's check if it matches: ref S str - your InputRange can be

linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
I'm trying the static bindings for glfw of bindbc on Windows, using the pre-compiled .lib files from the lib-vc2015 folder in the official download. (http://code.dlang.org/packages/bindbc-glfw) With LDC using the Microsoft MSCV linker, everything works. I can either add this: app.d: ```

Re: linker warnings and errors with bindbc-glfw

2018-11-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 November 2018 at 18:19:22 UTC, Dennis wrote: [...] I just noticed in the section about the static version: "This requires the GLFW development package be installed on your system at compile time." http://code.dlang.org/packages/bindbc-glfw I don't see where I can install the

Putting dmd error through grep for dustmite

2018-11-04 Thread Dennis via Digitalmars-d-learn
I am debugging a case where operator overloading seems to break when I define the opBinary templates in a mixin template. On my own simple test-case it worked fine, so I'm trying to reduce my current code with dustmite. The file tree is simply: myproject/ q16.d And the command I run is:

Re: Simple parallel foreach and summation/reduction

2018-09-21 Thread Dennis via Digitalmars-d-learn
On Friday, 21 September 2018 at 07:25:17 UTC, Chris Katko wrote: I get "Error: template instance `reduce!((a, b) => a + b)` cannot use local __lambda1 as parameter to non-global template reduce(functions...)" when trying to compile that using the online D editor with DMD and LDC. Any ideas?

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 18:17:54 UTC, Stanislav Blinov wrote: // implement separate methods for mutable/const/immutable Thanks. I should have tried that, but I assumed it wouldn't work since you can't overload on return-type only. However, the const / non-const makes it

difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
I'm making a fixed point numeric type and want it to work correctly with const. First problem: ``` const q16 a = 6; a /= 2; // compiles! despite `a` being const. writeln(a); // still 6 a.toQ32 /= 2;// what's actually happening ``` My q16 type has an implicit conversion to q32

Re: Fields with the same name not causing a warning?

2018-11-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 November 2018 at 20:13:42 UTC, Vinay Sajip wrote: More complicated for the compiler writers, or users of mixins/generics? For users of generics. It's hard to come up with an actual example because I don't know why one would ever use this, but in this concocted scenario: ```

Re: Fields with the same name not causing a warning?

2018-11-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 November 2018 at 18:37:00 UTC, Vinay Sajip wrote: Design flaws in what? Design flaws in the language. Quoting Jonathan M Davis: "Honestly, in general, warnings are a terrible idea. Anything that's a warning in your code has to be fixed, because it's bad practice to leave

Re: Some Fundamental Paradigm Questions

2018-12-21 Thread Dennis via Digitalmars-d-learn
The most fundamental problem that these features tackle is that code is costly, so making code-bases smaller and more reusable saves effort spent on maintaining large code-bases and rewriting code to suit a different situation. On Friday, 21 December 2018 at 12:39:48 UTC, Ron Tarrant wrote:

Re: Calling function explicitly from mixin template results in recursive call instead

2018-12-10 Thread Dennis via Digitalmars-d-learn
On Monday, 10 December 2018 at 21:16:23 UTC, aliak wrote: Does this fix your issue? struct S { mixin operators ops; S opBinary(string op, T)(T a) { alias opBinary = ops.opBinary; // explicitly alias opBinary in this scope return opBinary!op(a); } } It does,

Re: std.algorithm.canFind behavior difference between arrays and elements

2018-12-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 December 2018 at 18:51:27 UTC, Arun Chandrasekaran wrote: Why is there a difference in the behavior? Your first assert expression is looking for a string in a larger string, your second expression looks for hay which is not a string but a string[]. To flatten the array, use:

Re: Initialize static array without explicit length

2018-12-03 Thread Dennis via Digitalmars-d-learn
On Monday, 3 December 2018 at 10:00:31 UTC, Simen Kjærås wrote: However, it's easy to implement in a library: It even is in phobos: https://dlang.org/phobos/std_array.html#.staticArray ``` import std.array: staticArray; auto a = [0, 1, 2].staticArray; ```

Re: Ambiguous virtual function

2018-12-06 Thread Dennis via Digitalmars-d-learn
On Thursday, 6 December 2018 at 07:37:12 UTC, John Chapman wrote: Is the compiler giving the non-mixed-in function special treatment? I think you're running into this bug: https://issues.dlang.org/show_bug.cgi?id=19365 I see that it is not limited to operator overloading, in general the

Calling function explicitly from mixin template results in recursive call instead

2018-12-09 Thread Dennis via Digitalmars-d-learn
I'm using Adam's workaround from https://issues.dlang.org/show_bug.cgi?id=19365, but now I have endless recursion. Reduced code: ``` mixin template operators() { S opBinary(string op: "+")(S rhs) { return rhs; } // (A) auto opBinary(string op, T)(T rhs) if (false) {

Re: Calling function explicitly from mixin template results in recursive call instead

2018-12-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 9 December 2018 at 18:36:50 UTC, Dennis wrote: Does anyone know how to get this working? I added this to the mixin template: ``` alias mixinOpBinary = opBinary; ``` And called mixinOpBinary instead in the forwarded function. I think that solved it. I think I'll just file an issue

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 November 2018 at 22:30:52 UTC, Rubn wrote: Yah most people tend to avoid const for this reason. It only really works for basic types, if you have a "const int" you can convert it to an "int" by copy. But if you have a type like Vector!(const int) that won't work, you can't even

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:13:29 UTC, Stanislav Blinov wrote: You just dismissed that second to last sentence, did you? :) I don't know what you mean with it. It's not that I'm trying to be sneaky or lazy really trying to modify the const parameter when I should treat it properly. And

Re: difficulties with const structs and alias this / template functions

2018-11-18 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 01:24:02 UTC, Stanislav Blinov wrote: Yup, that's because, like Rubn said, copying value types is trivial. Where it all comes to bite you is when you start having pointers, because you can't copy a const(T)* into a T*. I'm not using reference types, but still:

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 02:39:32 UTC, Stanislav Blinov wrote: You're skimming the examples ;) I'm not saying your examples don't work, I'm trying to understand the minimum requirements. You said: "That's [constructors needing to be pure is] only for types with indirections

Re: difficulties with const structs and alias this / template functions

2018-11-19 Thread Dennis via Digitalmars-d-learn
On Monday, 19 November 2018 at 13:34:50 UTC, Stanislav Blinov wrote: Because it's not mutation, it's initialization. Oh. That's an epiphany for me. When a ctor is `pure`, the compiler knows it doesn't mutate any state other than the object's, so it allows conversion to all three

Re: UTFException when reading a file

2019-01-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 January 2019 at 19:45:05 UTC, Head Scratcher wrote: How can I read the file and convert the string into proper UTF-8 in memory without an exception? You have multiple options: ``` import std.file: read; import std.encoding: transcode, Windows1252String; auto ansiStr =

Re: Forbidding implicit conversions from an enum type to an integer

2019-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2019 at 08:38:28 UTC, Per Nordlöw wrote: Is there a way (compiler flag) to forbid implicit conversions from an enum type to integer types? You can make the enum type not an integer type. ``` struct Int{int i;} enum E: Int { first = Int(0), second = Int(1), } ```

Re: Forbidding implicit conversions from an enum type to an integer

2019-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2019 at 09:37:26 UTC, Per Nordlöw wrote: Are there any plans on deprecating implicit conversions of enums to integers? Not that I know of. Given the precedence of this: https://github.com/dlang/DIPs/blob/master/DIPs/rejected/DIP1015.md I doubt enum/integer-types are going

Re: Iterate/sort associative array by value?

2019-04-07 Thread Dennis via Digitalmars-d-learn
On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote: Error: no property sort for type Tuple!(uint, "key", int, "value")[] Did you import it? import std.algorithm;

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 07:53:23 UTC, Robert M. Münch wrote: Why does DMD not give a hint, that an import from the standard lib might be missing? I find these explicit import statements very annyoing. There currently are a few hard-coded import hints for common functions:

Re: Why is SwitchError an error and how is it unsafe to continue after catching it?

2019-02-24 Thread Dennis via Digitalmars-d-learn
On Sunday, 24 February 2019 at 10:53:09 UTC, aliak wrote: But the following code is very recoverable and I don't see how it's unsafe to continue executing: There is no guarantee that a final switch throws an Error. From what I've heard of Walter [1] (though I can't find it in the spec), the

Re: Block statements and memory management

2019-03-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 March 2019 at 03:47:43 UTC, Murilo wrote: Does anyone know if when I create a variable inside a scope as in {int a = 10;} it disappears complete from the memory when the scope finishes? Or does it remain in some part of the memory? I am thinking of using scopes to make

Re: bug in doc?

2019-03-14 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 March 2019 at 19:46:30 UTC, spir wrote: But the doc (the language ref for the matter) should definitely say what you just explained above, shouldn't they? Well arguably, the spec should detail the language semantics formally and not just be a description of the reference

Re: Aliasing a mixin (or alternative ways to profile a scope)

2019-03-09 Thread Dennis via Digitalmars-d-learn
On Friday, 8 March 2019 at 11:42:11 UTC, Simon wrote: Thanks, this works flawlessly. Out of interest: what is the "enum" doing there? I had the exact same behaviour in a function before, that I only called at compile-time, so why did it complain then? Can I somehow tell the compiler that a

Re: Applying a function each respective 2 elements of an array

2019-03-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 10 March 2019 at 08:59:59 UTC, kerdemdemir wrote: Can I avoid for loops and solve my problem with std algorithms or ranges ? Try slide: https://dlang.org/phobos/std_range.html#slide And then use map.

Re: Handling big FP numbers

2019-02-10 Thread Dennis via Digitalmars-d-learn
On Sunday, 10 February 2019 at 20:25:02 UTC, Murilo wrote: It seems this is a feature of D I will have to get used to and accept the fact I can't always get the same number as in C What compilers and settings do you use? What you're actually comparing here are different implementations of the

Casting int[] to ubyte[]: element wise cast or slice cast

2019-02-15 Thread Dennis via Digitalmars-d-learn
I assumed that casting an int[] to a ubyte[] would keep all bytes and quadruple the length of the original array. But when the array is a literal, it keeps the same length but truncates every int element to a ubyte: ``` import std.stdio; void main() { // enum: enum litA =

Re: Casting int[] to ubyte[]: element wise cast or slice cast

2019-02-15 Thread Dennis via Digitalmars-d-learn
On Friday, 15 February 2019 at 17:18:28 UTC, H. S. Teoh wrote: Why? because that's the only case where you can reinterpret the .sizeof*.length bytes as an array of a different type. There is no conversion, the cast works as a reinterpretation. It's by design. But my problem is that it

Re: How to convert `std.datetime.Duration` to seconds of floating point type?

2019-02-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 February 2019 at 14:34:09 UTC, drug wrote: Now I do it this way (https://run.dlang.io/is/8kVibT): ``` auto some_duration = dur!"msecs"(500); auto seconds = some_duration.total!"hnsecs" / 10_000_000.0; assert(seconds.approxEqual(0.5)); ``` is there better

Re: Iterate/sort associative array by value?

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 18:04:28 UTC, kdevel wrote: What's the purpose of .release? The documentation in https://dlang.org/phobos/std_range.html#.SortedRange.release is rather monosyllabic. The sort function returns a SortedRange, which is usually an array wrapper with the extra type

Re: I really don't understand DUB

2019-04-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 April 2019 at 19:54:28 UTC, WhatMeWorry wrote: Now, I've studied the on-line documentation and even walked through the code somewhat but I'm not making an headway. Very relatable. My tips so far are: - Look for projects in github with a similar structure to yours and look at

Re: Are static variables available to other static variables?

2019-04-12 Thread Dennis via Digitalmars-d-learn
On Friday, 12 April 2019 at 10:49:19 UTC, Jamie wrote: I was trying to declare a static variable dependent on another static variable, but it didn't work. Are static variables not known to other static variables at compile time? Add `const` or `immutable` to A and it will work. I don't know

Re: Extract code of function

2019-05-26 Thread Dennis via Digitalmars-d-learn
On Sunday, 26 May 2019 at 18:14:23 UTC, Jacob Carlborg wrote: No, that's not possible. Some hacky solutions are possible by importing a source file as a string and parsing it manually. dglsl actually extracts D function code to put into glsl shaders. Here's the snippet. See:

Re: File Exception, Access is denied - prompting for administrator's rights

2019-06-04 Thread Dennis via Digitalmars-d-learn
On Tuesday, 4 June 2019 at 16:30:41 UTC, BoQsc wrote: Is there any way to prompt for administrator's rights, to save the additional effort of lots of clicks? Looking at: https://stackoverflow.com/questions/31844584/is-there-an-api-call-to-prompt-user-for-uac-elevation You can try something

Re: What does ! Stand for in map! and filter! function calls?

2019-06-02 Thread Dennis via Digitalmars-d-learn
On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote: Is it not possible in the language to have template map function also to called as map(x=>... ? That would be slower, and std.algorithm generally disallows easy but slow functions. In Java, you can sort a linked list. In D, sort requires an

Re: Transform a function's body into a string for mixing in

2019-06-20 Thread Dennis via Digitalmars-d-learn
On Thursday, 20 June 2019 at 19:09:11 UTC, Emmanuelle wrote: Is there any trait or Phobos function for transforming a function/delegate/lambda/whatever's body into a string suitable for `mixin(...)`? For example: See: https://forum.dlang.org/post/kozwskltzidfnatbp...@forum.dlang.org If not,

Re: Where can find fix length array memory layout document

2019-06-18 Thread Dennis via Digitalmars-d-learn
On Tuesday, 18 June 2019 at 12:26:14 UTC, lili wrote: Hi guys: Is the Dlang fix-length array alloc on stack? when a test writeln([1]).sizeof //16 writeln([2]).sizeof //16 Why, What is the fix-length array memory layout. I'm assuming you mean writeln([1].sizeof). An array

Re: alias parameters, what for?

2019-05-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 May 2019 at 09:52:21 UTC, XavierAP wrote: alias parameters are used for functions (in the general sense). Why this instead of specifying and typing the parameter functions or delegates? With function pointers, there is extra indirection and the function can not be inlined.

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

2019-05-20 Thread Dennis via Digitalmars-d-learn
On Monday, 20 May 2019 at 11:10:32 UTC, Boqsc wrote: I'm frozen in learning basics of D lang since I want to create a simple game and I really would like a clean and simple code, For a simple game, I think it's the easiest to just store an integer of cents (or the lowest amount of currency

Re: Impose structure on array

2019-05-20 Thread Dennis via Digitalmars-d-learn
On Monday, 20 May 2019 at 12:09:02 UTC, Alex wrote: void* data; auto x = cast(byte[A,B,C])data; X is then an AxBxC matrix. It sounds like you're looking for ndslide from mir http://code.dlang.org/packages/mir-algorithm ``` ubyte data[]; auto x = x.sliced(A, B, C); ``` It should be pretty

Does slicing have an effect?

2019-05-21 Thread Dennis via Digitalmars-d-learn
I was replacing a memcpy with a slice assignment and accidentally used == instead of =. Usually the compiler protects me from mistakes like that: ``` int[4] a; a == a; ``` Error: a == a has no effect However, because I was using slices it didn't: ``` int[4] a; a[] == a[]; ``` No errors Does

Re: dmd + optlink Symbol Undefined _StretchDIBits@52

2019-05-03 Thread Dennis via Digitalmars-d-learn
On Friday, 3 May 2019 at 06:20:37 UTC, Mike Parker wrote: If you compile with -m32mscoff for 32-bit or -m64, DMD will use the Microsoft linker and import libraries if you have Visual Studio or the MS Build tools installed, and the LDC linker with some import libraries from MinGW if you don’t.

Re: alias to fully qualified symbol gives error, but when module is also a symbol

2019-05-05 Thread Dennis via Digitalmars-d-learn
On Sunday, 5 May 2019 at 18:07:10 UTC, Adam D. Ruppe wrote: The std.stdio one is supposed to be an error; the old buggy behavior was to bypass the private import in these cases and that is why it is deprecated pending changes. Thanks, that answers my question. The old private-bypassing

  1   2   >