Re: Pass type directly to a template function?

2017-02-07 Thread Dukc via Digitalmars-d-learn
On Tuesday, 7 February 2017 at 10:21:20 UTC, Mike Parker wrote: function2!float(); //? function3!float(); //? Yes, this is how it's done. Not quite with function3, because it takes one unnamed runtime parameter. It can be called like function1 however. The value of the parameter

Re: Why File.rawRead is @system?

2017-02-07 Thread Dukc via Digitalmars-d-learn
On Tuesday, 7 February 2017 at 09:21:18 UTC, Kagamin wrote: Can't find a reason why it's not inferred @safe (on linux). Any idea? Perhaps you are trying to read as a type for which a conversion from string to it is @system? Not sure if that's possible.

Re: cannot alias array ;/

2017-01-21 Thread Dukc via Digitalmars-d-learn
On Thursday, 19 January 2017 at 08:06:04 UTC, ketmar wrote: alias is not a macro, it is alias to *symbol*. only symbol, not any arbitrary expression. In fact, it can nowadays be. You just have to mark it so, with a lambda: void main() { import std.stdio; auto myArray = [2, 3, 5, 6];

Re: Why is [0] @safer than array.ptr?

2017-01-24 Thread Dukc via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 12:01:35 UTC, Jonathan M Davis wrote: So, while it makes sense to say that .ptr can't be used in @safe code, it really doesn't make sense to suggest [0] as an alternative. That may well be. But I believe everything that can provably be @safe are made so even

Re: Why is [0] @safer than array.ptr?

2017-01-26 Thread Dukc via Digitalmars-d-learn
On Wednesday, 25 January 2017 at 22:59:55 UTC, Jonathan M Davis wrote: So, yes, if all you're planning to do is look at the pointer to the first element in the array, then [0] is safer, but odds are quite low that that's actually what you're going to do, and in all of the other cases, you

Re: D idom for removing array elements

2017-01-27 Thread Dukc via Digitalmars-d-learn
On Friday, 27 January 2017 at 05:48:27 UTC, Stefan Koch wrote: To me it looks rather slow. please benchmark! void main() { import std.stdio, std.algorithm, std.range, std.array, std.datetime; int[] a = [1, 2, 3, 4, 5, 6, 7, 4].cycle.take(2000).array; int[] b = [3, 4,

Re: D idom for removing array elements

2017-01-27 Thread Dukc via Digitalmars-d-learn
On Thursday, 26 January 2017 at 23:10:02 UTC, albert-j wrote: Will it also work correctly and fast for arrays of custom objects? How should opCmp() be defined if objects don't have a meaningful ordering? The order of elements in the original array does not matter. Two options: either define

Re: D idom for removing array elements

2017-01-27 Thread Dukc via Digitalmars-d-learn
On Friday, 27 January 2017 at 08:15:56 UTC, Dukc wrote: My method is much better for large arrays I tested here. Trough, considering the size of the arrays the performance difference should be even greater, like 1000X better instead of 15X better so it's definitely not that great.

Re: D idom for removing array elements

2017-01-27 Thread Dukc via Digitalmars-d-learn
On Friday, 27 January 2017 at 10:20:19 UTC, albert-j wrote: I am also wondering why the standard library doesn't have convenience functions for this, e.g. like Java's removeAll? Now there's more typing than necessary for a relatively common task. That might be a good addition considering how

Is autodecoding being phased out?

2017-02-21 Thread Dukc via Digitalmars-d-learn
I (finally) managed to build the development build of dmd, with libraries. When testing if it compiles a Hello World program (it does, no problem) I got these messages: C:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(2716,24): Deprecation: function std.utf.toUTF8 is deprecated - To be

Re: Is autodecoding being phased out?

2017-02-21 Thread Dukc via Digitalmars-d-learn
On Tuesday, 21 February 2017 at 15:24:18 UTC, Jonathan M Davis wrote: [snip] - Jonathan M Davis Thanks for the in-depth answer. Well, auto-decoding is an annoyance but not that bad, I can live with it.

Re: Why is for() less efficient than foreach?

2017-02-10 Thread Dukc via Digitalmars-d-learn
On Friday, 10 February 2017 at 13:33:55 UTC, Bastiaan Veelo wrote: Thanks, I should have spotted that. Bastiaan. No, you don't even have to spot things like that. If you assert() the result that is. (Not a rant, half of us wouldn't probably have bothered).

Re: With not working with BitFlags

2017-01-20 Thread Dukc via Digitalmars-d-learn
This is fairly complex thing, but I managed to get it working: template EnumToFlags(E) if(is(E == enum)) { import std.traits, std.typecons, std.string; private static auto implementation() { string result; foreach(i, enumMem; EnumMembers!E) {

Re: With not working with BitFlags

2017-01-20 Thread Dukc via Digitalmars-d-learn
On Friday, 20 January 2017 at 09:12:04 UTC, Dukc wrote: template EnumToFlags(E) if(is(E == enum)) { import std.traits, std.typecons, std.string; //... } I think that typecons import was needless, you could try removing it...

Re: How to enforce compile time evaluation (and test if it was done at compile time)

2017-03-01 Thread Dukc via Digitalmars-d-learn
On Wednesday, 1 March 2017 at 16:43:41 UTC, Jonathan M Davis wrote: Assert is for program invariants. If the condition is true, your program is outright broken. Error: He meant that if the condition is FALSE, the program is faulty.

Re: How to enforce compile time evaluation (and test if it was done at compile time)

2017-02-27 Thread Dukc via Digitalmars-d-learn
On Monday, 27 February 2017 at 19:26:06 UTC, Christian Köstlin wrote: Is it enough to put up static immutable modifiers? How can I make sure, that the calculations are done at compile time? ... static immutable time = Unit("time", [Unit.Scale("ms", 1), ... An initialization of a static

Where should I dump workarounds?

2016-11-30 Thread Dukc via Digitalmars-d-learn
Well, I was working on std.range.chain (I'm new to contributing), and when trying to test locally: ...\phobos\std\range>rdmd -unittest -main package C:\D\dmd2\windows\bin\..\..\src\phobos\std\path.d(1319): Error: pure function 'std.path.buildPath!char.buildPath' cannot call impure function

Re: Where should I dump workarounds?

2016-11-30 Thread Dukc via Digitalmars-d-learn
On Wednesday, 30 November 2016 at 18:26:32 UTC, Jonathan M Davis wrote: [snip] - Jonathan M Davis Luckily, I have made a branch for my stuff instead of using master. But thanks for the help, now I know that it does not matter where I create the other branch for that workaround because I

Re: Where should I dump workarounds?

2016-11-30 Thread Dukc via Digitalmars-d-learn
On Wednesday, 30 November 2016 at 21:48:20 UTC, Johan Engelen wrote: Tip: forget about the `master` branch in your own fork on GH. I never use it. Instead, my advice is to locally checkout the master branch from the repo you want to contribute to (dlang/phobos in your case). That works and

Re: Append to dynamic array that was allocated via calloc

2017-07-25 Thread Dukc via Digitalmars-d-learn
On Tuesday, 25 July 2017 at 12:40:13 UTC, John Burton wrote: What happens? It seems to successfully append an extra value to the array. It appears to "work" when I try it in my compiler but I don't understand how. Will this be trying to write beyond the memory I calloc'ed? The language makes

Re: Need simple sound

2017-07-04 Thread Dukc via Digitalmars-d-learn
On Monday, 3 July 2017 at 08:55:20 UTC, Martin Tschierschke wrote: Hello for a simple game I would like to add some very simple sound, not much different than the beeps of "PAC Man". Is there anything I can use for this? When simplicity is the matter number 1, Arsd-official most likely what

About Dub capabilities

2017-07-04 Thread Dukc via Digitalmars-d-learn
When you want to do things other than just fetching packages, invoking D compilers and converting package descriptors, I am wondering is Dub up to it? For example, could dmd source code build (if somebody wanted to) be automated with Dub instead of CMake, bearing in mind it requires some c++

Re: About Dub capabilities

2017-07-05 Thread Dukc via Digitalmars-d-learn
On Tuesday, 4 July 2017 at 21:02:55 UTC, Martin Nowak wrote: preGenerate-/preBuildCommands are your friends to compile C++ code using dub. Hod did I not notice them... but that answers the question, thanks.

Re: How to build GUI-based applications in D ?

2017-08-01 Thread Dukc via Digitalmars-d-learn
On Tuesday, 1 August 2017 at 15:18:12 UTC, ashit wrote: i couldn't set control's width and height (Button widget) shows error. maybe it works a different way. 1. Try layoutHeight/width. Remember to set it for the main widget too, not just the children of it. 2. DlangUI is not intended to

Re: How to build GUI-based applications in D ?

2017-08-07 Thread Dukc via Digitalmars-d-learn
thank you aberba ok, so this is useless to me. i want something fully functional stand-alone tools. i have no internet connection there. Don't worry, DlangUI is stand-alone: you only need the connection to download it, but not to use it nor to compile with. Dub will function without

Re: templatized delegate

2017-05-22 Thread Dukc via Digitalmars-d-learn
On Monday, 22 May 2017 at 09:04:15 UTC, Alex wrote: 2. Now, I want to store the delegate in another struct. If I want to do this, I have to define the pointer as static. This is not intended at the beginning, but it's ok, as I know, that the delegate would be the same across all instances of

Re: [OT] #define

2017-05-22 Thread Dukc via Digitalmars-d-learn
On Monday, 22 May 2017 at 13:11:15 UTC, Andrew Edwards wrote: Sorry if this is a stupid question but it eludes me. In the following, what is THING? What is SOME_THING? #ifndef THING #define THING #endif #ifndef SOME_THING #define SOME_THING THING * #endif Is this

Re: need to emulate scope(failure) with struct destructor

2017-05-28 Thread Dukc via Digitalmars-d-learn
On Sunday, 28 May 2017 at 20:06:42 UTC, piotrklos wrote: I need to perform an action, in multiple separate functions, if scope exits with an exception. The trouble is I don't want to litter my code with scope(failure) everywhere. I already create an instance of a struct at each location, with

Re: What's a good wat to trunctate a time point

2017-05-05 Thread Dukc via Digitalmars-d-learn
On Friday, 5 May 2017 at 09:14:21 UTC, Biotronic wrote: Here's an implementation that supports start of year, month, week, day, hour, minute and second. Works for DateTime and SysTime. Not heavily tested (all tests included): [lots of code] Wow! You might want to create a pr to phobos

What's a good wat to trunctate a time point

2017-05-05 Thread Dukc via Digitalmars-d-learn
I have a time point, be it SysTime or DateTime, whatever. I want to trunctate it to weeks, eg. I want it to become the first point of time during the week it was representing. What's a good way to do that? Only hacks came to my mind. The solution does not have to be generic, trough I'd prefer

Trying to understand DIP1000

2017-05-05 Thread Dukc via Digitalmars-d-learn
Walters exciting yesterday talk made me think about dip1000 again. I found out that I do not understand this: Containers that own their data will be able to give access to elements by scope ref. The compiler ensures that the references returned never outlive the container. Therefore, the

Re: Trying to understand DIP1000

2017-05-05 Thread Dukc via Digitalmars-d-learn
On Friday, 5 May 2017 at 18:04:32 UTC, Dukc wrote: The compiler is too cunning to let you to leak test[x] out of a function by reference, or take an address of it. Nor you can assing it to another variable, because that means copy semantics. And oh, the identity function won't fool the

Re: Trying to understand DIP1000

2017-05-05 Thread Dukc via Digitalmars-d-learn
On Friday, 5 May 2017 at 18:04:32 UTC, Dukc wrote: @safe void killDMan() { auto outer = [RefCountedSlice!int(1)]; foreach(ref fail; outer) { outer = [RefCountedSlice!int(1)]; gcActivationAttempt = new int[3]; fail[0] = 24; } } should be int[]

Re: Andrei's "The D Programming Language" book. Up to date?

2017-10-05 Thread Dukc via Digitalmars-d-learn
On Wednesday, 4 October 2017 at 20:49:26 UTC, John Gabriele wrote: Hi all, This is my first message to this forum. And what a pleasure it is to be here. :) I was just looking around at what D books are available. I see that Andrei's "The D Programming Language" was published in 2010.

Re: Making a repo of downloaded dub package

2017-09-05 Thread Dukc via Digitalmars-d-learn
On Tuesday, 5 September 2017 at 08:43:02 UTC, Jonathan M Davis wrote: Yeah. I'm fairly certain that that's your only option. dub is not designed with the idea that you would be editing the source code that it downloads. That's just intended for building the code that you are editing. It does

Re: Making a repo of downloaded dub package

2017-09-05 Thread Dukc via Digitalmars-d-learn
On Monday, 4 September 2017 at 20:31:35 UTC, Igor wrote: Search for word "local" here: https://code.dlang.org/docs/commandline. Maybe some of those can help you. If not you could make a pull request for dub that would support such a thing :) That will make a Dub package out of a Git package,

Making a repo of downloaded dub package

2017-08-27 Thread Dukc via Digitalmars-d-learn
More than once I have downloaded a DUB package which almost compiles but not quite. The fixes are often so trivial that even the user can do them, and the package starts working. But one may want to create a pull request to fix those issues for others too. Is there any way to make the

Re: Making a repo of downloaded dub package

2017-09-04 Thread Dukc via Digitalmars-d-learn
Bump

Re: Floating point types default to NaN?

2017-11-27 Thread Dukc via Digitalmars-d-learn
On Saturday, 25 November 2017 at 09:39:15 UTC, Dave Jones wrote: I mean at the end of the day, that would turn a run time error into a compile time error which is a good thing isnt it? Debatable in this case. Consider: string servicePhoneNumber; final switch (car.manufacturer) //an

Re: Having "in" for arrays

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 08:03:50 UTC, Fra Mecca wrote: void main() { auto v = ["r", "i", "o"]; assert ("r" in v); } Also note that even if it wereimplemented, you search for 'r' instead of "r". "r" is a string, but you would want to search for a char.

Re: Having "in" for arrays

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 10:32:48 UTC, lobo wrote: On Wednesday, 22 November 2017 at 09:36:43 UTC, Dukc wrote: On Wednesday, 22 November 2017 at 08:03:50 UTC, Fra Mecca wrote: void main() { auto v = ["r", "i", "o"]; assert ("r" in v); } Also note that even if it

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe wrote: On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote: will do. Even if it were an lvalue, that would be the address of a local. You should basically NEVER do that with D classes. Just `cast(void*) this` if

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote: It seems in D, reference has its own address, am I right? unlike c++ In case of classes, yes. But I think function parameter references do not (or rather, of course they have since they exist in memory but it's hidden). Not sure

Re: Mirroring a drawable buf in DLangUI?

2017-11-23 Thread Dukc via Digitalmars-d-learn
On Thursday, 23 November 2017 at 13:31:23 UTC, Vadim Lopatin wrote: There is no such feature currently, but it can be added easy. In the meantime I should call OpenGL (I think it's the backend in my case) directly, correct?

Re: Passing this to void *

2017-11-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 22 November 2017 at 15:34:53 UTC, Adam D. Ruppe wrote: No, in both cases, if you do as I say, you will be passing the same address. I was referring to his version of the main function that used &. But yes, if you do a cast instead it works just as you say.

Mirroring a drawable buf in DLangUI?

2017-11-21 Thread Dukc via Digitalmars-d-learn
I am using the DrawRescaled method of DrawBuf[1] of DLangUI To draw a PNG image to a CanvasWidget[2] subclass. It has a minor issue of the box bounds showing in area that shoud be transparent but otherwise works well. My question is, does anybody know a way to draw that image backwards

Re: Clarify "Starting as a Contributor" document

2017-12-11 Thread Dukc via Digitalmars-d-learn
On Sunday, 10 December 2017 at 08:18:17 UTC, Ali Çehreli wrote: This page is very good: https://wiki.dlang.org/Starting_as_a_Contributor I need clarifications Another oddity: Someone has apparently made DRuntime build to use ../dmd/generated/windows/32/dmd instead of the "system" dmd

Re: Mirroring a drawable buf in DLangUI?

2017-12-04 Thread Dukc via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 13:45:31 UTC, Dukc wrote: My question is, does anybody know a way to draw that image backwards without making another PNG file to do so? After a lot of code research, I believe the best way for me is to use DlangUI helpers in same way as in the new api of the

LDC: Where is this supposed to link to?

2018-06-12 Thread Dukc via Digitalmars-d-learn
I have just managed to include a bit D code in a C# project compiled to Javascript. I am already looking at extending LDC runtime to open more possibilites, but something seems fishy. All DRuntime code the compiler can invoke directly is in object.d, is that right? When I try to copy a

Re: LDC: Where is this supposed to link to?

2018-06-12 Thread Dukc via Digitalmars-d-learn
On Tuesday, 12 June 2018 at 17:41:46 UTC, Adam D. Ruppe wrote: No, actually very little of it is there. Most the code the compiler calls into is found in the compiled druntime lib, like in the druntime/src/rt directory. That explains it. Well, back to exploring. Thank you.

Re: LDC: Where is this supposed to link to?

2018-06-12 Thread Dukc via Digitalmars-d-learn
On Tuesday, 12 June 2018 at 17:41:46 UTC, Adam D. Ruppe wrote: No, actually very little of it is there. Most the code the compiler calls into is found in the compiled druntime lib, like in the druntime/src/rt directory. And, just in case somebody at a later date has the same question, I

Re: Zip vs Enumerate

2018-06-19 Thread Dukc via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 03:44:58 UTC, Jordan Wilson wrote: Is there anything I can do to improve zip, before I go ahead and change to the faster but slightly less readable enumerate? The problem might be that zip checks both arrays for empty during each step, enumerate only the first

Re: How do you safely deal with range.front?

2017-12-30 Thread Dukc via Digitalmars-d-learn
On Saturday, 30 December 2017 at 19:00:07 UTC, aliak wrote: Instead of this: auto result = range.op!f; if (!result.empty) { result.front.method(); } This: range.op!f.ifFront.method(); Ah, so you don't have a problem with checking emptiness but you want to do it inside the

What could this OptLink Error mean?

2017-12-29 Thread Dukc via Digitalmars-d-learn
I was building one example of DLangUi (dub build --build-mode=allAtOnce --build=debuglinker) and it did compile but the linker started to complain. I did notice it seemed to be related to the standard library, so I updated it and DRuntime to the lastest master, rebuilt them and replaced

Re: Is Nullable supposed to provide Optional semantics?

2017-12-29 Thread Dukc via Digitalmars-d-learn
On Friday, 29 December 2017 at 21:43:25 UTC, Chris Paulson-Ellis wrote: Only nullify() can make isNull return true again. I need that semantic. Quick idea without much afterthought: instead of Nullable, use pointer to o?

Re: How do you safely deal with range.front?

2017-12-29 Thread Dukc via Digitalmars-d-learn
On Friday, 29 December 2017 at 19:38:44 UTC, aliak wrote: So when I'm dealing with ranges, there're a number of times where I get the front of the returned result of a set of operations, but of course there is no front so you get an runtime access error. This could be what you want: auto

Re: How do you do "const nazi" in D?

2018-01-04 Thread Dukc via Digitalmars-d-learn
On Thursday, 4 January 2018 at 13:52:14 UTC, Mark wrote: You ma find Ali Cehreli's talk from DConf 2013 [1] useful. It includes some guidelines (basically recommendations) on how to use immutable and const. Same topic and same mentor here, but in text form:

Re: What could this OptLink Error mean?

2018-01-04 Thread Dukc via Digitalmars-d-learn
On Saturday, 30 December 2017 at 00:49:48 UTC, user1234 wrote: The deps have to be rebuild too. After downloading dmd 78, it started to work. It's likely you were right about the issue, DUB rebuilt everything after detecting new compiler version. Sorry for my late reply.

Re: new int[]

2018-01-11 Thread Dukc via Digitalmars-d-learn
On Wednesday, 10 January 2018 at 23:08:28 UTC, Luís Marques wrote: void main() { int[]* x = &[[1, 2, 3]][0]; int[]* x2 = [[1, 2, 3]].ptr; /* same */ } That's an interesting solution. I'm not sure which one I prefer, the wrapper or this one. Still... I feel like the language should just

Re: Game and GC

2018-02-23 Thread Dukc via Digitalmars-d-learn
On Friday, 23 February 2018 at 01:54:07 UTC, Leonardo wrote: What can happen if I create a game using D without worrying with memory management? (using full GC) If you do not worry about memory management at all, it will probably lead to a need to redesign your game. And that's regardless

Re: Is it feasible to slowly rewrite a C++ codebase in D?

2018-07-16 Thread Dukc via Digitalmars-d-learn
On Saturday, 14 July 2018 at 03:08:50 UTC, Vladimir Panteleev wrote: I'll follow up with Alawain. Regardless, dscripten-tools borrows very little from the redistributable parts of dscripten - mostly the "minimalistic runtime", which I think was itself borrowed from somewhere else. Indeed, it

Is there any reason to use non-ref foreach?

2018-08-31 Thread Dukc via Digitalmars-d-learn
For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: import std.experimental.all; struct NoCopies { @disable this(this); int payload; } void main() { auto range = new NoCopies[20]; foreach(const ref el; range)

Re: Is it feasible to slowly rewrite a C++ codebase in D?

2018-07-13 Thread Dukc via Digitalmars-d-learn
On Thursday, 12 July 2018 at 15:12:51 UTC, Seb wrote: it might also be feasible to simply use normal D. Have you already tried this? There's no strict distinction between using D normally and in systems programming fashion for me, because my main function isn't written in D. But in

Re: Is it feasible to slowly rewrite a C++ codebase in D?

2018-07-13 Thread Dukc via Digitalmars-d-learn
On Wednesday, 20 June 2018 at 18:47:10 UTC, Jordi Gutiérrez Hermoso wrote: Now, as I understand it, I would need to begin with making `main` a D function, because D needs to initialise the runtime. Is this correct? No. Some initialization is required if you use the GC, as I understand it.

Re: Is it feasible to slowly rewrite a C++ codebase in D?

2018-07-11 Thread Dukc via Digitalmars-d-learn
On Wednesday, 11 July 2018 at 19:41:37 UTC, Jordi Gutiérrez Hermoso wrote: Just getting it into -betterC territory seems like a very daunting task. You do not need -betterC anymore. At least the LDC frontend will only add linking hooks for what you use, -betterC or no. No need build a stub

Re: @safe - why does this compile?

2018-07-13 Thread Dukc via Digitalmars-d-learn
On Friday, 13 July 2018 at 13:52:27 UTC, Timoses wrote: I suppose this is another good example of how casting can be dangerous? E.g. also: immutable int i = 3; int* j = cast(int*) assert(i == 3); *j = 4; assert(j == ); // data occupies same address space assert(i

Re: Optional parameters?

2018-04-04 Thread Dukc via Digitalmars-d-learn
On Sunday, 1 April 2018 at 15:54:16 UTC, Steven Schveighoffer wrote: But I'd rather avoid such things if possible. Is there a way around this? Seems rather limiting that I can do: Is this what you're looking for? void foo(Nullable!int x = Nullable!int.init) { if (!x.isNull) x.get.writeln;

Re: Optional parameters?

2018-04-04 Thread Dukc via Digitalmars-d-learn
On Wednesday, 4 April 2018 at 15:44:34 UTC, Steven Schveighoffer wrote: See my original post: I know I can do things like this: void foo(int x) { return foo(nullable(x)); } -Steve Oops, I read only the body of that function and thought it's a main function constructiong nullable when

Is there a way to pipeline program with random-access ranges in C#?

2018-03-19 Thread Dukc via Digitalmars-d-learn
This topic is technically in wrong place, since the problem is with C#, not D. But because what I'm asking is more idiomatic in D than elsewhere, I think I have the best changes to get understood here. So, I'm looking for some library, or technique, that allows me to chain range-evaluating

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-20 Thread Dukc via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 08:05:14 UTC, Kagamin wrote: On Monday, 19 March 2018 at 17:33:31 UTC, Dukc wrote: public static int Foo(int[] input) { int result = 10; for (int i = input.Length / 4; i >= 0; i -= 4) { int sum = 0; for (int j = i; j < i +4 && j < input.Length;

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-22 Thread Dukc via Digitalmars-d-learn
On Thursday, 22 March 2018 at 09:59:28 UTC, Kagamin wrote: On Thursday, 22 March 2018 at 09:04:12 UTC, Dukc wrote: So the real difference is that random-accesss ranges are not input-ranges in C# (or Rust, judging by a quick look I recently took) but can be used to fetch one. A bit cumbersome

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-22 Thread Dukc via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 08:40:25 UTC, Kagamin wrote: On Wednesday, 21 March 2018 at 07:40:01 UTC, Dukc wrote: ...except that IEnumerables cannot popBack(), so can only do that by doing an additional copy and reversing that. But I quess there's no better alternative, short of doing it

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-19 Thread Dukc via Digitalmars-d-learn
On Monday, 19 March 2018 at 14:41:27 UTC, rumbu wrote: Sorry, but I fail to understand your requirements. Do you have a practical example? Doing this without writing a loop or using arrays for memoizing half-finished calculations: public static int Foo(int[] input) { int result = 10;

Re: Convert output range to input range

2018-03-17 Thread Dukc via Digitalmars-d-learn
On Friday, 16 March 2018 at 08:07:09 UTC, Jonathan M Davis wrote: For instance, std.array.Appender is an output range, and you get a dynamic array out of it, which would be an input range. So, if you have control over what output range you're dealing with, the simplest would be to just use

Re: Is there a way to pipeline program with random-access ranges in C#?

2018-03-21 Thread Dukc via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 15:57:16 UTC, Kagamin wrote: On Tuesday, 20 March 2018 at 15:06:14 UTC, Dukc wrote: Won't quite do it, because that would not iterate backwards. Linq has no chunking, so you would need to write it, maybe similar to SelectMany, but with the opposite meaning.

Re: Reading binary streams with decoding to Unicode

2018-10-15 Thread Dukc via Digitalmars-d-learn
On Monday, 15 October 2018 at 10:49:49 UTC, Vinay Sajip wrote: Is there a standardised way of reading over buffered binary streams (at least strings, files, and sockets) where you can layer a decoder on top, so you get a character stream you can read one Unicode char at a time? Initially

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

2018-10-17 Thread Dukc via Digitalmars-d-learn
On Tuesday, 16 October 2018 at 22:59:50 UTC, Dennis wrote: [snip] The first thing to consider for invalid tokens, at least for me, would be to either have popFront set empty to true, or set front to some value representing a parsing error. A programming language parser almost certainly

Profiling with DUB?

2018-10-29 Thread Dukc via Digitalmars-d-learn
I'm trying to profile my program, built like: dub build --build=profile When I run the program, where is the performance profile file supposed to appear? I can find nothing new in the program/project root directory. This happens regardless whether I compile with dmd or ldc2.

Re: Profiling with DUB?

2018-11-05 Thread Dukc via Digitalmars-d-learn
On Thursday, 1 November 2018 at 13:59:39 UTC, Guillaume Piolat wrote: On Monday, 29 October 2018 at 10:14:23 UTC, Dukc wrote: I'm trying to profile my program, built like: dub build --build=profile When I run the program, where is the performance profile file supposed to appear? I can find

Re: javascript or typescript

2018-11-05 Thread Dukc via Digitalmars-d-learn
On Monday, 5 November 2018 at 08:49:42 UTC, Laurent Tréguier wrote: On Monday, 5 November 2018 at 02:51:19 UTC, Fred wrote: hi, my javascript skill is bad. but i want to host some nodejs app i am aware that there is converter to js like dtojs. but it is out of date. i'd like to give d a

Re: javascript or typescript

2018-11-05 Thread Dukc via Digitalmars-d-learn
On Monday, 5 November 2018 at 02:51:19 UTC, Fred wrote: hi, my javascript skill is bad. but i want to host some nodejs app i am aware that there is converter to js like dtojs. but it is out of date. i'd like to give d a try. is there any other converter available. a decent one. Let me

Re: Why use while if only iterating once ?

2018-11-06 Thread Dukc via Digitalmars-d-learn
On Saturday, 3 November 2018 at 21:13:49 UTC, Jonathan M Davis wrote: There's a continue right above the default case. So, if the code hits that point, it will loop back to the top. - Jonathan M Davis There's also the benefit that FLAGS f exists only until the end of the loop, and thus

Re: Profiling with DUB?

2018-11-06 Thread Dukc via Digitalmars-d-learn
On Monday, 29 October 2018 at 10:14:23 UTC, Dukc wrote: When I run the program, where is the performance profile file supposed to appear? I can find nothing new in the program/project root directory. The same thing happens when I try to get a coverage report: No file appears.

Re: Is there an efficient byte buffer queue?

2018-10-10 Thread Dukc via Digitalmars-d-learn
On Monday, 8 October 2018 at 10:31:33 UTC, Nicholas Wilson wrote: Try searching for "circular buffer". I'm sure http://code.dlang.org/packages/iopipe has them in some form but I can't find them with a cursory search.

Re: Is there any reason to use non-ref foreach?

2018-08-31 Thread Dukc via Digitalmars-d-learn
On Friday, 31 August 2018 at 12:52:17 UTC, bauss wrote: In reality you're micro-optimizing something that doesn't require it. I think you misunderstood. I wasn't trying to optimize, I was looking for a general way to iterate. I can't see the benefit other than added complexity. I just

Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Dukc via Digitalmars-d-learn
On Monday, 3 September 2018 at 13:34:36 UTC, Andrea Fontana wrote: On Friday, 31 August 2018 at 09:59:20 UTC, Dukc wrote: For me, it seems that for generality you should always add ref into foreach loop variable. The reason is this: One good reason:

Re: Is there any reason to use non-ref foreach?

2018-09-04 Thread Dukc via Digitalmars-d-learn
On Tuesday, 4 September 2018 at 08:17:14 UTC, Andrea Fontana wrote: Waiting for this to be merged: https://github.com/dlang/dmd/pull/8437 Well, it seems Andrei has already approved the concept. well, THAT is a good reason to avoid this paradigm. Thanks for the info.

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-16 Thread Dukc via Digitalmars-d-learn
On Tuesday, 15 January 2019 at 11:14:54 UTC, John Burton wrote: This is ok, but I'm not so keen on separating the creation and construction like this. Is there a better way that's not ugly? You can make the constructor a template that takes a single struct of arbitrary, and inspects (at

Re: Is there a nice syntax to achieve optional named parameters?

2019-01-16 Thread Dukc via Digitalmars-d-learn
On Wednesday, 16 January 2019 at 11:21:53 UTC, Dukc wrote: a template that takes a single struct of arbitrary, meant "of arbitrary type"

Re: Runtime heterogeneous collections?

2019-01-17 Thread Dukc via Digitalmars-d-learn
On Thursday, 17 January 2019 at 02:27:20 UTC, Neia Neutuladh wrote: 1. Make a wrapper class. Now you can store Object[], or you can make a base class or base interface and use that. 2. Use Variant, which can wrap anything, or the related Algebraic, which can wrap a fixed collection of types.

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-12-04 Thread Dukc via Digitalmars-d-learn
Nulls/Nones are always a big gap in a language's type system. A common alternative is to have some Option/Maybe type like Rust or Haskell or D's Variant. How about making that required to plug the null gap? There are others too who feel like that too:

Re: Why does nobody seem to think that `null` is a serious problem in D?

2018-12-01 Thread Dukc via Digitalmars-d-learn
On Saturday, 1 December 2018 at 00:32:35 UTC, Tony wrote: isocpp.org just had a link to a blog post where someone makes a case for uninitialized variables in C++ being an advantage in that you can potentially get a warning regarding use of an uninitialized variable that points out an error in

Re: Can LDC compile to supported legacy LLVM versions?

2019-01-28 Thread Dukc via Digitalmars-d-learn
On Monday, 28 January 2019 at 13:04:08 UTC, Nicholas Wilson wrote: Do you mean bitcode, LLVM IR or something different? The LDC built against a given version of LLVM can link to bitcode/compile LLMV IR, of that version. Bitcode in this case, but I think your following answer applies to

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 17:23:21 UTC, Q. Schroll wrote: For whatever reason, when I put the code in a struct, the @safe testing line tells me, it's @system now. I tested a bit, and it appears that attribute inference is not done at all for templates inside structs -the attribute

Re: Why is my @pure function @system when placed in a struct?

2019-02-27 Thread Dukc via Digitalmars-d-learn
On Wednesday, 27 February 2019 at 18:06:49 UTC, Stefan Koch wrote: the struct gets drawn into your delegate-context. and I guess that taints the function. Even if it did, it should not make the delegate @system. And it does not, since this manifest with static functions and function

Re: Ordered set container?

2019-01-29 Thread Dukc via Digitalmars-d-learn
On Monday, 28 January 2019 at 17:18:52 UTC, Victor Porton wrote: I want "ordered set" container (like list or vector but with the warranty of no duplicate elements). The above answers are ordered, but if you want a type that's a simple sorted array, there's none at the standard library

Can LDC compile to supported legacy LLVM versions?

2019-01-28 Thread Dukc via Digitalmars-d-learn
I have recenty updated my LDC to the most recent version (1.14). The problem is that it compiles to LLVM code version 7.0.1, but I need it to compile to LLVM 6.x.x or LLVM 5.x.x. The last release note said that LLVM versions from 3.something.something are supported, but does this mean only

Re: Dlang + emscripten

2019-05-16 Thread Dukc via Digitalmars-d-learn
On Thursday, 16 May 2019 at 18:23:12 UTC, SrMordred wrote: I´m following this link to build d+sdl2+emscripten on web: https://theartofmachinery.com/2018/12/20/emscripten_d.html And, i´m was able to compile but i get the warnings warning: Linking two modules of different data layouts / target

Re: Reading .pem files for secured

2019-06-03 Thread Dukc via Digitalmars-d-learn
On Friday, 31 May 2019 at 10:35:46 UTC, Dukc wrote: if I understand the logic of Base64, it's that each character stores 6 bits. My private key .pem has 49 lines of 64 characters worth of Base64, though the sat line isn't full. Anyway, this is data worth of over 18000 bits. The RSA key is

Reading .pem files for secured

2019-05-31 Thread Dukc via Digitalmars-d-learn
I need to manually sign and verify stuff with asymmetric crypto keys. I ended up using rsa from secured. The key pair needs to be persistant between, so I made a 4096-bit private key with OpenSSL, stored in .pem file. Then I constructed a public key from the private one, again with OpenSSL.

  1   2   >